Skip to content

Instantly share code, notes, and snippets.

View j0hn's full-sized avatar

Gonzalo Garcia Berrotaran j0hn

  • Cordoba, Argentina
View GitHub Profile
@j0hn
j0hn / pre-commit
Created August 9, 2012 18:19
git pre commit hook to ask the user if he ran the tests
#!/bin/sh
# file .git/hooks/pre-commit
exec < /dev/tty
read -p "Did you run the tests? [yN]: " yn
case $yn in
[Yy]* ) echo "Ok, your good to go";;
* ) echo "What are you waiting for then?" && exit 1;;
esac
@j0hn
j0hn / str2bf.py
Created January 1, 2012 08:32
String to brainfuck converter
#!/usr/bin/env python
# coding: utf-8
"""
String to Brainfuck.
Converts a string to a brainfuck code that prints that string.
Author: j0hn <j0hn.com.ar@gmail.com>
"""
@j0hn
j0hn / hbuto.py
Created October 10, 2011 14:37
j0hn's hamster buto
#!/usr/bin/env python
# coding: utf-8
"""
j0hn's hamster buto.
Math bitches (?)
"""
import gtk
@j0hn
j0hn / login.py
Created October 4, 2011 03:13
GTK unittest example
#!/usr/bin/env python
# coding: utf-8
import gtk
class LoginWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect("destroy", gtk.main_quit)
@j0hn
j0hn / short_cwd.sh
Created September 30, 2011 23:45
Get a short CWD
#!/bin/sh
# Bash script to transform a long cwd path to a short path
# that shows the first 2 folders, and the last 2 folders
#
# For example:
# /media/Datos/j0hn/Code/py/guicavane/guicavane/Downloaders
# Will be transformed to:
# /media/Datos/.../guicavane/Downloaders
@j0hn
j0hn / kernelroll.c
Created September 18, 2011 04:47
Kernelroll LD_PRELOAD version
/***********************************************************************
* KernelRoll, LD_PRELOAD version. *
* =============================== *
* *
* Compile with: gcc -o kernelroll.so kernelroll.c -shared -fPIC -ldl *
* Run with: LD_PRELOAD=./kernelroll.so some_file.mp3 *
* *
* Remember to change SONG constant in this file *
* *
* Authors: Roger Duran *
@j0hn
j0hn / checkouts.py
Created August 17, 2011 23:39
Checkout models
#!/usr/bin/env python
# coding: utf-8
"""
Checkout queue test, a test between two models of queues on supermarkets
and banks and stuff like that.
The two models tested are:
Independent checkouts Single queue
@j0hn
j0hn / screenshoter
Created July 11, 2011 00:53
Takes a screenshot and uploads it to imgur
#!/bin/bash
IMGPATH="/tmp/$(date +%s)_imgur.png"
if [ "$1" = "window" ]; then
scrot --focused "$IMGPATH"
else
scrot "$IMGPATH"
fi
@j0hn
j0hn / adding_a_method.py
Created June 1, 2011 01:03
How to add a method to an object's instance
#!/usr/bin/env python
# coding: utf-8
"""
Shows how to add a method to a instance of an object.
"""
class Useless:
"""
Does nothing, unless you hack it.
@j0hn
j0hn / loading_bar.py
Created May 10, 2011 12:34
Loading bar
#!/usr/bin/env python
# encoding: utf-8
import os
import sys
import fcntl
import struct
import termios
import threading
from time import sleep