Skip to content

Instantly share code, notes, and snippets.

View gawen's full-sized avatar

Gawen Arab gawen

View GitHub Profile
@gawen
gawen / gist:2028453
Created March 13, 2012 12:20
Network co-routines with gevent
#### GEVENT
import gevent
import gevent.monkey
import gevent.pool
def map_gevent(func, it, pool_size = None):
pool_size = pool_size if pool_size is not None else 10
pool = gevent.pool.Pool(pool_size)
result = []
@gawen
gawen / gevent_watchdog.py
Created April 11, 2012 12:58
Python Watchdog with gevent
""" Use watchdogs to make your code safer. (http://en.wikipedia.org/wiki/Watchdog_timer)
Usage:
with watchdog.Watchdog(duration = 1.0):
# Some code which takes less than 1s
# If it takes more, the exception Watchdog.Reset will be raised
# To notify the watchdog the section is still alive, call the method
# 'tick' to reset its internal timer.
@gawen
gawen / sparse.md
Created November 15, 2013 18:30
<3 sparse file

Get the smaller USB drive you have. Format it in ext4 or smater.

Mount it on /mnt/usb.

Then

$ cd /mnt/usb
$ dd if=/dev/urandom of=sparse-file bs=1k seek=10737418240 count=1
$ ls -lha sparse-file

-rw-rw-r-- 1 gawen gawen 11T Nov 15 19:25 sparse-file

@gawen
gawen / stdlol.h
Created February 2, 2014 17:26
Happy debugging!
#ifndef PWND_H
#define PWND_H
#ifdef NULL
#undef NULL
#endif
#define NULL ((void*)(rand() % 10 ? 0 : 0xDEADBEAF))
#endif // PWND_H
@gawen
gawen / gist:8828446
Created February 5, 2014 17:07
Go sleep Linux, you're drunk
root@OpenWrt:~# time dd if=/dev/urandom of=a ...
...
real 74h 20m 40s
user 0m 0.36s
sys 1m 33.78s
@gawen
gawen / 0_reuse_code.js
Created August 20, 2014 09:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@gawen
gawen / something_about_us.c
Created September 2, 2014 07:50
Daft Punk - Something About Us
#include <stdio.h>
#include <stdlib.h>
const char* a[2] = {"time", "one"};
const char* b = "I%c might not be the right %s\n";
const char* c[2] = {" want", "'ve got"};
const char* c_[2] = {"say", "do"};
const char* d = "But there's something about us I%s to %s\n%s\n\n";
const char* e[2] = {"Cause there's something between us anyway", "Some kind of secret I will share with you"};
const unsigned int f[4] = {0x6465656E, 0x746E6177, 0x7373696D, 0x65766F6C};
@gawen
gawen / .vimrc
Last active August 29, 2015 14:07
This VIM macro saves my life
" Put your text cursor on an expression you want to search in your project
" and type :Gr
" It will open a buffer on the left with every references of this expression
" in your current folder (recursively).
python << EOF
import vim
def set_register(reg, value):
@gawen
gawen / version_cmp.py
Last active June 17, 2022 23:10
Compare versions in Python
def cmp_version(va, vb):
# Split over '.' and convert members into int
va = map(int, va.split("."))
vb = map(int, vb.split("."))
# Get max length of versions
l = max(len(va), len(vb))
# Make the version the same length by appending 0
va = va + [0] * (l - len(va))
@gawen
gawen / singleton.py
Created December 29, 2014 15:08
Singleton in Python
class SingletonClass(object):
def __new__(cls):
if not cls._singleton:
self = super(SingletonClass, cls).__new__(cls)
# Real constructor
self._init()
cls._singleton = self