Skip to content

Instantly share code, notes, and snippets.

@c7h
c7h / gist:e2c73880159ab3502539
Created June 21, 2015 13:04
Python Decorator
__author__ = 'Christoph Gerneth'
'''
Decorators are one of the most powerful patterns. They can be used to
inject code in functions, modify them and infuence their beihavior.
[wikipedia](https://en.wikipedia.org/wiki/Decorator_pattern)
Here is an example:
'''
class Tools(object):
@classmethod
def sayhello(self, func):
@c7h
c7h / SingletonTypes.py
Created June 14, 2015 11:21
the _drop-method is used for unittesting. Easy way to get rid of all your old instances.
__author__ = 'Christoph Gerneth'
class SingletonType(type):
def __call__(self, *args, **kwargs):
try:
return self.__instance
except AttributeError:
self.__instance = super(SingletonType, self).__call__(*args, **kwargs)
return self.__instance
@c7h
c7h / gist:096f09925cbbea8fb11b
Created May 29, 2015 13:29
Process States in LaTeX with tikz
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5cm,
thick,main node/.style={circle,fill=blue!20,draw,
font=\sffamily\Large\bfseries,minimum size=15mm}]
\node[main node] (B) {B}; %Bereit
\node[main node] [above left of=B](L) {L}; %Laufend
\node[main node] [above right of=B](I) {I}; %Inaktiv
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---
@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
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: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: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: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: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: