Skip to content

Instantly share code, notes, and snippets.

def connect(addr, family=socket.AF_INET, bind=None):
"""Convenience function for opening client sockets.
:param addr: Address of the server to connect to. For TCP sockets,
this is a (host, port) tuple.
:param family: Socket family, optional. See :mod:`socket`
documentation for available families.
:param bind: Local address to bind to, optional.
"""
sock = green_socket.socket(family)
# chunkify_list( list(xrange(1, 11), 2 ) -> ([1,2], [3,4], [5,6], [7,8], [9,10])
def chunkify_list(L, size):
while L:
chunk, L = L[:size], L[size:]
yield chunk
; Copied from http://newos.org/txt/context_switch.txt
BITS 32
global HalSwitchContext
section .text
; void i386_context_switch(void **from_esp, void *esp)
HalSwitchContext:
pusha ; save all 8 general purpose regs on the stack
# Muhs3 in Go.
include $(GOROOT)/src/Make.inc
TARG := muhs3
GOFMT := gofmt -spaces=true -tabindent=false -tabwidth=4
GOFILES := \
main.go \
muh.go \
@temoto
temoto / gist:1330373
Created November 1, 2011 11:46
Python time machine contextmanager for tests
# Except it would not work, because TypeError: can't set attributes of built-in/extension type 'datetime.datetime'
@contextmanager
def time_machine(now=None, utcnow=None, today=None):
if now is None and utcnow is None and today is None:
raise ValueError(u"At least one of `now`, `utcnow` or `today` must be specified.")
real_now = datetime.now()
real_utcnow = datetime.utcnow()
tz_delta = real_now - real_utcnow
#include <pcrecpp.h>
#include <iostream>
int main(int argc, char *argv[]) {
// Don't sync C++ and C I/O
std::ios_base::sync_with_stdio(false);
if (argc < 2) {
std::cerr << "Usage: re_remove REGEX <input" << std::endl;
@temoto
temoto / test_pub_sub_double_bind.py
Created March 20, 2012 12:30
ZeroMQ test PUB-SUB multiple bind to ipc socket
#!/usr/bin/env python
# coding: utf-8
import os
import time
import zmq
name = "main"
#endpoint = "ipc://test-pub-sub-double-bind.ipc"
endpoint = "tcp://127.0.0.1:5004"
@temoto
temoto / zmq-to-file.py
Created March 21, 2012 20:31
ZeroMQ -> file writer with optional forwarder device
ZeroMQ -> file writer
@temoto
temoto / 01.sql
Created April 6, 2012 13:50
plpgsql for loop -> single select?
-- Types: ticket_query, ticket_result
-- Functions: ticket_search_1, ticket_unique_sellers
drop type ticket_query cascade;
create type ticket_query as (
cities_from text[],
cities_to text[],
date_direct date,
date_back_min date,
date_back_max date,
@temoto
temoto / xmonad.hs
Created June 9, 2012 16:04
my xmonad config
$ xmonad --recompile
Error detected while loading xmonad configuration file: /home/temoto/.xmonad/xmonad.hs
xmonad.hs:81:54:
Couldn't match expected type `Data.Monoid.Endo WindowSet'
with actual type `()'
Expected type: X (Data.Monoid.Endo WindowSet)
Actual type: X ()
In the first argument of `liftX', namely
`(withDisplay $ \ d -> io (lowerWindow d w))'