Skip to content

Instantly share code, notes, and snippets.

@danielthiel
danielthiel / clear_workspace.m
Created June 10, 2015 06:23
clear matlab workspace (closing figures and open simulink models)
% clear workspace
clear % erase variables from matlab workspace without saving
clc % clear command window
close all % close all figures windows wihtout saving
bdclose all % close all simulink models without saving
@danielthiel
danielthiel / execution_time.py
Created May 4, 2015 11:16
time the application execution of fn to args
"""
by: Peter Norvig
http://norvig.com/python-iaq.html
"""
def timer(fn, *args):
"Time the application of fn to args. Return (result, seconds)."
import time
start = time.clock()
return fn(*args), time.clock() - start
@danielthiel
danielthiel / capslock-to-umlate.ahk
Last active August 29, 2015 14:19
Remap Capslock to special characters via AutoHotkey (umlauts)
; Remap Umlaute
; http://www.autohotkey.com/
; 2015-04-21
SetCapsLockState AlwaysOff
Capslock::RAlt
>!+a::
Send, Ä
Return
>!+u::
Send, Ü
@danielthiel
danielthiel / round_up_minutes.py
Created April 6, 2015 12:22
Round up the minutes of a datetime object to any minute factor
import datetime
import math
def round_up_minutes(dt=None, minute_factor=60):
""" Round up the minutes of a datetime object to any minute factor
dt : datetime.datetime object, default now.
minute_factor : number to which closest factor the minutes will round up
with minute_factor = 15 it would round up to the closest quarter hour (0, 15, 30, 45)
with minute_factor = 60 it would always round up to the next full hour
@danielthiel
danielthiel / myconf.conf
Last active August 29, 2015 14:13
An example for [supervisor](http://supervisord.org/).
[program:myconf]
command=/root/to/my/folder/startup.py
directory=/root/to/my/folder/
user=myusername
@danielthiel
danielthiel / sqlalchemy_simple.py
Created January 21, 2015 18:21
simple SQLAlchemy example
from __future__ import print_function
import datetime
from sqlalchemy import create_engine
from sqlalchemy import Column, DateTime, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# connect to an database:
@danielthiel
danielthiel / fotografie.md
Created August 20, 2014 20:15
mein cheat sheet zur fotografie (Anfänger! und ich wusste nicht wohin schreiben - also hier)

Thiel's Fotografie Cheat Sheet

Von einem Anfänger der in die Fotografie rein kommen will.

Begriffe

Schärfentiefe

auch ST, der Bereich nach hinten (z-Achse) der scharf ist im Bild

@danielthiel
danielthiel / imagecrop_opencv.py
Created August 20, 2014 17:23
crop images with opencv (OpenCV)
"""
found here: http://amiest-devblog.blogspot.de/2008/08/how-to-crop-images-with-opencv-in.html
opencv: http://opencv.org/
"""
cropped = cvCreateImage( cvSize(new_width, new_height), 8, 3)
src_region = cvGetSubRect(image, opencv.cvRect(left, top, new_width, new_height) )
cvCopy(src_region, cropped)
@danielthiel
danielthiel / args_kwargs.py
Created August 8, 2014 15:02
arguments args, keyword arguments kwargs with functions (more to come!)
def kwargs_test(**kwargs):
print('search for keyword >foo<: {0}'.format(kwargs.get('foo') or 'nope...'))
if __name__ == "__main__":
kwargs_test(foo='success')
kwargs_test(bar='you dont see this')
@danielthiel
danielthiel / json_encoder.py
Created May 23, 2014 11:37
JSON encoder class with serializer for dates and decimal numbers: serializes json objects without error
import json
import datetime
import decimal
class MyJsonEncoder(json.JSONEncoder):
""" JSON Encoder with serializer for dates and decimal numbers """
def default(self, obj):
if isinstance(obj, datetime.datetime):
return str(obj.isoformat())
elif isinstance(obj, datetime.time):