This file contains hidden or 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
| //Sample usage | |
| //var redis = require("./redis"); | |
| //var sys = require('sys'); | |
| //var c = redis.connect('0.0.0.0', 6379); | |
| //c.addListener("connect", function (){ | |
| // c.hasKey("foss").addCallback(function(data) { | |
| // sys.puts("Cool " + data); | |
| // c.quit(); | |
| // }); |
This file contains hidden or 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
| class HTTPClient(object): | |
| _inst = None | |
| def __new__(cls): | |
| if cls._inst: | |
| return cls._inst | |
| else: | |
| o = super(HTTPClient, cls).__new__(cls) | |
| cls._inst = o | |
| return o |
This file contains hidden or 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 StringIO | |
| from eventlet import coros | |
| from eventlet.green import urllib2 | |
| class EventCouchDb(): | |
| def __init__(self, url): | |
| self.url = url | |
| def fetch(self, url, callback): | |
| callback.write(urllib2.urlopen(url).read()) | |
| def get(self, callback): |
This file contains hidden or 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
| require "neverblock" | |
| require "net/http" | |
| require "uri" | |
| def load_timer(url, number_of_requests=50) | |
| @pool = NB::Pool::FiberPool.new(number_of_requests) | |
| start = Time.now | |
| number_of_requests.times do | |
| @pool.spawn do | |
| request_url = URI.parse(url) |
This file contains hidden or 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 httplib2 import Http | |
| from urllib import urlencode | |
| class TwitterClient: | |
| def __init__(self, username, password): | |
| self.username = username | |
| self.password = password | |
| def update_status(self, message): | |
| client = Http() |
This file contains hidden or 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
| def fibonacci(): | |
| i = j = 1 | |
| while True: | |
| result, i, j = i, j, i + j | |
| yield result | |
| for k in fibonacci(): | |
| print k | |
| if (k > 100) : break |
This file contains hidden or 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
| def increment(): | |
| i = 0 | |
| while True: | |
| yield i | |
| i += 1 | |
| for j in increment(): | |
| print i | |
| if (j > 10) : break |
This file contains hidden or 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
| -module(pingpong). | |
| -export([ping/0, pong/0]). | |
| ping()-> | |
| receive | |
| {Pid, ping} -> | |
| io:fwrite("Ping received Pong~n",[]), | |
| timer:sleep(3000), | |
| Pid ! {self(), pong}, | |
| ping(); |
This file contains hidden or 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
| def factorial_tail(number) | |
| proc_fact = lambda do |acc, x| | |
| if x <= 0 | |
| acc | |
| else | |
| proc_fact.call(x * acc, x - 1) | |
| end | |
| end | |
| return proc_fact.call(1, number) | |
| end |
This file contains hidden or 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
| #install libnotify-bin for this to work. Do a apt-get install libnotify-bin | |
| def notify(title, message, urgency = 'normal') | |
| command = "notify-send -u #{urgency} '#{title}' '#{message}'" | |
| system command | |
| end |