Skip to content

Instantly share code, notes, and snippets.

@melpomene
melpomene / binarysearchtree.py
Created April 16, 2014 21:10
Binary search tree in python
class Node():
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def append(self, value):
if value < self.value:
@melpomene
melpomene / findGroupSignup.py
Created January 18, 2012 00:30
Find labb sign up page for Computer Science courses on LTH when teacher forgett to update links on course page...
import requests
import time
COURSE_NAME = "Kompilatorteknik"
""" Byt ut COURSE_NAME till kursen du letar efter. Botten crawlar sedan och hojtar till om den hittar din kurs labbanmälningsformulär.
Kommer även skriva ner datan till fil om ditt sökord inte fungerade och du vill kolla för hand.
GLÖM EJ ÄNDRA PATH TILL FILEN DU VILL SKRIVA TILL"""
f = open("/path/to/file/sites.txt", "a")
@melpomene
melpomene / Main.py
Created January 19, 2012 00:37
Script to download all Amigara episodes. [ugly hack]
import urllib
import requests
from BeautifulSoup import BeautifulSoup
""" CHANGE PATH TO DIRECTORY IN WHICH TO SAVE FILES AND ALL IS WELL"""
PATH = "path/to/file"
url = "http://brasscockroach.com/h4ll0w33n2007/manga/Amigara-Full/Amigara-0.html"
img_url = "http://brasscockroach.com/h4ll0w33n2007/manga/Amigara-Full/"
r = requests.get(url)
count = 0
@melpomene
melpomene / shiftordivide.py
Created April 11, 2012 14:11
Compare bit shift and division in Python
"""
Why is division by two slower than bitshift in python?
Should the "compiler" represent this in the same way.
> python shiftordivide.py
Divided mean time took 0.027
Shift mean time took 0.008
>pypy shiftordivide.py --OJit
Divided mean time took 0.034
@melpomene
melpomene / Main.py
Created May 3, 2012 19:51
Uploads emails ending with "if republished"-threats to Pastebin.
import getpass
import imaplib
import ConfigParser
import httplib
import urllib
import pastebin
import emailfilter
#Add filters here
email_filters = [emailfilter.ExampleFilter(), emailfilter.SwedishKeywordFilter()]
@melpomene
melpomene / tree.py
Created May 16, 2012 09:47
Test difference in speed and memory usage of DFS and BFS.
import time,sys
from random import randint
class node():
def __init__(self, child1, child2, data):
self.left = child1
self.right = child2
self.data = data
def __str__(self):
return str(self.data)
@melpomene
melpomene / crawlsongbook.py
Created May 21, 2012 00:48
Convert html songbook to JSON
""" A small script to crawl a website with some songs on it and put it in a JSON file format."""
import requests, re, json
re.DEBUG = True
URL = "http://www.hedin.mobi/sangbok/lista.php"
if __name__ == "__main__":
r = requests.get(URL)
reg = re.compile(r"<h2>(.+?)</h2><p>Melodi:(.*?)</p><p>(.+?)</p>")
songs = reg.findall(r.content.replace("\r\n", '').decode('iso8859-1'))
song_list = []
@melpomene
melpomene / Read.py
Created May 27, 2012 12:59
Read info from Arduino handcontroller and fake mouse events
import serial
import time
import sys
from os import system
class JoystickReader():
def __init__(self):
try :
@melpomene
melpomene / Monty.py
Created July 9, 2012 17:15
Monty Hall problem
from random import randint
class Game:
def __init__(self):
self.correct = randint(0,2)
def make_guess(self, door):
self.guess = door
def verify(self):
@melpomene
melpomene / LinkedList.scala
Created August 3, 2012 01:18
Learning Scala
class LinkedList(startNode:Node) {
var lastNode = startNode
def printList() = {
startNode.print()
}
def addNode(node:Node) = {
this.lastNode.next = Some(node)
node.last = Some(lastNode)
this.lastNode = node