Skip to content

Instantly share code, notes, and snippets.

@snaury
snaury / CrashSignal.java
Created December 15, 2012 16:43
Crash java using sun.misc.SignalHandler.
import sun.misc.*;
public class CrashSignal {
public static void main(String[] args) {
Signal signal = new Signal("INT");
SignalHandler signalHandler = SignalHandler.SIG_IGN;
signalHandler.handle(signal);
}
@snaury
snaury / dnstest.erl
Created October 31, 2012 06:36
Work in progress
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable
-module(dnstest).
-mode(compile).
-record(dnsmsg, {id, qr, opcode, aa, tc, rd, ra, z, rcode,
questions, answers, authorities, extras, packet}).
-record(dnsquestion, {name, type, class}).
@snaury
snaury / README
Created October 27, 2012 20:36
Tests MongoDB/PostgreSQL performance under different concurrency settings
For PostgreSQL you'd need to increase your kernel shared memory quotas. For Mac OS X to set it to 40MBs do:
sudo sysctl -w kern.sysv.shmmax=41943040
sudo sysctl -w kern.sysv.shmall=10240
Then in mydb/postgresql.conf change:
max_connections = 128
More info here:
@snaury
snaury / elastic.go
Created May 17, 2012 22:08
Channel with an unrestricted buffer in the middle
type Message struct {
Value string
}
func MakeElastic() (<-chan Message, chan<- Message) {
input := make(chan Message, 64)
output := make(chan Message, 64)
middle := make(chan []Message, 1)
go func(middle chan []Message, input <-chan Message) {
defer close(middle)
@snaury
snaury / broker.go
Created May 16, 2012 21:28
Non-blocking fan-out broker in go
package main
import (
"fmt"
"time"
)
type Message struct {
Timestamp time.Time
Client *Client
@snaury
snaury / gevent + greenlet + gc
Created March 27, 2011 00:05
How to take advantage of greenlet gc support in gevent
#!/Users/dragonfox/vpython/bin/python
import gc
import sys
from greenlet import getcurrent, GreenletExit
from gevent import spawn, spawn_later
from gevent.hub import get_hub
from gevent.greenlet import Greenlet
def run():
self = getcurrent()