Skip to content

Instantly share code, notes, and snippets.

@saivenkat
saivenkat / buildbot_messagepub.py
Created March 10, 2010 12:48
MessagePub notification for buildbot build
'''
Example Usage:
from buildbot.status import messagepub
c['status'].append(messagepub.Notifier(recipient="a@b.c", key="Your messagepub key"))
'''
import urllib, base64
from zope.interface import implements
@saivenkat
saivenkat / find_line_count_of_files_in_dir.sh
Created February 24, 2010 07:07
Find line count of all files in a directory
for file in `find . -type f`; do echo $file `cat $file | wc -l`; done
@saivenkat
saivenkat / clojure.rb
Created February 19, 2010 11:30
Using Clojure STM in Ruby using cloby
require "java"
require "ClojureLibrary.jar"
require "clojure-1.0.0.jar"
include_class "org.jruby.clojure.ClojureLibrary"
clj_lib = ClojureLibrary.new
clj_lib.load(JRuby.runtime, true)
@saivenkat
saivenkat / jruby-jetlang-example.rb
Created February 16, 2010 10:27
JRuby Jetlang Message Passing Example
require "java"
require "jetlang-0.2.0.jar"
include_class "org.jetlang.fibers.ThreadFiber"
include_class "org.jetlang.channels.MemoryChannel"
class Arnie
def initialize(channel, consumer)
@channel = channel
@saivenkat
saivenkat / glom.clj
Created January 29, 2010 10:18
The problem: given a list of strings, produce a list where sequential non-empty strings are concatenate
(use 'clojure.test)
(defn concat-elements [x y]
(cond (empty? x) (apply str (concat "-" y))
(empty? y) (apply str (concat x "-"))
:else (apply str(concat x y))))
(defn glom [x]
(remove #(empty? %)
(seq (.split (apply str (reduce concat-elements x)) "-"))))
@saivenkat
saivenkat / glom.rb
Created January 29, 2010 07:34
The problem: given a list of strings, produce a list where sequential non-empty strings are concatenate
require "test/unit"
class GlomTest < Test::Unit::TestCase
def glom(l)
l.inject([""]) do |r,x|
r << "" if x.empty?
r.last << x
r
@saivenkat
saivenkat / eventlet_url_loader.py
Created January 28, 2010 08:58
Eventlet based url timer
import time
from eventlet import coros
from eventlet.green import urllib2
def fetch(url):
print "%s fetching %s" % (time.asctime(), url)
data = urllib2.urlopen(url)
print "%s fetched %s" % (time.asctime(), data.read())
def load(url, pool_size):
@saivenkat
saivenkat / never_block_http.rb
Created January 28, 2010 08:21
Neverblock Net/Http problem
require "rubygems"
require "neverblock"
require "eventmachine"
require "net/http"
require "uri"
def load_timer(url, number_of_requests=50)
start = Time.now
EM.run do
@pool = NB::Pool::FiberPool.new(number_of_requests)
@saivenkat
saivenkat / udp_load_generator.py
Created January 14, 2010 05:17
UDP load generator
# Inspired fromCorey Goldberg's load gen work.
import sys
import time
import socket
from threading import Thread
host = '127.0.0.1'
port = 21567
data = "This is a test packet"
@saivenkat
saivenkat / em-couchdb-sample.rb
Created December 30, 2009 18:41
Checkout em-couchdb project
EventMachine.run do
couch = EventMachine::Protocols::CouchDB.connect :host => 'localhost', :port => 5986
couch.get_all_dbs {|dbs| puts dbs}
couch.create_db("test-project")
couch.get_all_dbs {|dbs| puts dbs}
couch.get_db("test-project") do |db|
puts db
couch.save(db["db_name"], {:name => "couchd", "description" => "awesome"}) do |doc|
couch.get(db["db_name"], doc["id"]) do |doc|
puts doc