Skip to content

Instantly share code, notes, and snippets.

View rsms's full-sized avatar

Rasmus rsms

View GitHub Profile
// ==UserScript==
// @name Spotify URL handler
// @namespace http://open.spotify.com/
// @description Takes care of zombie windows left undead from Spotify URL-to-URI actions
// @include http://open.spotify.com/*
// ==/UserScript==
window.close();
@rsms
rsms / gist:58576
Created February 5, 2009 06:38 — forked from khafatech/gist:58553
"Calculates the binary huffman code for the given characters and their frequencies."
from copy import copy
freqs = {'a': 20, 'b': 10, 'c': 12, 'd': 5, 'e': 15, 'z': 65 }
class Node:
def __init__(self, ch='', freq=-1, code=None):
'''Time modulus for use with caching etc.
A time window of size window_size second distributed in chunks of granularity seconds.
'''
import time
def modtime(window_size, granularity, t=None):
'''Time distributions
modtime(60, 5)
12 unique evenly distributed over 60 seconds
* * * * * root ps xU www-data|grep '/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf'|grep -v grep>/dev/null || invoke-rc.d lighttpd restart
ttserver\
-host 127.0.0.1\
-port 41201\
-mhost 127.0.0.1\
-mport 51201 \
-pid /Users/rasmus/src/lightcloud_manager/data/lookup1_A.pid\
-dmn \
-le \
-ulog /Users/rasmus/src/lightcloud_manager/data/logs/1/\
-sid 1\
# String substitution by indexing, avoiding recursive replacement.
#
# Copyright (c) 2009 Rasmus Andersson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#!/usr/bin/env python
# encoding: utf-8
'''A very simple HTTP server using eventlet (which in turn is based on greenlet)
'''
from eventlet import api, httpd, util
util.wrap_socket_with_coroutine_socket()
class Handler(object):
def handle_request(self, req):
# libevent echo server example using buffered events
SOURCES=libevent_echo.c
EXECUTABLE=libevent_echo
CFLAGS=-c -Wall -DDEBUG=1 -I/opt/local/include
LDFLAGS=-L/opt/local/lib -levent
OBJECTS=$(SOURCES:.c=.o)
all: $(SOURCES) $(EXECUTABLE)
% simple TCP secho server in Erlang
-module(tcp_echo_server).
-export([run/1]).
-define(TCPOPTS, [binary, {packet,0}, {active,false}, {reuseaddr,true}]).
% Call tcp_echo_server:run(Port) to start the service.
run(Port) ->
run(Port, {127,0,0,1}).
run(Port, IpAddress) ->
@rsms
rsms / spotlight-ax.m
Created May 10, 2009 16:45 — forked from liesen/gist:109666
A small utility that observes any changes of a search field of a given application
/* Cocoa accessibility framework for intercepting Spotlight user input. */
#import <Cocoa/Cocoa.h>
#import <AppKit/NSAccessibility.h>
static CFStringRef kSpotlightBundleIdentifier = CFSTR("com.apple.spotlight");
static void SpotlightCallback(AXObserverRef observer,
AXUIElementRef element,