Skip to content

Instantly share code, notes, and snippets.

@RK11
RK11 / PyFraction.py
Created July 11, 2012 19:37
PyFraction provides fraction for Python
class fraction:
"""This class provides fraction representation and basic operation (+, -, * and /). Operations can be done with fractions and whole numbers)"""
def __init__(self, numerator, denominator = 1):
"""To create a fraction, you can use either numerator and denominator, or only the numerator.
If you give only one decimal number, the find_fraction method will find the appropriate fraction."""
self.numerator = numerator
self.denominator = denominator
if str(self.numerator).find(".") != -1:
self.find_fraction()
@RK11
RK11 / hash_checksum.py
Created July 13, 2012 19:11
A VERY unefficient checksum. Works well with strings and tiny files (<1MB)
class myhash:
"""A VERY unefficient checksum. Works well with strings and tiny files (<1MB)"""
hexa = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
def __init__(self, content = ""):
self.content = content
self.checksum = ['0']*32
self.position = 0
self.update(self.content)
def digest_one(self, to_digest):
@RK11
RK11 / wordsmaker.py
Created August 20, 2012 11:31
Generate (almost) pronounceable words.
#This program enable you to generate pronounceable - not always i admit - words with custom and/or random properties. It can for instance be used to make passwords which are easy to memorize.
import random
###Vars. You can freely add vowels, consonant and syllabes without changing the program
v = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
c = ['a','e','i','o','u']
s = []
for a in v:
for b in c:
s.append(a+b)
@RK11
RK11 / bf.py
Created September 28, 2012 21:40
A brainfuck interpreter (Not completely done, please report bugs)
#Python Brainfuck interpreter, made by RK11
#Version 0.2
#Changelog:
#0.1> First version
#0.2> Better output, and debug mode
import sys, time
class bf:
def __init__(self, input_bf, debug = False):
self.input = input_bf
@RK11
RK11 / posibilities.py
Created October 26, 2012 21:23
All posibilities
def all_posibilities(max_length, letters):
result = []
for length in range(1, max_length+1):
pos = [0]*length
actual_word = ""
limit = (len(letters))**length
nbr_of_words = 0
while nbr_of_words < limit:
for char in range(length):
actual_word = letters[pos[char]] + actual_word
@RK11
RK11 / mp3Skull_downloader.py
Created January 23, 2013 11:40
A simple python program to download in a simple way a mp3 on mp3skull.com. Features : Search, result list, download
import urllib2, urllib
number_of_result = 20
def get_page(query):
page_source = urllib2.urlopen("http://mp3skull.com/mp3/{}.html".format(query.replace(" ","_"))).read()
return page_source
def get_link(page_source, n):
# "n" is the position in the list in the results