Skip to content

Instantly share code, notes, and snippets.

View j0hn's full-sized avatar

Gonzalo Garcia Berrotaran j0hn

  • Cordoba, Argentina
View GitHub Profile
#/usr/bin/env python
# -*- encoding: utf-8 -*-
import time
import random
import sys
if len(sys.argv) > 1:
word = " ".join(sys.argv[1:])
else:
@j0hn
j0hn / criba.py
Created March 14, 2011 11:59
Prime criba
#!/usr/bin/env python
import sys
import time
def f(k):
return lambda j: (j <= k) or (j%k != 0)
def criba(i, version=1):
p = range(2, i)
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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