Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3.0
import sys, array, tempfile, heapq
assert array.array('i').itemsize == 4
def intsfromfile(f):
while True:
a = array.array('i')
a.fromstring(f.read(4000))
if not a:
require "rubygems"
require "tokyocabinet"
require "benchmark"
include TokyoCabinet
records = 1000000
hdb = HDB::new # Hash database; acts as a key value store
hdb.open("casket.hdb", HDB::OWRITER | HDB::OCREAT)
import socket
def sockrecv(sock):
d = ''
while not d or d[-1] != '\n':
d += sock.recv(8192)
return d
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
@jakedouglas
jakedouglas / gist:135109
Created June 24, 2009 09:04
Simple UDP Growl packets in Lua
require "luarocks.require"
require "pack"
require "socket"
require "md5"
Growl = {version = 1, registration = 0, notification = 1}
function Growl.new(hostname, appname)
local mysock = assert(socket.udp())
@defunkt
defunkt / resque.py
Created November 3, 2009 19:49
Resque client in Python
from redis import Redis
import simplejson
class Resque(object):
"""Dirt simple Resque client in Python. Can be used to create jobs."""
redis_server = 'localhost:6379'
def __init__(self):
host, port = self.redis_server.split(':')
self.redis = Redis(host=host, port=int(port))
@greut
greut / gevent-wsgi.py
Created November 15, 2009 12:02
using the WSGI server from gevent
#!/usr/bin/env python
def application(environ, start_response):
start_response("200 OK", [("Content-Type", "text/html; charset=utf-8")])
return ["Hello, World!"]
if __name__ == "__main__":
from gevent.wsgi import WSGIServer
address = "localhost", 8080
puts <<ASCII
/´¯/)
,/¯ /
/ /
/´¯/' '/´¯¯`·¸
/'/ / / /¨¯\\
('( ´ ´ ¯~/' ')
\\ ' /
'' \\ _ ·´
\\ (
@tessro
tessro / redis-server
Created December 16, 2009 14:20
A CentOS initscript for Redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
import tweepy
auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
auth.get_xauth_access_token(username, password)
# you can then use this for API access...
api = tweepy.API(auth)
api.update_status("hello")
# to get the access token object for storing...