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 / Setup an USB raw device
Created January 17, 2014 09:31
To boot Virtualbox from a USB pendrive you must first create a virtual disk to access to it and then add it as storage.
#!/bin/bash
if [ -r USB.vmdk ]; then
VBoxManage storageattach "BootFromUSB" --storagectl "SATA" --port 0 --device 0 --medium none
VBoxManage closemedium disk USB.vmdk --delete
fi
sudo chown $USER /dev/disk1*
VBoxManage internalcommands createrawvmdk -filename USB.vmdk -rawdisk /dev/disk1 -partitions 1,2
@mapio
mapio / Vagrantfile
Last active August 29, 2015 14:07
La configurazione di Vagrant per la macchina virtuale codebox4im
Vagrant.configure("2") do |config|
if ARGV[0] == 'up' || ARGV[0] == 'provision' || ARGV[0] == 'reload'
if File.exists?( 'provision.sh' )
$provisioning_script = File.open( 'provision.sh' ).read
$stderr.puts( "Using 'provision.sh' for provisioning...\n" )
else
require 'net/http'
$provisioning_script = Net::HTTP.get(URI('https://gist.githubusercontent.com/mapio/ef23edceb8a5709b87d0/raw/provision.sh'))
$stderr.puts( "Downloaded gist #ef23edceb8a5709b87d0 for provisioning...\n" )
@mapio
mapio / HOWTO-GUNICORN-GEVENT-OSX-YOSEMITE.md
Last active August 29, 2015 14:09
How to install gunicorn + gevent on OS X 10.10 Yosemite

Given that I've spent a few hours to get it right, here is how I did it.

First install the required dependencies using Homebrew, by this I mean at least

brew install python libevent

Then upgrade setuptools with

curl https://bootstrap.pypa.io/ez_setup.py -o - | python
@mapio
mapio / opearazioni.py
Last active August 29, 2015 14:12
Come tenere occupato un nano saccente…
# -*- coding: utf-8 -*-
import subprocess
from random import randint, choice
VOCI = "Alice", "Federica", "Luca", "Paola"
COMPIMENTI = "geniaccio", "sei un figo", "super", "che gallo"
OFFESE = "coglionazzo", "minchione", "cacchio dici"
OP = ( lambda a, b: a + b, "più"), ( lambda a, b: a - b, "meno" )
@mapio
mapio / collapse
Created January 15, 2015 00:33
A trick to collapse Mercurial revisions in steps
#!/bin/bash
dbg() {
echo WORK
hg -R work log --template '{node|short} {desc}\n'
echo PUBLIC
hg -R public log --template '{node|short} {desc}\n'
echo CLEAN
hg -R clean log --template '{node|short} {desc}\n'
}
@mapio
mapio / hg_archive.sh
Last active August 29, 2015 14:13
How to "archive" an initial segment of a Mercurial repository history.
# let's assume that we have an "original" repo and that we want to
# create a new "archvied" repo with a first release corresponding to what
# happened in the original repo in revisions O:ARCHIVE, plus all the
# releases (ARCHIVE+1):tip in the original repo.
# first remove the cruft from the previous run
rm -rf original archived
# now create the "original" repository that will contain a
@mapio
mapio / digitalocean.txt
Created January 18, 2015 00:50
Linode vs. Digitalocean
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: digitalocean: GNU/Linux
OS: GNU/Linux -- 3.8.0-38-generic -- #56~precise1-Ubuntu SMP Thu Mar 13 16:22:48 UTC 2014
Machine: x86_64 (x86_64)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: QEMU Virtual CPU version 1.0 (4800.0 bogomips)
x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
19:06:58 up 4 days, 15:52, 1 user, load average: 0.62, 0.58, 0.31; runlevel 2
@mapio
mapio / AnHttpServer.java
Last active May 11, 2016 21:46
Putting together ElementalHttpServer and LifecycleWebServer
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@mapio
mapio / IGDesktopOSXClient.md
Last active August 29, 2015 14:14
How to install a kind of desktop client for Instagram on OSX

You just need two steps:

Invoking `instagram' from the shell will then do the trick.

@mapio
mapio / ArgMax.java
Created February 23, 2015 23:32
An implementation of an argmax collector using the Java 8 stream APIs
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collector;
class ArgMaxCollector<T> {
private T max = null;
private ArrayList<T> argMax = new ArrayList<T>();