Skip to content

Instantly share code, notes, and snippets.

@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:
@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: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: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 / user.pl
Created December 9, 2015 10:53
logfile evaluation
#!/usr/bin/perl
my $user_c = 0;
my $user_min = 0;
my @ip = ();
while(<>) {
if (m/(^\w+).*(\d{2}:\d{2})/) {
if ($1 eq 'christoph'){
$user_c++; # user_zaehler erhöhen
@c7h
c7h / binserarchtree.py
Created November 16, 2015 23:16
understanding binary search trees
class BinSearchTreeElement(object):
def __init__(self, data, leftTree=None, rightTree=None):
self.data = data
self.left = leftTree
self.right = rightTree
def add(self, element):
if element <= self.data:
self._insertElement(self.left, element)
else:
@c7h
c7h / gist:e0aa37201f255fd5e92a
Created July 3, 2015 10:03
CSV DictWriter Example
__author__ = 'Christoph Gerneth'
from csv import DictWriter
from random import randrange
filename = 'data.csv'
label = ['x-axis', 'y-axis']
with open(filename, 'w') as f:
csvw = DictWriter(f, fieldnames=label)
csvw.writeheader()
@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):