Skip to content

Instantly share code, notes, and snippets.

View romuald's full-sized avatar
🍣

Romuald Brunet romuald

🍣
View GitHub Profile
@romuald
romuald / with.py
Created November 20, 2014 10:15
python context manager behavior changing over python versions
import sys
class Bar(object):
def __enter__(self):
pass
def __exit__(self, exc, exc_type, tb):
return True
# pong.py
import sys
from time import time, sleep
while True:
print time()
sys.stdout.flush()
sleep(1)
@romuald
romuald / deezequalizer.js
Last active September 1, 2015 08:11
Stop Deezer player equalizer animation
// ==UserScript==
// @name Deezer equalizer stop
// @description Stop Deezer player equalizer from animating, saving CPU time in the process. Very useful to save battery
// @namespace http://chivil.com/
// @grant none
// @match https://*.deezer.com/
// @match http://*.deezer.com/
// @include http://*.deezer.com/
// @include https://*.deezer.com/
// @version 1
function RenderRST()
write
let tmpfile = tempname()
silent execute "!rst2html \"%\" > " . tmpfile . " && x-www-browser " . tmpfile . " >/dev/null &"
redraw!
endfunction
@romuald
romuald / gist:1168049
Created August 24, 2011 13:26
syslog handler fix for python
from logging.handlers import SysLogHandler as Base
class SysLogHandler(Base):
def emit(self, record):
if type(record.msg) is unicode:
# RFC says we should prefix with BOM, but rsyslog will log the BOM
record.msg = record.msg.encode('utf-8')
return Base.emit(self, record)
@romuald
romuald / gist:3713731
Created September 13, 2012 11:35
PyCountry memory patch
diff --git a/src/pycountry/db.py b/src/pycountry/db.py
index 38689ed..aeb8640 100644
--- a/src/pycountry/db.py
+++ b/src/pycountry/db.py
@@ -45,6 +45,7 @@ class Database(object):
entry.attributes.get(key).value)
entry_obj = self.data_class(entry, **mapped_data)
self.objects.append(entry_obj)
+ tree.unlink()
@romuald
romuald / gist:3898140
Created October 16, 2012 08:54
Perl timing method
=head2 timeit
Measure a block's execution time.
Example usage:
sub do_stuff() {
timeit {
some_method();
# and other stuff probably
@romuald
romuald / readable-docker-docs.js
Created November 12, 2015 10:31
Readable Docker docs
// ==UserScript==
// @name Readable Docker docs
// @namespace http://your.homepage/
// @version 0.1
// @description Readable docs, use more than 50% screen size
// @author You
// @match http://docs.docker.com/*
// @grant none
// ==/UserScript==
@romuald
romuald / gist:4702494
Last active December 12, 2015 02:58
older perl bug with sub + open pipe ?
#!/usr/bin/env perl
use strict; use warnings;
use Data::Dumper;
my $less ;
my $pid;
my $abc = sub {
$pid = open($less, "| less");
select $less;
@romuald
romuald / bitmap-cache.c
Created December 21, 2015 13:56
Pebble bitmap cache
static BitmapLayer *s_graph_layer;
static GBitmap *s_cache_bitmap;
static void init_bitmap(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer);
s_graph_layer = bitmap_layer_create(bounds);
s_cache_bitmap = gbitmap_create_blank(bounds.size, GBitmapFormat8Bit);
}