小编qed*_*qed的帖子

在python中命名为非捕获组?

是否有可能在python中命名非捕获组?例如,我想匹配此模式中的字符串(包括引号):

"a = b"'bird = angel'

我可以做以下事情:

s = '"bird=angel"'
myre = re.compile(r'(?P<quote>[\'"])(\w+)=(\w+)(?P=quote)')
m = myre.search(s)
m.groups()
# ('"', 'bird', 'angel')
Run Code Online (Sandbox Code Playgroud)

结果捕获了引用组,这在这里是不可取的.

python regex

4
推荐指数
2
解决办法
2035
查看次数

我如何理解这个R功能?

mfibR <- local({
    memo <- c(1, 1, rep(NA, 1000))
    f <- function(x) {
        if (x == 0) 
            return(0)
        if (x < 0) 
            return(NA)
        if (x > length(memo)) 
            stop("x too big for implementation")
        if (!is.na(memo[x])) 
            return(memo[x])
        ans <- f(x - 2) + f(x - 1)
        memo[x] <<- ans
        ans
    }
})
Run Code Online (Sandbox Code Playgroud)

它没有函数体,但它实际上正确地返回了Fibonacci序列.

r function

4
推荐指数
1
解决办法
93
查看次数

使用boost regex库有什么问题?

这是代码;

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using boost::regex;
using boost::regex_match;

int main(int argc, char **argv) {
    std::string input;
    regex gdreg(R"(g[a-z]+d)");
    while(true)
    {
        std::cout << "Give me a word: ";
        std::cin >> input;
        if(input == "q") {
            break;
        }
        if(regex_match(input, gdreg))
            std::cout << "It's a GD word!" << std::endl;
        else
            std::cout << "Nooooooo!" << std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

g++ x.cpp -std=c++11 -o x
/tmp/ccJ7zdHo.o: In function `bool boost::regex_match<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char …
Run Code Online (Sandbox Code Playgroud)

c++ regex boost

4
推荐指数
2
解决办法
1万
查看次数

禁用任何网站中的所有超链接

有没有办法使用javascript禁用任何网站中的所有超链接?

我想这样做的原因是为了文本选择。许多网站将整块文本放在标签内,这使得选择文本变得困难。

我在 kubuntu 13.10 上使用了 Chromium 和 firefox。

javascript firefox chromium web

4
推荐指数
2
解决办法
6690
查看次数

在java中使用泛型类型重载构造函数

这是代码:

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IDEA on 15/11/14.
 */
public class Matrix<T> {
    private final int nrow;
    private final int ncol;

    Matrix(List<List<T>> data) {
        nrow = data.size();
        ncol = data.get(0).size();
    }

    Matrix(List<T[]> data) {
        nrow = data.size();
        ncol = data.get(0).length;
    }
}
Run Code Online (Sandbox Code Playgroud)

IDE要求我删除第一个构造函数,为什么?

java constructor overloading

4
推荐指数
1
解决办法
975
查看次数

do 块中作业数量的上限?

这是代码:

(ns typedclj.async
  (:require [clojure.core.async
             :as a
             :refer [>! <! >!! <!!
                     go chan buffer
                     close! thread
                     alts! alts!! timeout]]
            [clj-http.client :as -cc]))


(time (dorun
        (let [c (chan)]
          (doseq [i (range 10 1e4)]
            (go (>! c i))))))
Run Code Online (Sandbox Code Playgroud)

我得到了一个错误:

Exception in thread "async-dispatch-12" java.lang.AssertionError: Assert failed: No more than 1024 pending puts are allowed on a single channel. Consider using a windowed buffer.
(< (.size puts) impl/MAX-QUEUE-SIZE)
    at clojure.core.async.impl.channels.ManyToManyChannel.put_BANG_(channels.clj:150)
    at clojure.core.async.impl.ioc_macros$put_BANG_.invoke(ioc_macros.clj:959)
    at typedclj.async$eval11807$fn__11816$state_machine__6185__auto____11817$fn__11819.invoke(async.clj:19)
    at typedclj.async$eval11807$fn__11816$state_machine__6185__auto____11817.invoke(async.clj:19)
    at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:940)
    at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:944)
    at typedclj.async$eval11807$fn__11816.invoke(async.clj:19) …
Run Code Online (Sandbox Code Playgroud)

multithreading clojure core.async

4
推荐指数
1
解决办法
742
查看次数

postgresql中嵌套的子句

我试图使用嵌套with:

CREATE TABLE audit_trail (
      old_email TEXT NOT NULL,
      new_email TEXT NOT NULL
);

INSERT INTO audit_trail(old_email, new_email)
  VALUES ('harold_gim@yahoo.com', 'hgimenez@hotmail.com'),
         ('hgimenez@hotmail.com', 'harold.gimenez@gmail.com'),
         ('harold.gimenez@gmail.com', 'harold@heroku.com'),
         ('foo@bar.com', 'bar@baz.com'),
         ('bar@baz.com', 'barbaz@gmail.com');

with iter2 as (
    with iter1 as (
        select old_email, new_email from audit_trail where old_email = 'harold_gim@yahoo.com'
        ) select a.old_email, a.new_email from audit_trail a join iter1 b on (a.old_email = b.new_email)
) select * from iter1 union iter2;
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

ERROR:  syntax error at or near "iter2" at character 264 …
Run Code Online (Sandbox Code Playgroud)

postgresql

4
推荐指数
1
解决办法
2965
查看次数

与Google Drive API v3等效的File.setTitle方法

这是一个官方的例子:

package com.google.api.services.samples.drive.cmdline;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.media.MediaHttpDownloader;
import com.google.api.client.googleapis.media.MediaHttpUploader;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.Preconditions;
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Collections;

/**
 * A sample application that runs multiple requests against the Drive API. The requests this sample
 * makes are:
 * <ul>
 * <li>Does a resumable media …
Run Code Online (Sandbox Code Playgroud)

java google-drive-api

4
推荐指数
1
解决办法
1340
查看次数

intellij中的自定义注释标记

当你todo:在评论中,intellij可以检测到它并在待办事项列表中显示它.如何识别某些自定义标记?例如,config:.

intellij-idea

4
推荐指数
1
解决办法
457
查看次数

R引用类中是否有析构函数?

就像一个测试:

myclass = setRefClass("myclass",
                       fields = list(
                           x = "numeric",
                           y = "numeric"
                       ))


myclass$methods(
    dfunc = function(i) {
        message("In dfunc, I save x and y...")
        obj = .self
        base::save(obj, file="/tmp/obj.rda")
    }
    )

myclass$methods(
    print = function() {
            if (.self$x > 10) {
                stop("x is too large!")
            }
    message(paste("x: ", .self$x))
    message(paste("y: ", .self$y))
    }
    )

myclass$methods(
    initialize = function(x=NULL, y=NULL, obj=NULL) {
        if(is.null(obj)) {
            .self$x = x
            .self$y = y
        }
        else {
            .self$x = obj$x
            .self$y = obj$y …
Run Code Online (Sandbox Code Playgroud)

r reference-class

3
推荐指数
1
解决办法
618
查看次数