Skip to content

Instantly share code, notes, and snippets.

View j2labs's full-sized avatar

The Ghost Of J2 Labs j2labs

View GitHub Profile
@j2labs
j2labs / gist:1046726
Created June 25, 2011 18:15
Stream API example in Python using PyCurl
#!/usr/bin/env python
# Example for reading from the Twitter streaming API using pycurl
#
# PyCurl is not installed by default so install it like this:
#
# pip install pycurl
#
# The streaming api methods are documented here:
@j2labs
j2labs / gist:1043833
Created June 23, 2011 22:57
logging_decorator_example.py
#!/usr/bin/env python
import logging
import time
logging.basicConfig(level=logging.DEBUG,
filename='whatevz.log')
def log_runtime(method):
def wrapper(*a, **kw):
@j2labs
j2labs / gist:1042932
Created June 23, 2011 16:34
JSON speed test in Javascript / Node.js (not sure who to attribute for this speed)
/*
* A typical run looks like this:
*
* Dumping:
* JSON: 2.017
* Loading:
* JSON: 1.93
* eval(): 25.387
*/
@j2labs
j2labs / gist:1042778
Created June 23, 2011 15:34
JSON speed test with many implementations
#!/usr/bin/env python
# The output geneally looks like this:
#
# $ ./serialization.py
# Dumping:
# json: 6.40960884094
# simplejson: 6.82945179939
# cjson: 2.23045802116
# ujson: 0.806604146957
#!/usr/bin/env python
from tweepy.models import Model, User
import urllib
import json
import copy
general_function_map = {
'created_at': lambda dt: '%s' % dt.strftime('%x'),
-module(amazon).
-include_lib("erlcloud/include/erlcloud.hrl").
-include_lib("erlcloud/include/erlcloud_ec2.hrl").
-export([init_ec2conn/0,
create_instances/2]).
%%
%% These two are required first
#!/usr/bin/env python -u
# Using Python 2.6
# Starting json... done: 17.8986079693
# Starting simplejson... done: 6.75326800346
# Starting cjson... done: 2.19219493866
# Starting ujson... done: 0.742480039597
# Starting pickle... done: 43.2633650303
# Starting cPickle... done: 6.45727396011
# Starting marshal... done: 1.2130010128
#!/usr/bin/env python -u
# python 3.2
# Starting json... done: 17.7406787872
# Starting simplejson... done: 6.82341694832
# Starting cjson... done: 2.29899692535
# Starting ujson... done: 0.729449987411
# Starting pickle... done: 45.2784938812
# Starting cPickle... done: 6.48070406914
>>> print "%0.20f" % (0.1 + 0.2)
0.30000000000000004441
>>> print "%0.30f" % (0.1 + 0.2)
0.300000000000000044408920985006
>>> print "%0.30f" % (0.2 + 0.2)
0.400000000000000022204460492503
>>> print "%0.30f" % (0.3 + 0.2)
0.500000000000000000000000000000
>>> print "%0.30f" % (0.3 + 0.3)
#!/usr/bin/env python
"""
Least-recently used (LRU) queue device
Clients and workers are shown here in-process
Author: Guillaume Aubert (gaubert) <guillaume(dot)aubert(at)gmail(dot)com>
"""