Skip to content

Instantly share code, notes, and snippets.

@c7h
c7h / gist:4722329
Last active December 12, 2015 05:28
primitive built-in debugging w. execution time measurement.
import time
import inspect
start_time = time.time()
debuglevel = 2 #e.g: 0=no 1=error 2=info ...
def printdebug(level, message):
if debuglevel >= level:
curr_time = time.time() - start_time
caller = inspect.stack()[1][3]
@c7h
c7h / gist:4730089
Created February 7, 2013 10:22
primitive debugging class as Singleton
'''
Created on Feb 6, 2013
@author: Christoph Gerneth
'''
import time
import inspect
class SingletonType(type):
@c7h
c7h / gist:5003772
Created February 21, 2013 10:30
split string - fixed format
n = 8 #format
[line[i:i+n] for i in range(0, len(line), n)]
@c7h
c7h / gist:5396518
Created April 16, 2013 14:47
CSV to VCARD
#!/usr/bin/python
import sys
import csv
def convert(filename):
reader = csv.reader(open(filename, 'rb'))
for row in reader:
@c7h
c7h / gist:5521563
Created May 5, 2013 17:54
maxgif.com image download script (via firefox bookmarks)
#! /usr/bin/env python
'''
Created on 05.05.2013
@author: christoph gerneth
ugly, short hack!
read in firefox bookmarks and
download images from maxgif.com
'''
@c7h
c7h / gist:5526802
Last active December 17, 2015 01:10
authenticates user at HI-PLAN
import requests
def authenticate(username, password, fh="fhin"):
"""
'authenticates' user at hiplan-app
@return: session id
@raise LoginFailedException: if login fails
"""
url = "https://www2.primuss.de/stpl/login.php"
values = {
@c7h
c7h / gist:5943777
Last active December 19, 2015 10:49
different usage of SQL's stored functions and stored procedures
-- schema for exchange:
CREATE TABLE exchange(cur VARCHAR(3), rate DECIMAL(12,3));
INSERT INTO exchange VALUES ("eur", 1.00), ("usd", 1.28), ("czk", 25.98);
-- stored procedure
DELIMITER :-)
CREATE PROCEDURE exrate(IN cur_in DECIMAL(12,3), IN currency VARCHAR(3), OUT cur_out DECIMAL(12,3))
BEGIN
DECLARE course DECIMAL(12,3) DEFAULT 1;
SET course = (SELECT rate FROM exchange WHERE cur = currency);
@c7h
c7h / gist:6421212
Created September 3, 2013 08:38
read methods from module, starting with a given string and return a list
def read_funcs_from_module(self, functionname_prefix, module):
"""read methods from module, starting with a given string and return a list"""
moduleValues = module.__dict__.values()
functions_in_module = filter(lambda obj: hasattr(obj, '__call__'), moduleValues)
matching_functions = filter(lambda k: k.__name__.startswith(functionname_prefix), functions_in_module)
return matching_functions
@c7h
c7h / gist:8670768
Last active January 4, 2016 19:59
Hashmap Example - Understanding Hashmap - linear probing
#!/usr/bin/env python
#Hashmap example
#Author: Christoph Gerneth
#usage: python ordinal-hashmap.py map-size x y STR_1 [STR_2 STR_3 .. STR_N]
#x and y are K_x K_y (Glaviner Standard values for Hashfunction
#example python ordinal-hash.py 13 1 3 Petrus Andreas Jakobus Johannes Phillippus Bartholomaus Thomas Matthaus Jakobus Thaddaus Simon Judas
import sys
debug=True
chars_start = int(sys.argv[2])
chars_end = int(sys.argv[3])
c7h in ~/workspace/TimetableParser/examples on master ● λ python read_semesterplan.py -u if1184
Password:
Deine Faecher dieses Semester:
00: Entwicklung mobiler Anwendung unter iOS bei Mack, Alexander
01: Next Generation Networks bei Sós, Eckhard
Heute auf dem Plan:
---nichts---