Skip to content

Instantly share code, notes, and snippets.

View hinnerk's full-sized avatar

Hinnerk Haardt hinnerk

View GitHub Profile
@hinnerk
hinnerk / stack-ressources.sh
Last active June 13, 2018 09:28
Count AWS CloudFormation Stack Ressources
AWS_PROFILE=XXX
AWS_DEFAULT_REGION=YYY
echo -e "Stack Name\t\tRessource Count"; for name in $(aws cloudformation list-stacks --stack-status-filter UPDATE_COMPLETE CREATE_COMPLETE | jq --raw-output ".StackSummaries[].StackName"); do echo -ne "${name}\t"; aws cloudformation list-stack-resources --stack-name ${name} | jq ".StackResourceSummaries | length"; done

Ghostscript tricks (run in )

  • render a pdf as png files, to remove all hidden information: gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -r600 -dDownScaleFactor=3 -sDEVICE=png16m -sOutputFile=new-%01d.png original.pdf
  • rebuild a pdf file to remove errors: gs -dPDFA -dBATCH -dNOPAUSE -sProcessColorModel=DeviceCMYK -sDEVICE=pdfwrite -sPDFACompatibilityPolicy=1 -sOutputFile=repariert.pdf original.pdf
@hinnerk
hinnerk / XeLaTeX-Docker.engine
Last active August 29, 2015 14:09
TeXShop Engine description for dockerized XeLaTeX. Place in `~/Library/TeXShop/Engines/`.
#!/bin/bash
export WORKDIR=$( cd $(dirname $1) ; pwd -P )
export FILENAME=$( basename $1 )
for x in `boot2docker shellinit`; do if [ $x != 'export' ]; then export $x; fi; done
docker inspect xelatex > /dev/null && docker rm xelatex > /dev/null
echo "Starting dockerized XeLaTeX in $WORKDIR on $FILENAME"
# clean all temporary stuff
port clean --all all
# remove all inactive ports
port -f uninstall inactive
# update all installed ports and remove the outdated ones
port -u upgrade outdated
# get all the dependecies for…
@hinnerk
hinnerk / NIST_TestVectors_AES256CTR.py
Created January 7, 2014 19:35
NIST AES 256 CTR Test Vectors.
# NIST AES 256 CTR test vector
key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4"
counter = (0xf0f1f2f3, 0xf4f5f6f7, 0xf8f9fafb, 0xfcfdfeff)
counter = ("\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")
nist = {'block1': {'plain': "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
@hinnerk
hinnerk / ngramm.py
Created January 7, 2014 19:33
n-gram Zerlegung aus einem Programmierkurs für Erwachsene aus dem Jahre 2010.
#!/usr/bin/env python2.7
from operator import itemgetter
import sys, pickle, os
def normalisiere_text(text):
"""
1. Buchstaben sollen zu Kleinbuchstaben werden
@hinnerk
hinnerk / mxquest.py
Created January 7, 2014 19:28
Get mail exchange provider for a list of domains.
#!/usr/bin/env python2.6
import commands
domains = ['meine-domain.de', 'meine-andere-domain.com']
def slice_domain(o):
ergebnis = "UNDEFINED"
count = 0
for line in o.split("\n"):
@hinnerk
hinnerk / ics2rem.awk
Created January 7, 2014 17:43
Why would anyone ever write an awk script? This one converts some parts of an ics calender file to the remind format.
#!/usr/bin/awk -f
# ics2rem by Hinnerk Haardt <hinnerk@randnotizen.de>
#
# Converts output of iCalendar to remind
# usage: cat FILENAME.ics | rem2ics > reminders.rem
#
# THE FOLLOWING CODE IS RELEASED INTO THE PUBLIC DOMAIN
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@hinnerk
hinnerk / __init__.py
Created January 7, 2014 17:03
What's faster, `filter()` or `reduce()`? Find out using a very primitive Monte Carlo search für π.
from random import random
from datetime import datetime
def simulate_dart(x=None):
point_x = random()
point_y = random()
distance = (point_x**2 + point_y**2)**.5 # x**0.5 == sqrt(x)
return (distance < 1) and 1 or 0
@hinnerk
hinnerk / hashbench.py
Created January 7, 2014 17:00
My self written RollingHash was slower than SHA-1… (written ~2007)
import hashlib
from backup import hashes
import timeit
import cProfile
def rechne_sha(filename):
block = open(filename, "rb").read()
for i in range (512,len(block)):
[hashlib.sha1(block[i:i+512]).hexdigest()]