Skip to content

Instantly share code, notes, and snippets.

View mapio's full-sized avatar
🎯
Focusing

Massimo Santini mapio

🎯
Focusing
View GitHub Profile
@mapio
mapio / gist:1050635
Created June 28, 2011 06:53
A test comparing defaultdict and groupby for grouping
from timeit import Timer
from operator import attrgetter
from random import randint
def timeit( stmt, setup ):
t = Timer(stmt=stmt, setup=setup)
print "%.2f usec/pass" % (100000 * t.timeit(number=10000)/10000)
class Person(object):
def __init__(self, age):
@mapio
mapio / gist:1082301
Created July 14, 2011 11:36
Trasposizione tabella LaTeX
# -*- coding: utf-8 -*-
# salva questo in un file "pippo.py" ed eseguilo da riga di comando con "python pippo.py"
# metti la tua tabella tra le triple virgolette
table = r"""
a & b & c & d \\
e & f & g & h \\
i & j & k & l
@mapio
mapio / rhc-chk output
Created November 18, 2011 12:30
Issues with my openshift account
$ rhc-chk -l massimo.santini@gmail.com
Password:
Ruby Version: 1.8.7
host_alias:
Proxy being used: none
TEST1: Confirming connection to OpenShift
Code: 200
Message: OK
{"debug":"","data":"{\"carts\":[\"raw-0.1\",\"jenkins-1.4\",\"jbossas-7.0\",\"perl-5.10\",\"rack-1.1\",\"wsgi-3.2\",\"php-5.3\"]}","api_c":["placeholder"],"result":null,"messages":"","broker":"1.1.1","broker_c":["namespace","rhlogin","ssh","app_uuid","debug","alter","cartridge","cart_type","action","app_name","api"],"exit_code":0,"api":"1.1.1"}
@mapio
mapio / gist:1474444
Created December 13, 2011 23:24
Rebase for Formatting
from datetime import datetime
from pytz import utc, timezone
# My local time in Italy is now midnight
local_time = datetime.now()
print local_time.strftime( '%H' ), local_time.hour # outputs "00 0"
# Following http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/
# take that UTC datetime object
@mapio
mapio / gist:2263346
Created March 31, 2012 12:24
Curlish error
$ curlish -i https://graph.facebook.com/me
Traceback (most recent call last):
File "/Users/santini/.virtualenvs/948ddccbe548751e/bin/curlish", line 9, in <module>
load_entry_point('curlish==1.2', 'console_scripts', 'curlish')()
File "/Users/santini/.virtualenvs/948ddccbe548751e/lib/python2.7/site-packages/curlish.py", line 648, in main
site = get_site(args.site, extra_args[url_arg])
File "/Users/santini/.virtualenvs/948ddccbe548751e/lib/python2.7/site-packages/curlish.py", line 363, in get_site
base_url = site.get('base_url')
AttributeError: 'str' object has no attribute 'get'
@mapio
mapio / set_path.sh
Created October 21, 2012 23:30
Setup the DI LabProg path
if [ -z $BASH ]; then exit; fi;
if ! grep -q 'export PATH=/users/ms000123/dbin:' 2>/dev/null ~/.bash_profile; then
( echo;
echo '# Definizione del PATH per il laboratorio di programmazione...';
echo 'export PATH=/users/ms000123/dbin:$PATH';
echo '# non rimuovere questa e le due righe precedenti!';
echo ) >> ~/.bash_profile;
export PATH=/users/ms000123/dbin:$PATH;
fi
@mapio
mapio / codici.txt
Created November 8, 2012 15:06
Mail merge in Python per mandare username e password
PASSWORD user@foo.bar
@mapio
mapio / stupidario.md
Last active October 12, 2015 22:58
La stupidità degli studenti…

Come si fa a stampare il p-esimo valore di un vettore v (diciamo di N interi)?

for ( i = 0; i < N; i++ ) 
    if ( i == p ) printf( "%d", v[ i ] );
    else printf( "non trovato" );

E si stupiva pure che stampasse N-1 volte "non trovato"!

La giustificazione: "credevo che l'unico modo per accedere ai valori del vettore fosse usare l'espressione v[ i ]"… detto altrimenti: pensava che tra le quadre ci si potesse mettere solo i!

@mapio
mapio / errata.c
Created January 31, 2013 14:19
Non si può insegnare C al primo anno!
#include <stdio.h>
int main( int argc, char *argv[] )
{
printf( "Salve, %s!\n" );
return 0;
}
@mapio
mapio / Vagrantfile
Last active December 17, 2015 14:39
A simple script to update/install the SDT vagrant box (for more details see https://github.com/mapio/sdt/).
$functions = <<FUNCTIONS
function _fixperms {
echo "*** Fixing /home/vagrant permissions and ownership" 1>&2
chown -R vagrant:vagrant /home/vagrant
chmod -R go= /home/vagrant
}
function _github {
if ! [ -d /home/vagrant/sdt ]; then
echo "*** Cloning 'sdt' from GitHub" 1>&2
su - vagrant -c 'hg clone git://github.com/mapio/sdt.git'