Skip to content

Instantly share code, notes, and snippets.

View pschwede's full-sized avatar
💭
Brainstorming...

Peter Schwede pschwede

💭
Brainstorming...
View GitHub Profile
@pschwede
pschwede / commas_in_url.patch
Created January 11, 2011 13:29
Patch for dodo/blain
From 4277c9ea35efd406b9c4cbe0ed3526dacb4f6fc6 Mon Sep 17 00:00:00 2001
From: spazz spz pp2 <a@b.c>
Date: Tue, 11 Jan 2011 14:21:26 +0100
Subject: [PATCH 1/2] Support commas in URL
---
inc/parse.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/inc/parse.py b/inc/parse.py
@pschwede
pschwede / Pages
Created February 11, 2011 21:11
Rearranges pages for book-like fold-able printouts.
#!/usr/bin/env python
"""
This script calculates and returns a string of page numbers for
printing book-like fold-able printouts.
Use it like:
python pages.py 42 > pages.file
pdftk input.pdf cat `cat pages.file` output output.pdf
@pschwede
pschwede / Mental arithmetic trainer
Created February 11, 2011 21:17
Uses espeak to ask user about simple arithmetic calculations and answers each question by itself after some time. Default language is German. – It has been reported to me that, making a game with it, can be great fun on parties. ;)
#!/usr/bin/env python
import random as ra
import os, time
def main(language):
ra.seed()
ops = ("+", "-", "*", "/")
equals = ("=")
comma = "point"
@pschwede
pschwede / RegexReduce.py
Last active September 24, 2015 22:58
Reduces a set of strings to one regular expression string. Respects a black list.
'''
===RegexReduce===
Goal is to generate regular expressions out of lists of strings to match
all strings in that list.
This happens by reducing strings to their unique substrings..
@author: spazzpp2
'''
import re
@pschwede
pschwede / gist:1015622
Created June 8, 2011 22:37
small 3d emulation for R/G-Glasses with HMTL, CSS and jQuery
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
animate = function(z,t, dt) {
$("h1").css(
"text-shadow", "rgba(0,0,0,.5) "+17*z+"px "+17*z+"px "+13*z+"pt, rgba(0,0,0,"+.5*(1-z)+") 0 1px 0px, rgba(255,0,0,.5) "+3*z+"pt 1px 3px, rgba(0,255,0,.5) -"+3*z+"pt 1px 3px"
).css(
"font-size", 19*(2+z)+"pt"
@pschwede
pschwede / bpmdetect.py
Created July 28, 2012 12:24
Add bpm tags to your music collection
#!/usr/bin/env python
# Uses bpmcount from bpmdj.sf.net to add BPM-tags to your music files.
# Copyright (C) 2012 spazzpp2
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@pschwede
pschwede / levenshtein.py
Created July 28, 2012 12:28
Calculates Levenshtein-distance between strings
#!/bin/python
# https://en.wikipedia.org/wiki/Optimal_string_alignment
def distance(s, t):
"""Calculate Levenshtein distance between words s and t"""
m, n = len(s), len(t)
d = [[0 for j in range(n)] for i in range(m)]
for i in range(1, m):
d[i][0] = i
@pschwede
pschwede / stringinlist.py
Created August 1, 2012 08:57
Timing the search for a string in a list.
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@pschwede
pschwede / prim.py
Created October 12, 2012 13:26
Adds primes into a file that lists primes. (Absurdly fast single-thread prime finder.)
#!/usr/bin/env python
import time
import os.path
import atexit
import argparse
def write_primes(filename, known_primes):
"""Writes all known primes from RAM to disk"""
@pschwede
pschwede / histdist
Last active October 12, 2015 18:57
Unix command history distribution
#!/usr/bin/env python
from os.path import expanduser
from collections import Counter
distribution = Counter()
f = open(expanduser("~/.bash_history"))
commands = list()
for line in f.readlines():
line = line.replace("\n","").split(" ")