Skip to content

Instantly share code, notes, and snippets.

@cgbystrom
cgbystrom / redischat.py
Created December 7, 2010 23:02
Simple Redis chat experiment
# Monkey patching with redis-py didn't work out so well
#from gevent import monkey; monkey.patch_all()
import gevent
import redis
import time
import random
client = redis.Redis(host='localhost', port=6379, db=0)
client.flushdb()
@cgbystrom
cgbystrom / redischat.py
Created December 7, 2010 23:02
Simple Redis chat experiment
# Monkey patching with redis-py didn't work out so well
#from gevent import monkey; monkey.patch_all()
import gevent
import redis
import time
import random
client = redis.Redis(host='localhost', port=6379, db=0)
client.flushdb()
@cgbystrom
cgbystrom / node-beaconpush_example.js
Created February 20, 2011 19:17
Quick API overview of node-beaconpush
var bp = require('beaconpush');
// Create a new client
var beaconpush = new bp.Client('<your-api-key>', '<your-secret-key>');
// Get number of users currently connected to your site
beaconpush.usersConnected(function (numConnected) {
console.log('There are ' + numConnected + ' users online');
});
@cgbystrom
cgbystrom / TestArrayIteration.java
Created May 8, 2011 12:51
Compare iteration over native array vs ArrayList (JVM playing tricks on me?)
import java.util.ArrayList;
public class TestArrayIteration {
public static void testArray() {
Integer[] arr = new Integer[1000];
for (int i = 0; i < 1000; i++) {
arr[i] = 1;
}
int total = 0;
@cgbystrom
cgbystrom / StringTokenizer.java
Created May 22, 2011 10:28
Super-fast Java string tokenizer
public class StringTokenizer {
public static String[] tokenize(String string, char delimiter) {
String[] temp = new String[(string.length() / 2) + 1];
int wordCount = 0;
int i = 0;
int j = string.indexOf(delimiter);
while( j >= 0) {
temp[wordCount++] = string.substring(i, j);
i = j + 1;
@cgbystrom
cgbystrom / netperf_tcp_crr_reports.markdown
Created May 22, 2011 13:41
Reports for netperf's TCP_CRR test

Reports for netperf's TCP_CRR test (i.e TCP accept() performance)

Below is list of results collected with netperf. The interesting value is TCP_CRR, it measures how fast it can TCP connect/request/response/receive. In short, the transaction rate. The test is used to simulate a normal HTTP/1.0 transaction. What's worrying is that this value has very low on Xen virtualized guests. Performance differences between bare metal and virtualization has been as high as 2-3x.

@cgbystrom
cgbystrom / beaconpush-toolbar.js
Created July 12, 2011 15:44
Bookmarklet toolbar for Beaconpush Client
(function (){
/*!
* jQuery JavaScript Library v1.6.2
* http://jquery.com/
*
* Copyright 2011, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Includes Sizzle.js
@cgbystrom
cgbystrom / actstream.py
Created October 12, 2011 21:15
Simple proof-of-concept implementing an activity stream on top of Cassandra
# Naive implementation of an activity stream service using Cassandra.
# Just a proof of concept and not anything that is for production use.
# Probably flawed in many ways like proper key usage, writing and features.
import pycassa
import datetime
import uuid
pool = pycassa.connect('Actstream')
@cgbystrom
cgbystrom / LatencySimulatorHandler.java
Created October 31, 2011 14:50
Netty event latency simulator
import org.jboss.netty.channel.*;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timeout;
import org.jboss.netty.util.Timer;
import org.jboss.netty.util.TimerTask;
import java.util.concurrent.TimeUnit;
/**
* Simulates latency of Netty events
@cgbystrom
cgbystrom / parse_route53_usage.py
Created March 5, 2012 10:53
Prints usage for Amazon Route 53 zones for a given time period
"""
Prints usage for Route 53 for a given time period
(exported from the Amazon Route 53 usage console).
"""
import csv
route53_reader = csv.reader(open('route_53_usage_february_2012.csv', 'rb'), delimiter=',', quotechar='|')
route53_reader.next() # Skip header
zone_lookup = dict('INSERT_ZONE_ID'='mydomain.com')