Skip to content

Instantly share code, notes, and snippets.

View dvarrazzo's full-sized avatar

Daniele Varrazzo dvarrazzo

View GitHub Profile
diff -u --recursive --new-file v1.1.41/linux/kernel/sched.c linux/kernel/sched.c
--- v1.1.41/linux/kernel/sched.c Wed Aug 3 09:32:33 1994
+++ linux/kernel/sched.c Tue Aug 9 09:34:45 1994
@@ -161,7 +161,7 @@
* information in task[0] is never used.
*
* The "confuse_gcc" goto is used only to get better assembly code..
- * Djikstra probably hates me.
+ * Dijkstra probably hates me.
*/
@dvarrazzo
dvarrazzo / exmany.py
Last active February 1, 2017 13:11
Test for a different implementation of psycopg executemany
import os
import time
import psycopg2
from psycopg2 import extensions as ext
def paginate(seq, page_size=100):
page = []
it = iter(seq)
while 1:
@dvarrazzo
dvarrazzo / timeenc.py
Created October 12, 2016 00:42
Benchmark program to measure psycopg decoding speed
"""
Test fetching unicode strings for the database.
"""
from __future__ import print_function
from timeit import Timer
def main():
opt = parse_cmdline()
@dvarrazzo
dvarrazzo / dedup.py
Created March 24, 2016 16:20
A psycopg2 namedtuple cursor de-duplicating repeated fields names
"""
An example of named tuple cursor de-duplicating repeated fields names.
This is **not** a good idea: it makes the program unpredictable. But if you put
the foot and really look for a gun...
See https://github.com/psycopg/psycopg2/issues/418
"""
from itertools import count
from collections import OrderedDict, namedtuple
@dvarrazzo
dvarrazzo / META.yaml
Last active January 13, 2016 11:23
Hypothetical definition of a PGXN package description in YAML
# This file specifies all information for a PGXN distribution. Full spec is at
# http://pgxn.org/spec/ *NOTE* A single distribution can contain multiple
# extensions! See http://pgxn.org/spec/#Terminology.
#
# Keys marked REQUIRED or Optional are what you'd expect. Keys marked Unusual
# are keys you don't normally need to use. The pgxntool Makefile will strip
# out empty keys to produce a working META.json, so it's fine to leave them
# here.
# REQUIRED. Name of distribution.
@dvarrazzo
dvarrazzo / find-rated-pics
Created May 20, 2015 23:12
Find pictures rated one star or more
#!/usr/bin/env python
"""Find pictures rated one star or more and print their file names.
The output can be used e.g. with rsync --files-from
"""
import os
import sys
from glob import glob
from xml.etree import cElementTree as ET
@dvarrazzo
dvarrazzo / gist:b7c8f050bbd39dd2c104
Last active September 27, 2018 14:43
Accessing EscapeIdentifier from Python
From an email about ukulele:
[...], but I have a trick for you. We always refused to
"bless" it into psycopg because it may break in the future (well, it
will only in psycopg3 which is not really on anybody's roadmap, only
on mine if I manage to clone myself at least 4 times). But...
In [5]: class Identifier(str): pass
In [7]: psycopg2.extensions.register_adapter(Identifier, psycopg2.extensions.AsIs)
@dvarrazzo
dvarrazzo / README.md
Last active August 29, 2015 14:06
Test what happens to a libpq connection when we close the file

A test to verify psycopg issue #263. Compile with:

$ gcc -I$(pg_config --includedir) -c testclose.c
$ gcc -o testclose testclose.o -L$(pg_config --libdir) -lpq

The output (with PostgreSQL 9.3.5) suggests PQstatus is not good to detect the closed fd.

$ ./testclose 
PQconsumeInput is fine
@dvarrazzo
dvarrazzo / 0_reuse_code.js
Last active August 29, 2015 14:06
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
@dvarrazzo
dvarrazzo / appind.py
Last active January 7, 2018 00:36
Create an Application Indicator
#!/usr/bin/env python
#
# [SNIPPET_NAME: Create an Application Indicator]
# [SNIPPET_CATEGORIES: Application Indicator]
# [SNIPPET_DESCRIPTION: How to create an application indicator and add items to it]
# [SNIPPET_AUTHOR: Jono Bacon <jono@ubuntu.com>]
# [SNIPPET_DOCS: https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators]
# [SNIPPET_LICENSE: GPL]
import gi