Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Massimo Santini mapio

🎯
Focusing
Block or report user

Report or block mapio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mapio
mapio / gist:1050635
Created Jun 28, 2011
A test comparing defaultdict and groupby for grouping
View gist:1050635
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 Jul 14, 2011
Trasposizione tabella LaTeX
View gist:1082301
# -*- 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 Nov 18, 2011
Issues with my openshift account
View rhc-chk output
$ 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 Dec 13, 2011
Rebase for Formatting
View gist:1474444
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
View gist:2263346
$ 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 Oct 21, 2012
Setup the DI LabProg path
View set_path.sh
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 Nov 8, 2012
Mail merge in Python per mandare username e password
View codici.txt
PASSWORD user@foo.bar
@mapio
mapio / stupidario.md
Last active Oct 12, 2015
La stupidità degli studenti…
View stupidario.md

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 Jan 31, 2013
Non si può insegnare C al primo anno!
View errata.c
#include <stdio.h>
int main( int argc, char *argv[] )
{
printf( "Salve, %s!\n" );
return 0;
}
@mapio
mapio / Vagrantfile
Last active Dec 17, 2015
A simple script to update/install the SDT vagrant box (for more details see https://github.com/mapio/sdt/).
View Vagrantfile
$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'
You can’t perform that action at this time.