Skip to content

Instantly share code, notes, and snippets.

@asim
asim / keystore.lua
Created December 5, 2010 21:52
key value store, the humble beginnings
local config = { host="localhost", port=6379 }
local socket = require("socket")
local server = assert(socket.bind(config.host, config.port))
local ip, port = server:getsockname()
print(string.format("listening on %s:%s", ip, port))
local store = {}
local function add(key, value)
store[key] = value
@asim
asim / maillog.rb
Created December 9, 2010 17:16
ugly code
#!/usr/local/ruby/bin/ruby
require "rubygems"
require "redis"
require "eventmachine"
require "eventmachine-tail"
LOG = "/tmp/foo"
R = Redis.new(:host => "10.1.10.2")
class Reader < EventMachine::FileTail
@asim
asim / stats.rb
Created December 15, 2010 15:51
stats class
class Stats
QUEUES = ["bounced", "connect", "conversations", "deferred", "host", "lost", "sent"]
def self.lookup(pattern)
h = {}
REDIS.keys(pattern).map { |k,v| h[k] = REDIS[k] }
h
end
def self.day_for(ip)
# method should return a hash of count queues for 24 hours
h = {}
Stats::QUEUES.size.times do |i|
a[i] = Thread.new {
queue = Stats::QUEUES[i-1]
h["#{queue}:#{ip}:24"] = return_day_for(ip,queue)
}
end
@asim
asim / foo.sh
Created January 17, 2011 15:29
save
# LOL!!1
alias wtf='dmesg'
alias onoz='cat /var/log/errors.log'
alias rtfm='man'
alias visible='echo'
alias invisible='cat'
alias moar='more'
@asim
asim / ev.c
Created March 30, 2011 11:49
ignore this
#include <stdio.h>
#include <event.h>
#include <evhttp.h>
#include <stdlib.h>
struct server {
struct event_base *base;
struct evhttp *http;
};
@asim
asim / foo.c
Created April 17, 2011 19:30
nothing special
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct array {
int pos;
char *pointers[1024];
};
static struct array arr;
@asim
asim / pseudocode.c
Created April 20, 2011 07:44
written by the boss
typedef struct {
int pos;
int size;
char *data;
} stack;
#define INITIAL_SIZE 1024
stack *init_stack() {
pos = 0;
@asim
asim / tcp_connections.pl
Created April 28, 2011 12:30
tcp conns
#!/usr/bin/perl
my @statuses = ("ESTABLISHED","SYN_SENT","SYN_RECV","FIN_WAIT1","FIN_WAIT2","TIME_WAIT","CLOSED","CLOSE_WAIT","LAST_ACK","CLOSING","UNKNOWN");
my @ports = ( "80", "443" );
my %data = ();
my $netstat = 'netstat -ant | awk \'$4 ~ /:(80|443)$/ && $6 != "LISTEN" { split($4,a,":"); print a[2],$6;}\' | sort | uniq -c';
# initialize to 0
foreach $status (@statuses) {
@asim
asim / about.md
Created August 9, 2011 14:17 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer