Skip to content

Instantly share code, notes, and snippets.

View naufraghi's full-sized avatar

Matteo Bertini naufraghi

View GitHub Profile
@naufraghi
naufraghi / retry.py
Created June 12, 2014 12:41
Generic Python retry decorator
def retry(func, exception=Exception, num=3, wait=0.5):
"""
Example usage:
f = retry(open, IOError, num=3, wait=0.5)(file_path, 'w')
"""
def _retry(*args, **kwargs):
c = num
while True:
c = c-1
try:
@naufraghi
naufraghi / backup-google-authenticator.py
Last active July 10, 2020 20:11
Script to backup Google Authenticator secrets as QR-codes
#!/usr/bin/env python3
# Copyright 2014 Matteo Bertini [email protected]
# Released as Public Domain
#
# Latest version:
# wget http://slug.it/backup-google-authenticator.py
#
# Requirements
# ============
#
<!DOCTYPE html>
<html>
<head>
<title>Scola la pasta</title>
<style type='text/css'>
@import url(http://fonts.googleapis.com/css?family=Krona+One);
h1 {
font-family: 'Krona One', sans-serif;
font-size: 8em;
font-size: 8vm;
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# http://www.bradshawenterprises.com/blog/2008/5-ways-to-make-using-bash-more-productive/
# erase old dups and skip commands starting with spaces
export HISTCONTROL="ignorespace:ignoredups"
@naufraghi
naufraghi / .vimrc
Created October 9, 2013 14:48
naufraghi: move easily in tags tag->first, tselect->list, tjump->list-if-more-than-one
" naufraghi: move easily in tags
" tag->first, tselect->list, tjump->list-if-more-than-one
map <silent><C-Right> :exec("tjump ".expand("<cword>"))<CR>
map <silent><C-Left> :pop<CR>
# This is the "normal" way
class C(object):
def __init__(self):
self._x = None
@property
def x(self):
return self._x
@x.setter # will copy C.x and add the setter
def x(self, value):
self._x = value
@naufraghi
naufraghi / MyImageView.java
Created December 15, 2012 15:38
Move and zoom image with Gestures in and android View
package com.develer.circularsliderule;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
@naufraghi
naufraghi / find_implementing_classes.py
Created August 12, 2011 15:33
Given a method return all the classes the method is implemented in
def find_implementing_classes(method):
"""
Given a method return all the classes the method is implemented in.
a.aaa() -> A.aaa
a.bbb() -> A.bbb
b.aaa() -> A.aaa
b.bbb() -> B.bbb
A.aaa == B.aaa -> True
A.bbb == B.bbb -> False
find_implementing_classes(b.aaa) -> [<class '__main__.A'>]
@naufraghi
naufraghi / git-svn-utils.sh
Created August 12, 2011 09:20
git svn outgoing | rebase-all | dcommit
git-svn-outgoing() {
need_stash=$(git st --por | cut -c 1-2 | grep M | cat)
if [ "$need_stash" ]; then
git stash > /dev/null
fi
git svn dcommit -n | grep diff-tree | while read line; do git show $(echo $line | cut -d' ' -f 3); done
if [ "$need_stash" ]; then
git stash pop > /dev/null
fi
}
@naufraghi
naufraghi / ignore2recall.py
Created May 15, 2011 15:55
Convert .hgignore files to a local recoll skipped[Names|Paths] lines
import os
import sys
from collections import defaultdict
def hgignore2skipped(filename):
localdir = os.path.dirname(os.path.abspath(os.path.expanduser(filename)))
def _iter_skipped():
with open(filename) as lines:
for line in (l.strip() for l in lines):
if line.startswith("syntax:") or line.startswith("#") or not line: