Skip to content

Instantly share code, notes, and snippets.

@melpomene
melpomene / wordcollector.py
Created October 11, 2011 11:33
Wordlist generating script that parses websites for words.
#!/usr/bin/env python2.7
''' Creates wordlists from web scraping. BeautifulSoup requierd (pip install beautifulsoup) '''
import sys
import os
import robotparser
from BeautifulSoup import BeautifulSoup as bs
import urllib2
from urlparse import urlparse
@melpomene
melpomene / brute.py
Created December 12, 2011 23:18
Statistical attack on simple linear substitution ciphers.
import sys, string, re
"""
Brute.py script to statistically break simple replacement ciphers.
Named after Ceasars killer.
Called with
python brute.py -m 'some text to break'
or
python brute.py -f filewithcypher.txt
@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 / lagrange.py
Created April 24, 2012 19:27
Lagrange interpolation in python
import numpy as np
import matplotlib.pyplot as plt
import sys
def main():
if len(sys.argv) == 1 or "-h" in sys.argv or "--help" in sys.argv:
print "python lagrange.py <x1.y1> .. <x_k.y_k>"
print "Example:"
print "python lagrange.py 0.1 2.4 4.5 3.2"
@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 :