Skip to content

Instantly share code, notes, and snippets.

@danielthiel
danielthiel / .gitignore
Last active December 27, 2015 16:29 — forked from realtime/.gitignore
gitignore File for LaTeX projects
# editor backups and auto-saves
*~
*.bak
*.swp
\#*#
# files generated by TeX system or TeX editors
*.aux
*.glo
*.idx
@danielthiel
danielthiel / periodical_updates.js
Last active January 2, 2016 23:09
for rootScope some global variable if you don't use it in AngularJS context
clearInterval($rootScope.last_tick)
$rootScope.last_tick = setIntervall(self.updateFunction, 2000)
@danielthiel
danielthiel / SQLAlchemy_cast.py
Last active February 12, 2021 13:06
SQLAlchemy: filter by date for an datetime field(does not work with SQLite, with PostgreSQL it works fine)
from datetime import date
from sqlalchemy import cast, DATE
Match.query.filter(cast(Match.date_time_field, DATE)==date.today()).all()
@danielthiel
danielthiel / simulink_export.matlab
Last active August 29, 2015 13:56
Simulink: export models or scopes
@danielthiel
danielthiel / pretty_date.py
Created March 1, 2014 18:20
Returns a prettyfied date
def pretty_date(dt, default='gerade'):
"""
Returns string representing "time since" e.g.
3 days ago, 5 hours ago etc.
Ref: https://bitbucket.org/danjac/newsmeme/src/a281babb9ca3/newsmeme/
"""
now = datetime.utcnow()
diff = now - dt
periods = (
(diff.days / 365, 'Jahr', 'Jahren'),
@danielthiel
danielthiel / pil_scale_picture.py
Last active August 29, 2015 13:56
Scale a picture/image in python with PIL (pil-python)
""" some documentation:http://www.effbot.org/imagingbook/ """
from PIL import ImageOps
from PIL import Image
def scale_picture(img_path, size=(150,150), save_path='/tmp', subdir=False):
"""
img_path: absolute path to a picture
size: (width, height) tuple
save_path: where the new files be saved
@danielthiel
danielthiel / aws_s3_class.py
Last active August 29, 2015 13:56
Uploading files to Amazon Web Service (AWS) S3 with BOTO. Init with AWS-ID, AWS-KEY.
from boto.s3.connection import S3Connection
from boto.s3.key import Key
# from boto.s3.connection import Location
class FilehandlerAmazon():
def __init__(self, aws_id, aws_key):
self.aws_id = aws_id
self.aws_key = aws_key
self.conn = S3Connection(self.aws_id, self.aws_key)
@danielthiel
danielthiel / template.html
Created March 2, 2014 11:46
Mutliple forms in flask
<!-- put Forms here -->
<input type="submit" name="button" value="Save">
<input type="submit" name="button" value="Cancel">
@danielthiel
danielthiel / gcm.py
Created April 18, 2014 22:27
GCM (Google Cloud Messaging) in Python
"""
https://developer.android.com/google/gcm/index.html
https://github.com/geeknam/python-gcm
"""
from gcm import GCM
API_KEY = 'secret'
DEVICE_REG_ID = 'some_registrated_device_id'
@danielthiel
danielthiel / go_through_files.py
Created May 3, 2014 16:10
different walk stuff in python, go through all files recursively or just files in one directory
import os
def all_files(dirname):
for root, dirs, filenames in os.walk(dirname):
for f in filenames:
print f
# log = open(os.path.join(root, f),'r')
def all_files_in_dir(dirname):
onlyfiles = [ f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname,f)) ]