小编ste*_*t99的帖子

安装以前版本的软件包

我使用nvm下载节点v0.4.10并安装了npm以使用该版本的节点.

我正在尝试安装快递使用

npm install express -g
Run Code Online (Sandbox Code Playgroud)

我收到一个表达需要节点版本> = 0.5.0的错误.

好吧,这很奇怪,因为我遵循节点+ express + mongodb教程的指示,这里使用了节点v0.4.10,所以我假设express是/可用于节点v0.4.10.如果我的假设是正确的,我如何告诉npm获取可以使用我的设置的版本?

node.js npm

838
推荐指数
6
解决办法
63万
查看次数

C++ STL map:是访问时间O(1)?

关键是在std::mapO(1)上查找?我以为直到我想到它为止.它基于树实现,因此查找时间应为O(log N),对吗?

而且,是否有可能让O(1)查找字符串键std::unordered_map

c++ std data-structures c++11

32
推荐指数
2
解决办法
3万
查看次数

origin/branch_name和branch_name之间的区别?

推送到bitbucket.

如果我这样做:git push origin origin/branch_name我的提交没有被推送.

Total 0 (delta 0), reused 0 (delta 0)
Run Code Online (Sandbox Code Playgroud)

如果我做git push origin branch_name我的提交被推送:

Counting objects: 160, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (20/20), 2.10 KiB | 0 bytes/s, done.
Total 20 (delta 6), reused 0 (delta 0)
Run Code Online (Sandbox Code Playgroud)

那么branch_name前面的起源/平均值是多少?为什么这很重要?

git bitbucket

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

c ++ 11 emplace_back和push_back语法与struct

我正在使用MSVC,Visual Studio 2013.

假设我有一个结构:

struct my_pair {
    int foo, bar;
};
Run Code Online (Sandbox Code Playgroud)

我想有效地添加一堆这些,而不是创建一个临时的,然后丢弃它:

vector<my_pair> v;
v.push_back(41, 42); // does not work              [a]
v.push_back({41,42}); // works                     [b]
v.emplace_back(41,42); // does not work            [c]
v.emplace_back({41,42}); // does not work          [d]
v.emplace_back(my_pair{41,42}); //works            [e]
Run Code Online (Sandbox Code Playgroud)

现在,如果我将构造函数和复制构造函数添加到我的代码中:

my_pair(int foo_, int bar_) : foo(foo_), bar(bar_) 
{
    cout << "in cstor" << endl;
}
my_pair(const my_pair& copy) : foo(copy.foo), bar(copy.bar)
{
    cout << "in copy cstor" << endl;
}
Run Code Online (Sandbox Code Playgroud)

然后行为改变:

v.push_back(41, 42); // does not work                              [f]
v.push_back({41,42}); …
Run Code Online (Sandbox Code Playgroud)

c++ rvalue-reference c++11

17
推荐指数
1
解决办法
5866
查看次数

javascript visual studio 2013缩进

我开始在Visual Studio 2013上玩javascript,我无法弄清楚为什么它不会自动将光标定位到正确的缩进级别,而是总是重置回头部.例如:

