Skip to content

Instantly share code, notes, and snippets.

@embayer
embayer / DACH.json
Last active April 20, 2016 12:26
state names of Germany/Austria/Swiss
{
"Deutschland": [
"Baden-Württemberg",
"Bayern",
"Berlin",
"Brandenburg",
"Bremen",
"Hamburg",
"Hessen",
"Mecklenburg-Vorpommern",
@embayer
embayer / day_of_week.py
Created April 13, 2016 18:11
get the day of week
def get_day_of_week(year, month, day):
month_table = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
if month < 3:
year = year - 1
return (year + year / 4 - year / 100 + year / 400 + month_table[month - 1] + day) % 7
print get_day_of_week(2016, 3, 25)
@embayer
embayer / docker.md
Last active November 5, 2016 12:05
shell cheatsheet

docker

kill all running containers
docker kill $(docker ps -q)
delete all stopped containers (including data-only containers)
docker rm $(docker ps -a -q)
delete all 'untagged/dangling' () images

docker rmi $(docker images -q -f dangling=true)

@embayer
embayer / memoize.py
Created February 24, 2016 20:36
caching decorator
def memoize(f):
cache = {}
def memoized_function(*args):
if args not in cache:
cache[args] = f(*args)
return cache[args]
memoized_function.cache = cache
return memoized_function
@embayer
embayer / dict_in_list.py
Created December 8, 2015 20:39
check if a_list already contains a_dict
from json import dumps
def dict_in_list(a_dict, a_list):
"""
check if a_list already contains a_dict
"""
def dict_equals_dict(dict_a, dict_b):
"""
check if all key-value-pairs of dict_a and dict_b are equal
"""
@embayer
embayer / flex-img-container.html
Created September 28, 2015 15:45
display images of different sizes within a fixed size div
<html>
<head>
<title>kitten store</title>
<style>
.img-container {
width: 600px;
height: 800px;
display: flex;
align-items: center;
justify-content: center;
@embayer
embayer / media_query_breakpoints.css
Last active August 29, 2015 14:26
common css breakpoints
@media (min-width:320px) {
/* smartphones, iPhone, portrait 480x320 phones */
body {background-color: red}
}
@media (min-width:481px) {
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
body {background-color: orange}
}
@media (min-width:641px) {
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
@embayer
embayer / monitor_clipboard.py
Last active August 29, 2015 14:23
monitor the clipboard and write to file
#!/usr/bin/python
import xerox
import time
def poll_cb():
cb = ""
cbh = ""
while True:
@embayer
embayer / media_types.py
Created April 21, 2015 21:23
mimetype mapping
media_types = {
"": "application/octet-stream",
".aif": "audio/aiff",
".aiff": "audio/aiff",
".au": "audio/basic",
".avi": "video/avi",
".bmp": "image/bmp",
".bz": "application/x-bzip",
".bz2": "application/x-bzip2",
".c": "text/x-c",