Skip to content

Instantly share code, notes, and snippets.

:shipit:
Shipping up to Boston

Christoph Gerneth c7h

View GitHub Profile
@c7h
c7h / read_portexpander.sh
Created Sep 6, 2018
Read an I2C Portexpander
View read_portexpander.sh
#!/bin/bash
ADDRESS=0x27
printf "76543210 76543210\n"
while :
do
v=$(i2cget -y 0 $ADDRESS 0x00 w)
echo ${v: -4:4} | xxd -r -p | xxd -b | awk '{split($0,a," "); printf "%s %s\r", a[2], a[3]}'
done
View rotarydial.ino
/* Rotary Dial encoder
encode the rotary dial of an old analog phone.
by Christoph Gerneth
*/
const int active_pin = 2;
const int pulse_pin = 3;
int number_counter = 0;
int last_pulse_state = 0; // last state of the rotary dial pulser
int last_active_state = 0;
@c7h
c7h / gist:cbba43f1c3d58250f9c9fc7bd39ebba7
Created Jul 17, 2017
major and annoying differences between module versions of Pythons JSON Library
View gist:cbba43f1c3d58250f9c9fc7bd39ebba7
Two versions of the same library behave completely different :-/
the PI
```
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> try:
View keybase.md

Keybase proof

I hereby claim:

  • I am c7h on github.
  • I am c7h (https://keybase.io/c7h) on keybase.
  • I have a public key ASCdetH8IgkxSS8N_CBwRxZhqthPiFpK-iGS4vlIn1vtUQo

To claim this, I am signing this object:

@c7h
c7h / user.pl
Created Dec 9, 2015
logfile evaluation
View user.pl
#!/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 Nov 16, 2015
understanding binary search trees
View binserarchtree.py
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 Jul 3, 2015
CSV DictWriter Example
View gist:e0aa37201f255fd5e92a
__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()
View gist:e2c73880159ab3502539
__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 Jun 14, 2015
the _drop-method is used for unittesting. Easy way to get rid of all your old instances.
View SingletonTypes.py
__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
Process States in LaTeX with tikz
View gist:096f09925cbbea8fb11b
\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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.