这可能是一个非常愚蠢的问题,但是如何在我的代码中打开这些调试消息呢?
#ifdef DEBUG_MSG
printf("initial state : %d\n", initial_state);
#endif
Run Code Online (Sandbox Code Playgroud)
提前谢谢了,
我正试图让Python扭曲在我的Ubuntu 11.04盒子上工作.
我做到了 sudo apt-get install python-twisted
但是,当我尝试以下代码时:
from twisted.internet import protocol, reactor
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
reactor.listenTCP(1234, EchoFactory())
reactor.run()
Run Code Online (Sandbox Code Playgroud)
我得到这个错误,我不能到底:
Traceback (most recent call last):
File "eamorr.py", line 1, in <module>
from twisted.internet import protocol, reactor
File "/home/eamorr/Desktop/twisted.py", line 1, in <module>
ImportError: No module named internet
Run Code Online (Sandbox Code Playgroud)
任何帮助都非常感谢.
我有一个mongodb对象如下:
array (
'_id' => new MongoId("4cc97fb0247ae8747ec5fefb"),
'posts' =>
array (
0 =>
array (
'comment' => 'Eamorr',
'fromUname' => 'Eamorr',
'time' => 1288273840,
'UTC' => '2010-10-28T14:50:40+01:00',
'ip' => '127.0.0.1',
'id' => '123lasdfiqwoei28asdf',
),
1 =>
array (
'comment' => 'Hello',
'fromUname' => 'Eamorr',
'time' => 1288277023,
'UTC' => '2010-10-28T15:43:43+01:00',
'ip' => '127.0.0.1',
'id' => 'qopqwier982389qwfa',
),
2 =>
array (
'comment' => 'Hello',
'fromUname' => 'Anonymous',
'time' => 1288283506,
'UTC' => '2010-10-28T17:31:46+01:00',
'ip' => '127.0.0.1',
'id' => 'ioqwoeias892398wrf',
), …Run Code Online (Sandbox Code Playgroud) 问候,
我有以下jQuery Mobile代码:
<div data-role="content">
A confirmation code has been sent to your mobile phone via SMS
<br><br>
To proceed, please enter the 3-digit confirmation code below:
<br>
<input id="verifySMS_code" type="text" /><br>
<a id="verifySMS_submit" href="#" data-role="button">Submit</a>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的javascript:
$(document).ready(function(){
$("#verifySMS_submit").live("click",function() {
alert('hi');
var code=$('input#verifySMS_code').val();
alert(code);
});
});
Run Code Online (Sandbox Code Playgroud)
'hi'出现在第一个警告框中,但是''出现在第二个警告框中 - 即完全空白!
我试过document.getElementById('verifySMS_code')也无济于事.
我甚至尝试过jquery mobile 1.0a3pre
这对我来说是一个非常严重的问题,我不知道如何解决它.
我希望有人能帮帮忙.
提前谢谢了,
如何从以下HEX流创建.gif文件:
0d 0a 0d 0a 47 49 46 38 39 61 01 00 01 00 80 ff 00 ff ff ff 00 00 00 2c 00 00 00 00 01 00 01 00 00 02 02 44 01 00 3b
3b是GIF文件终止符
我正按照http://en.wikipedia.org/wiki/Graphics_Interchange_Format#Example_GIF_file上的指南进行操作
我想在Perl或C/C++中实现它.任何语言都可以.
提前谢谢了,
谢谢各位回复.我删除了领先的'0d 0a 0d 0a'...
这就是我所熟悉的:
#!/usr/bin/perl
use strict;
use warnings;
open(IN,"<test.txt");
open(OUT,">test.gif");
my @lines=<IN>;
foreach my $line (@lines){
$line=~s/\n//g;
my @bytes=split(/ /,$line);
foreach my $byte (@bytes){
print OUT $byte;
}
}
close(OUT);
close(IN);
Run Code Online (Sandbox Code Playgroud) 我有以下从谷歌的sparsehash网站获得的C++代码:
#include <iostream>
#include <google/dense_hash_map>
#include <string.h>
using google::dense_hash_map; // namespace where class lives by default
using std::cout;
using std::endl;
using ext::hash; // or __gnu_cxx::hash, or maybe tr1::hash, depending on your OS
struct eqstr
{
bool operator()(const char* s1, const char* s2) const
{
return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
}
};
int main(void){
dense_hash_map<const char*, int, hash<const char*>, eqstr> months;
months.set_empty_key(NULL);
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = …Run Code Online (Sandbox Code Playgroud) 我在我的服务器上运行以下node.js:
var net=require('net');
var util=require('util');
var server=net.createServer(function(conn){
conn.on('connect',function(){
util.puts('connect');
});
conn.on('data',function(data){
util.puts(data);
});
});
server.listen(5000,'172.16.1.197');
Run Code Online (Sandbox Code Playgroud)
这工作得很好,我可以telnet到172.16.1.197:5000,它的行为符合预期.
现在,我有一个客户端在另一个IP地址为172.16.1.218的盒子上运行,我只是想向服务器发送一条消息.
function sendAMessage(payLoad){
//what to put in here?
}
Run Code Online (Sandbox Code Playgroud)
payLoad应该打印在服务器端.
我知道这看起来很简单,但我真的无法理解它 - 我对node.js很新.
提前谢谢了,
添加一些代码:
这是客户端(172.16.1.218):
var http = require('http');
var util=require('util');
var net=require('net');
var localHash={};
var chunkLength=100;
http.createServer(function(request, response) {
var proxy = http.createClient(80, request.headers['host'])
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(x) {
var responseData=x.toString("binary");
var bytes=getBytes(responseData);
util.puts(bytes.length);
for(var i=0;i<bytes.length;i++){
var hash=DJBHash(bytes[i]);
//util.puts(hash);
if(hash in localHash){
//in hash, …Run Code Online (Sandbox Code Playgroud) 我无法编译我的C++程序.如您所见,我正在编写Node.js插件.这是代码(Eamorr_addon.cpp):
#include <iostream>
#include <v8.h>
#include <node.h>
#include <gmp.h>
#include "Definitions.h"
#include "Rk.h"
#include "tbb/concurrent_hash_map.h"
//#include <tbb/concurrent_vector.h>
using namespace std;
using namespace v8;
static Handle<Value> Echo(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1) {
return ThrowException(Exception::TypeError(String::New("Bad argument")));
}
return scope.Close(args[0]);
}
extern "C" void init (Handle<Object> target)
{
HandleScope scope;
target->Set(String::New("hello"), String::New("world"));
NODE_SET_METHOD(target, "echo", Echo);
}
Run Code Online (Sandbox Code Playgroud)
我删除线条时一切正常#include "tbb/concurrent_hash_map.h".
这是我的gyp make文件:
{
'targets': [
{
'target_name':'Eamorr_addon',
'sources':['src/Eamorr_addon.cpp'],
'include_dirs': ['/usr/include','/usr/local/include/'],
'cflags': ['-Wall','-fopenmp'],
'ldflags': ['-ltbb','-lgmp']
}
]
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时 …
我有以下代码:
#include <stdio.h>
#include <sys/time.h>
#include <event.h>
void say_hello(int fd, short event, void *arg){
printf("Hello\n");
}
int main(int argc, const char* argv[])
{
struct event ev;
struct timeval tv;
tv.tv_sec = 3;
tv.tv_usec = 0;
event_init();
evtimer_set(&ev,say_hello,NULL);
evtimer_add(&ev, &tv);
event_dispatch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是"你好"打印一次,然后程序退出...
我想让它无限期地输出"你好".
这该怎么做?提前谢谢了,
所以我有一个回调函数,它提供了一个json对象:
function(object){
var data=object.packet.link.ip.tcp.data;
console.log(data.toString());
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是任何packet/link/ip/tcp/data都可能是"未定义的" - 我的node.js程序每遇到一个未定义的变量就会失败.
我尝试将"data"的声明放在try/catch中,但是我不断收到"未定义"错误 - 我的猜测是我需要放置object/object.packet/object.packet.link/object.packet.link .IP /等.在try/catch中.
所以,我发现了一些优雅的咖啡因:
if object?.packet?.link?.ip?.tcp?.data? then doStuff()
Run Code Online (Sandbox Code Playgroud)
编译为:
var _ref, _ref1, _ref2, _ref3;
if ((typeof object !== "undefined" && object !== null ? (_ref = object.packet) != null ? (_ref1 = _ref.link) != null ? (_ref2 = _ref1.ip) != null ? (_ref3 = _ref2.tcp) != null ? _ref3.data : void 0 : void 0 : void 0 : void 0 : void 0) != null) {
//doStuff:
var …Run Code Online (Sandbox Code Playgroud)