Skip to content

Instantly share code, notes, and snippets.

View sentenza's full-sized avatar

Alfredo Torre sentenza

View GitHub Profile
@sentenza
sentenza / say.sh
Created February 25, 2013 11:25
This script use google translate to speak in italian via mplayer. Example $ ./say.sh Ciao Mondo
#!/bin/bash
say()
{
mplayer -really-quiet -ao alsa "http://translate.google.com/translate_tts?tl=it&q=$*"
}
say $*
@sentenza
sentenza / simpleRest.py
Last active December 18, 2015 03:39
Simple Python REST client See also https://github.com/scastillo/siesta
import httplib2 as http
import json
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
headers = {
'Accept': 'application/json',
@sentenza
sentenza / TileLayer.Common.js
Created August 24, 2013 09:50 — forked from mourner/TileLayer.Common.js
A useful snippet for selecting the right tile layer on a leaflet map
// Lefalet shortcuts for common tile providers - is it worth adding such 1.5kb to Leaflet core?
L.TileLayer.Common = L.TileLayer.extend({
initialize: function (options) {
L.TileLayer.prototype.initialize.call(this, this.url, options);
}
});
(function () {
@sentenza
sentenza / scriptTemplate.py
Created January 31, 2014 22:58
Combining Bash and Python. Shell script template.
#!/usr/bin/env python
import subprocess
import optparse
import re
#Create variables out of shell commands
#Note triple quotes can embed Bash
#You could add another bash command here
#HOLDING_SPOT="""fake_command"""
sudo apt-get install python2.7
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 20
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10
sudo update-alternatives --set python /usr/bin/python2.6
@sentenza
sentenza / list_func.py
Created February 2, 2014 20:47
Managing lists as function parameters
def funct(list1, list2):
assert isinstance(list1, list) and isinstance(list2, list)
@sentenza
sentenza / verbose_print.py
Created February 3, 2014 15:58
Implementing verbose print in a Python script -- http://stackoverflow.com/a/5980173/1977778
if verbose:
def verboseprint(*args):
# Print each argument separately so caller doesn't need to
# stuff everything to be printed into a single string
for arg in args:
print arg,
print
else:
verboseprint = lambda *a: None # do-nothing function
if sys.version_info < (2, 6):
print('ERROR: %s' % sys.exc_info()[1])
print('ERROR: this script requires Python 2.6 or greater.')
sys.exit(101)
@sentenza
sentenza / __init__.py
Created February 5, 2014 19:41
Every Python logger is a child of parent's module logger. It is possible to configure the logger via the init module and it is the easiest way to do so.
import logging.config
logging.config.fileConfig('logging.conf')
log = logging.getLogger(__name__)
######################################################################
# CURRENT AWARE LOCAL DATETIME
######################################################################
from datetime import datetime
from tzlocal import get_localzone
local_tz = get_localzone()
local_dt = datetime.now(local_tz)