function foo(y) {
    var f = function bar(x) {
    |<-- cursor should be here, but ends up
|<-- over here
}
Run Code Online (Sandbox Code Playgroud)

有没有人看到这个,你怎么改变它?

我安装了typescript,nodejs插件,这就是它.

editor visual-studio visual-studio-2013

14
推荐指数
1
解决办法
3674
查看次数

在node.js中使用参数时,对象没有方法'reduce'错误?

为什么我arguments这样使用时会出错?

function sum(){
    return arguments.reduce(function(a,b){
        console.log(a+b)
        return a+b;
    },0);
}

sum(1,2,3,4);
Run Code Online (Sandbox Code Playgroud)

错误:

/Users/bob/Documents/Code/Node/hello.js:2
return arguments.reduce(function(a,b){
                 ^
TypeError: Object #<Object> has no method 'reduce'
    at sum (/Users/bob/Documents/Code/Node/hello.js:2:19)
    at Object.<anonymous> (/Users/bob/Documents/Code/Node/hello.js:8:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:903:3
Run Code Online (Sandbox Code Playgroud)

这是来自Crockford先生的JS讲座.

javascript node.js

10
推荐指数
1
解决办法
5216
查看次数

是否应该从现在开始声明所有C++函数的rvalue?

我为什么要或不应该创建我的所有函数和成员函数来取一个带有a的rvalue版本lvalue?你总是可以转发lvalue到右转,对吧?我甚至可以拥有const rvalue,为什么这是一个坏主意或好主意呢?

我在代码中的意思如下.该"&&" rvalue引用允许用户使用临时对象,并且仍然可以lvalue通过简单的转发使用.所以考虑到这一点,我为什么要提供print_string(string& str)(lvalue参考)c ++ 11中的任何函数(除了const参考,因为rvalue有好的)?

#include <iostream>
#include <string>
#include <utility>

using namespace std;


void print_string(string&& str)
{
    str += "!!!";
    cout << str << endl;
}
void print_string2(string& str)
{
    str += "???";
    cout << str << endl;
}

int main(int argc, char* argv[])
{

    print_string("hi there");  // works
    print_string(string("hi again")); // works
    string lvalue("lvalue");
    print_string(forward<string>(lvalue)); // …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

8
推荐指数
2
解决办法
1878
查看次数

AWS Glue编写具有分区的镶木地板

我能够写成实木复合地板格式,并按如下所示进行分区:

jobname = args['JOB_NAME']
#header is a spark DataFrame
header.repartition(1).write.parquet('s3://bucket/aws-glue/{}/header/'.format(jobname), 'append', partitionBy='date')
Run Code Online (Sandbox Code Playgroud)

但是我无法使用Glue的DynamicFrame做到这一点。

header_tmp = DynamicFrame.fromDF(header, glueContext, "header")
glueContext.write_dynamic_frame.from_options(frame = header_tmp, connection_type = "s3", connection_options = {"path": 's3://bucket/output/header/'}, format = "parquet")
Run Code Online (Sandbox Code Playgroud)

我已经尝试将dict partitionBy作为connection_optionsdict 的一部分进行传递,因为AWS文档说镶木地板Glue不支持任何格式选项,但是那没有用。

这有可能吗?至于这样做的原因,我认为工作书签需要工作,因为这目前对我而言不起作用。

amazon-web-services apache-spark pyspark aws-glue

6
推荐指数
2
解决办法
4229
查看次数

如何在Clojure中的try catch块中创建占位符变量

我有一些Java代码,我会这样写:

String var1;
String var2;
int var3;

try {
    String var1 = func1_that_might_throw();
    String var2 = func2_that_might_throw();
    int var3 = func3_that_might_throw();

    do_something_that_might_throw(var1, var2, var3);
} catch (Exception e) {
    cleanup_resources(var1, var2, var3);
}
Run Code Online (Sandbox Code Playgroud)

把它变成Clojure是一场噩梦.

(try+
  (let [var1 (func1_that_might_throw)
        var2 (func2_that_might_throw)
        var3 (func3_that_might_throw)]
    (do_something_that_might_throw var1 var2 var3))
  (catch Exception e
    (cleanup_resources var1 var2 var3)))
Run Code Online (Sandbox Code Playgroud)

问题是var1,var2,var3不要在catch块存在.移动let到外面try是有问题的,因为功能1到3可能会抛出并需要被捕获并清理资源.

我认为我可能需要的只是try之外的三个占位符变量,但是a)我甚至不知道clojure是否允许这样做,并且b)使一切变得更复杂.我不认为这是一个老将如何在clojure中做到这一点.这里有什么解决方案?

clojure

5
推荐指数
1
解决办法
322
查看次数

Java匿名内部类List

我想通过匿名内部类在运行时将方法附加到LinkedList对象.这可能吗?

例如:

    LinkedList<String> paths = new LinkedList<String>() {
        void addAllIfNotNull(Collection<String> c) {
            if(c != null) {
                addAll(c);
            }
        }
    };
    paths.add(list1);
    paths.add(list2);
    paths.add(list3);
    ...
    paths.add(listN);
Run Code Online (Sandbox Code Playgroud)

无需执行if(list_i不为null)addAll(list_i)?

这似乎不可能,因为LinkedList没有AddAllIfNotNull方法.有没有办法让这项工作?

java

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