我想在C#中使用基于定时器的while循环替换基于while循环的计数器.
示例:
while(count < 100000)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
至
while(timer < X seconds)
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
我有两种类型的C#.NET定时器本的System.Timers和Threading.Timers.哪一个会更好用,怎么样.我不想在计时器上增加额外的时间消耗或线程问题.
所有人都知道,如果我们打电话,undefined.test我们将收到以下错误(两者都相同:NodeJS和Javascript):
$ node
> undefined.test
TypeError: Cannot read property 'test' of undefined
at repl:1:11
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
Run Code Online (Sandbox Code Playgroud)
那是对的!
通过一周我在调试以下问题时浪费了大约30分钟:脚本意外停止并且没有抛出任何错误.
我有一个urls应该是一个对象的变量:
var urls = settings.urls || {};
Run Code Online (Sandbox Code Playgroud)
然后在接下来的行中,我需要获取shop密钥,urls这是一个字符串:
var shop = urls.shop || "/";
Run Code Online (Sandbox Code Playgroud)
我开始添加console.log以查找变量的值:
console.log(urls); // undefined
var shop = urls.shop || "/";
console.log("Passed"); …Run Code Online (Sandbox Code Playgroud) 在修复问题时,我想确保在提交消息中关闭正确的问题:"Fixed #issueId".
为了更快,我想列出终端中的存储库问题.这可能是git命令吗?
我想象下面的东西:
$ git issues --all
+---------------------------------------+
| Repository Name - Issues |
+---------------------------------------+
| # | Title | Status |
+---------------------------------------+
| 1 | Lorem Ipsum 1 | OPEN |
| 2 | Lorem Ipsum 2 | WONTFIX |
| 3 | Lorem Ipsum 3 | RESOLVED|
| 4 | Lorem Ipsum 4 | INVLID |
+---------------------------------------+
Run Code Online (Sandbox Code Playgroud) 该问题的解决方案工作正常:
而不是做:
$ mongo my_db_name -u superuser -p 1234
Run Code Online (Sandbox Code Playgroud)
我做
$ mongo admin -u superuser -p 1234 # connecting as super user to admin db
> use anotherDb
Run Code Online (Sandbox Code Playgroud)
在外壳中。
NodeJS中的解决方案是什么?
我尝试连接,mongodb://superuser:1234@localhost:27017/my_db_name但出现此错误:
{ [MongoError: auth fails] name: 'MongoError', code: 18, ok: 0, errmsg: 'auth fails' }
我的代码是:
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient;
MongoClient.connect("mongodb://superuser:1234@localhost:27017/my_db_name",
function(err, db) {
if (err) { return console.log(err); }
console.log("Successfully connected.");
}
);
Run Code Online (Sandbox Code Playgroud)
请注意,超级用户是可以在任何数据库中写入和读取权限的全能用户。 …
我想找到许多只做1个查询的随机记录.
我试过了:
var count = db.collections.count()
var rand = function(){return Math.floor( Math.random() * count )}
db.collection.find().limit(-1).skip(rand()).next();
Run Code Online (Sandbox Code Playgroud)
但是这只返回一个文档.我需要获得更多随机记录.
我怎样才能做到这一点?
我想toString为数据类型创建自己的函数.
我们来举个例子:
JSON.stringify({}) // "{}"
Run Code Online (Sandbox Code Playgroud)
我想要"test"归还.所以,我试图修改对象原型:
Object.prototype.toString = function () { return "test"; }
Run Code Online (Sandbox Code Playgroud)
然后:也JSON.stringify({})回来"{}"了.
我确信有一个函数可以重写以返回自定义值.
那是什么功能?
我有一个非常基本的http服务器:
require("http").createServer(function (req, res) {
res.end("Hello world!");
}).listen(8080);
Run Code Online (Sandbox Code Playgroud)
如何监听服务器崩溃,以便我可以发送500状态代码作为响应?
process.on("uncaughtException", handler)在process级别上听作品,但我没有请求和响应对象.
我看到的一个可能的解决方案是try - catch在createServer回调中使用语句,但我在寻找是否有更好的解决方案.
我试着error在server对象上侦听事件,但没有任何反应:
var s = require("http").createServer(function (req, res) {
undefined.foo; // test crash
res.end("Hello world!");
});
s.on("error", function () { console.log(arguments); });
s.listen(8080);
Run Code Online (Sandbox Code Playgroud) 运行时出现以下错误compass create my-theme -r bootstrap-sass --using bootstrap:
$ compass create my-theme -r bootstrap-sass --using bootstrap
directory my-theme/
create my-theme/config.rb
Compass can't find any Sass files to compile.
Is your compass configuration correct?.
If you're trying to start a new project, you have left off the directory argument.
Run "compass -h" to get help.
Run Code Online (Sandbox Code Playgroud)
我在运行上述命令的任何目录中都收到此错误.
相关产出:
$ compass --version
Compass 1.0.1 (Polaris)
Copyright (c) 2008-2014 Chris Eppstein
Released under the MIT License.
Compass is charityware.
Please make a …Run Code Online (Sandbox Code Playgroud) 我使用以下代码创建了一个ACE编辑器实例:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");Run Code Online (Sandbox Code Playgroud)
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/ace.js"></script>
<div id="editor">function foo (x) {
return 2 * x;
}
function bar (y) {
return foo(y) / 2;
}
console.log(bar(2) + foo(3));</div>Run Code Online (Sandbox Code Playgroud)
我想控制缩进尺寸(特别是按下tab键时).我怎样才能做到这一点?
我搜索了API参考但我找不到解决方案......
Git接受许多不同的URL格式(例如ssh,http,https等)。有什么规格/官方文档可以找到受支持的git url格式吗?
我写了一个git url解析器,我想确保在那里做的是正确的。
在这里,在YonderGit上,我找到了以下列表。由于https://<token>:x-oauth-basic@host.xz/path/to/repo.git不存在,因此不完整。
安全外壳传输协议
ssh://user@host.xz:port/path/to/repo.git/ssh://user@host.xz/path/to/repo.git/ssh://host.xz:port/path/to/repo.git/ssh://host.xz/path/to/repo.git/ssh://user@host.xz/path/to/repo.git/ssh://host.xz/path/to/repo.git/ssh://user@host.xz/~user/path/to/repo.git/ssh://host.xz/~user/path/to/repo.git/ssh://user@host.xz/~/path/to/repo.gitssh://host.xz/~/path/to/repo.gituser@host.xz:/path/to/repo.git/host.xz:/path/to/repo.git/user@host.xz:~user/path/to/repo.git/host.xz:~user/path/to/repo.git/user@host.xz:path/to/repo.githost.xz:path/to/repo.gitrsync://host.xz/path/to/repo.git/Git传输协议
git://host.xz/path/to/repo.git/git://host.xz/~user/path/to/repo.git/HTTP / S传输协议
http://host.xz/path/to/repo.git/https://host.xz/path/to/repo.git/本地(文件系统)传输协议
/path/to/repo.git/path/to/repo.git/~/path/to/repo.gitfile:///path/to/repo.git/file://~/path/to/repo.git/