Skip to content

Instantly share code, notes, and snippets.

@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()
@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 / 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 / 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 / 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 / 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);
}
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from __future__ import print_function
import time
import threading
import multiprocessing
from Queue import Queue
from multiprocessing import Queue as MPQueue
messages = (
@snaury
snaury / configure-intel-rapid-start.conf
Created April 11, 2014 21:04
Upstart job for configuring Intel Rapid Start to save memory to disk only when battery is critically low
description "Configure Intel Rapid Start"
start on acpi-device-added DEVPATH=*/INT3392:00
task
script
test -f "/sys$DEVPATH/wakeup_events" || { stop; exit 0; }
echo -n 2 >"/sys$DEVPATH/wakeup_events"
end script
import os
import shutil
from bsddb.db import *
DB_HOME = 'data'
DB_FILENAME = 'queue.db'
if os.path.isdir(DB_HOME):
shutil.rmtree(DB_HOME)
os.makedirs(DB_HOME)
@snaury
snaury / cpuinfo.txt
Created October 5, 2015 22:27
Scaleway linux
$ cat /proc/cpuinfo
Processor : Marvell PJ4Bv7 Processor rev 2 (v7l)
processor : 0
BogoMIPS : 1332.01
processor : 1
BogoMIPS : 1332.01
processor : 2
BogoMIPS : 1332.01