Skip to content

Instantly share code, notes, and snippets.

View romuald's full-sized avatar
🍣

Romuald Brunet romuald

🍣
View GitHub Profile
function RenderRST()
write
let tmpfile = tempname()
silent execute "!rst2html \"%\" > " . tmpfile . " && x-www-browser " . tmpfile . " >/dev/null &"
redraw!
endfunction
@romuald
romuald / property.py
Created July 25, 2011 14:22
Python 2.5 compatibility hack for property.setter, property.deleter
# Python 2.5 compatibility hack for property.setter, property.deleter
import __builtin__
if not hasattr(__builtin__.property, "setter"):
class property(__builtin__.property):
__metaclass__ = type
def setter(self, method):
return property(self.fget, method, self.fdel)
def deleter(self, method):
@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 / 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 / gist:6717687
Created September 26, 2013 17:35
Try to gracefully handle a missing module, but raise if that module itself tries to import something that isn't available
try:
module = __import__(name, **specs)
except ImportError:
# If tracback "length" is greater than 1, there is most
# probably a deeper ImportError that we don't want to
# mask (example: missing library used by the base import)
_, _, tb = sys.exc_info()
if len(traceback.extract_tb(tb)) > 1:
raise
# else, handle the error graciously
@romuald
romuald / gettime.c
Last active February 24, 2017 13:44
Doing some benchmarks on a lib, found out that gettimeofday is way faster on MacOS (10.6) than Linux (3.8.0)(50ms vs 600+ms on the same machine, 64bit in both cases)
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#define COUNT 800000
int main() {
long i = 0;
long start, end;
struct timeval tstart, tend, tt;
@romuald
romuald / fix-awesome.diff
Created January 2, 2014 15:34
Fix Awesome / GTK3 focus bug … but probably breaks badly when no window manager is running
diff --git a/gdk/x11/gdkeventsource.c b/gdk/x11/gdkeventsource.c
index 7fff28f..a687963 100644
--- a/gdk/x11/gdkeventsource.c
+++ b/gdk/x11/gdkeventsource.c
@@ -249,7 +249,7 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
event->crossing.window != NULL)
{
/* Handle focusing (in the case where no window manager is running */
- handle_focus_change (&event->crossing);
+ // handle_focus_change (&event->crossing);
@romuald
romuald / signaltest.py
Created January 7, 2014 10:53
Did I just find a bug in python locks? Or do I simply don't understands them? Signals does not wake up main thread if waiting with an indefinite time
"""
When `wait` is None, program does not receive signal (and cannot be stopped)
When anything else, signals wakes up main thread and stop as intended
"""
import os
import signal
from threading import Event