Skip to content

Instantly share code, notes, and snippets.

View dvarrazzo's full-sized avatar

Daniele Varrazzo dvarrazzo

View GitHub Profile
@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 <[email protected]>]
# [SNIPPET_DOCS: https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators]
# [SNIPPET_LICENSE: GPL]
import gi
@dvarrazzo
dvarrazzo / pypi_docs_upload.py
Created September 1, 2014 15:19
Script script to upload a project docs on PyPI
# -*- coding: utf-8 -*-
"""
Standalone script to upload a project docs on PyPI
Hacked together from the following distutils extension, avaliable from
https://bitbucket.org/jezdez/sphinx-pypi-upload/overview (ver. 0.2.1)
sphinx_pypi_upload
~~~~~~~~~~~~~~~~~~
@dvarrazzo
dvarrazzo / include_defaults.py
Last active November 2, 2015 16:36
Ansible Plugin implementing the include_defaults action.
"""
Ansible Plugin implementing the include_defaults action.
Like include_vars, but the included defaults can be overridden by the
inventory or by group vars. Can be used to read the defaults from another role.
Usage: drop it into a directory called ``action_plugins`` in your playbook
directory. Then you can use it with::
- name: get the defaults from the web server role
@dvarrazzo
dvarrazzo / codice_catastale.sql
Last active August 29, 2015 14:05
Script di importazione codici catastali, vedi italian_codes #1
-- Crea una tabella di importazione dati
create table codice_catastale_import (
codice text not null,
codice_belfiore text,
provincia text,
comune text not null,
annotazione text,
codice_var text,
codice_belfiore_var text,
provincia_var text,
@dvarrazzo
dvarrazzo / pypi_docs_upload.py
Created January 7, 2014 13:03
Standalone script to upload a project docs on PyPI
# -*- coding: utf-8 -*-
"""
Standalone script to upload a project docs on PyPI
Hacked together from the following distutils extension, avaliable from
https://bitbucket.org/jezdez/sphinx-pypi-upload/overview (ver. 0.2.1)
sphinx_pypi_upload
~~~~~~~~~~~~~~~~~~
@dvarrazzo
dvarrazzo / values.py
Created October 3, 2013 12:57
An adapter for psycopg2 to pass a sequence of objects to a VALUES list.
import psycopg2.extensions as ext
class Values(object):
"""Wrapper to pass a sequence of objects as VALUES argument"""
def __init__(self, seq):
self.seq = map(ext.adapt, seq)
def __conform__(self, proto):
if proto is ext.ISQLQuote:
return self
@dvarrazzo
dvarrazzo / reren
Last active December 21, 2015 07:19
A script for smart file rename. Written several years ago, not necessarily the best tool for the job.
#!/usr/bin/python
'''reren -- rinomina usando espressioni regolari.
Utilizzo:
reren "from" "to" [dir] [-y] [-s] [-f]
from: Pattern a cui devono corrispondere i file. I file vengono letti
in ordine alfabetico.
to: Stringa in cui vanno trasformati i file;
se viene specificata l'opzione -f, deve essere una funzione
@dvarrazzo
dvarrazzo / patch_db.py
Created November 28, 2012 12:58
A simple script to record the schema patches applied to a database
#/usr/bin/env python -u
"""
Apply database patches.
Database patches are found in the 'db' directory relative to this script. They
are recorded in the schema_patch table of the database.
The dsn to connect to defaults to a local one (empty connection string). It
can be chosen using the command line or an environment variable (so that the
Makefile doesn't need to be tweaked per developer). Patches application is