Skip to content

Instantly share code, notes, and snippets.

View dvarrazzo's full-sized avatar

Daniele Varrazzo dvarrazzo

View GitHub Profile
@dvarrazzo
dvarrazzo / hwclient.py
Created March 31, 2012 20:48
zmq eventlet tests
import sys
import zmq
try:
n = int(sys.argv[1])
except:
n = 10
ctx = zmq.Context()
@dvarrazzo
dvarrazzo / rtdealer.py
Created April 2, 2012 20:12
syncing over tcp appears working
#!/usr/bin/env python
"""
This script should be a test in synchronizing zmq sockets.
Synchronization fails even if the threads prepare the subscriber before
signaling they are ready.
"""
import sys
import random
@dvarrazzo
dvarrazzo / prepare.py
Created September 28, 2012 01:19
An example of psycopg2 cursor supporting prepared statements
#!/usr/bin/env python
"""An example of cursor dealing with prepared statements.
A cursor can be used as a regular one, but has also a prepare() statement. If
prepare() is called, execute() and executemany() can be used without query: in
this case the parameters are passed to the prepared statement. The functions
also execute the prepared statement if the query is the same prepared before.
Prepared statements aren't automatically deallocated when the cursor is
deleted, but are when the cursor is closed. For long-running sessions creating
@dvarrazzo
dvarrazzo / ditaa_rst.py
Last active June 8, 2022 04:05
ditaa ascii art diagrams in reStructuredText
#!/usr/bin/env python
"""Custom reST_ directive for ditaa_ integration.
.. _reST: http://docutils.sourceforge.net/rst.html
.. _ditaa: http://ditaa.sourceforge.net/
"""
import os
import tempfile
from zlib import adler32
@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
@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 / 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 / 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 / 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 / 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