This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readFile('static/grid.html', 'ascii').addCallback(function(data){ | |
sys.debug('test'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int* foo(){ | |
static int out[2] = {1,2}; | |
return out; | |
} | |
int main(int argv, char* argc){ | |
int* bar = foo(); | |
printf("%p\n", bar); | |
printf("%d %d\n", bar[0], bar[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var url = require('url'); | |
var sys = require('sys'); | |
var http = require('http'); | |
require('./ejs'); // EJS, http://embeddedjs.com/ | |
/* | |
* Server-side controller methods | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _deref = function (doc, field, col) { | |
var oid = ObjectId(doc[field]); | |
delete doc[field]; | |
doc[field] = db[col].findOne({_id:oid}); | |
return doc; | |
} | |
var deref = function(field, collection){ | |
// C-C-C-Closure!! | |
return function(doc){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> x = {'a':1,'b':"foo",'c':ObjectId()} | |
>>> print x | |
{'a': 1, 'c': ObjectId('4c4f4f5e2554c813e4000001'), 'b': 'foo'} | |
>>> print json.dumps(x) | |
Traceback (most recent call last): | |
[...] | |
TypeError: ObjectId('4c4f4f5e2554c813e4000001') is not JSON serializable | |
>>> print json.dumps(x, cls=MongoEncoder) | |
'{"a": 1, "c": ObjectId("4c4f4f5e2554c813e4000001"), "b": "foo"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cPickle as pickle | |
from UserDict import UserDict | |
class HashableDict(UserDict): | |
def __hash__(self): | |
return hash(pickle.dumps(dict([(k,self.data[k]) for k in sorted(self.data.keys())]))) | |
>>> d1 = HashableDict({'a':1, 'b':2, 'c':3}) | |
>>> d2 = HashableDict({'a':1, 'b':2, 'c':3}) | |
>>> d3 = HashableDict({'a':1, 'b':2, 'c':4}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import JSONEncoder | |
from pymongo.objectid import ObjectId | |
class MongoEncoder(JSONEncoder): | |
def _iterencode(self, o, markers=None): | |
if isinstance(o, ObjectId): | |
return """ObjectId("%s")""" % str(o) | |
else: | |
return JSONEncoder._iterencode(self, o, markers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import JSONEncoder | |
from pymongo.objectid import ObjectId | |
class MongoEncoder(JSONEncoder): | |
def _iterencode(self, o, markers=None): | |
if isinstance(o, ObjectId): | |
return """ObjectId("%s")""" % str(o) | |
else: | |
return JSONEncoder._iterencode(self, o, markers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import JSONEncoder | |
from pymongo.objectid import ObjectId | |
class MongoEncoder(JSONEncoder): | |
def _iterencode(self, o, markers=None): | |
if isinstance(o, ObjectId): | |
return """ObjectId("%s")""" % str(o) | |
else: | |
return JSONEncoder._iterencode(self, o, markers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import struct | |
import socket | |
import hashlib | |
import sys | |
from select import select | |
import re | |
import logging | |
from threading import Thread | |
import signal |
OlderNewer