Skip to content

Instantly share code, notes, and snippets.

Karsten Lang klang

Block or report user

Report or block klang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
klang /
Created Jun 21, 2019
Terraform 0.12+ does not support "."'s in hash keys
locals {
project = "project-name"
env = {
# = "default-workspace-name" # <= tf0.11 notation
default_name = "default-workspace-name" # <= tf0.12 notation
# = "other-workspace-name"
other_name = "other-workspace-name"
name = "${lookup(local.env, "${terraform.workspace}_name")}"
klang / .bashrc
Created Feb 26, 2018
resolve dns via local hosts file
View .bashrc
function resolve {
if [[ -f "$hostfile" ]]; then
for arg in $(seq 1 $#); do
if [[ "${!arg:0:1}" != "-" ]]; then
ip=$(sed -n -e "/^\s*\(\#.*\|\)$/d" -e "/\<${!arg}\>/{s;^\s*\(\S*\)\s*.*$;\1;p;q}" "$hostfile")
if [[ -n "$ip" ]]; then
command "${FUNCNAME[1]}" "${@:1:$(($arg-1))}" "$ip" "${@:$(($arg+1)):$#}"
klang /
Created Feb 14, 2017 — forked from john2x/
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.


klang / config
Created Jan 23, 2017
aws credentials configuration
View config
# ~/aws/config
[profile main-account-with-no-resources]
[profile sub-account-with-resources]
region = eu-west-1
role_arn=arn:aws:iam::<account number for sub-account-with-resources>:role/dashsoft-iam
klang /
Last active Jan 12, 2017
user is logged in on a ssh connection and has to call a rest service running on his local machine
foo=$(pstree -c -p -s $$ | awk -Fsshd '{print $3}' | cut -f2 -d '(' | tr -d ')' | tr -d '-')
caller=$(who -u | grep $foo | cut -f2 -d '(' | tr -d ')')
# a few other ways to get the IP
TTy=$(ps -eo pid,tty|grep $$|awk '{print $2}')
WhoAmI=$(who -u |grep -e "$TTy")
TheIp=$(echo $WhoAmI | awk '{print $7}' | sed 's/[()]//g'
klang /
Created Jun 22, 2016
Make jenkins run an aws instance to take care of a build
aws ec2 describe-instances --region eu-central-1 --output table --filter Name=image-id,Values=$AMI
aws ec2 run-instances --image-id $AMI --count 1 --instance-type t2.medium --key-name xxxxxx --security-group-ids sg-xxxxxxxx --subnet-id subnet-xxxxxxxx --iam-instance-profile Name=CIWindows --region eu-central-1 --output table
aws ec2 wait instance-exists --region eu-central-1 --output json --filter Name=image-id,Values=$AMI
instance=$(aws ec2 describe-instances --region eu-central-1 --output text --filter Name=image-id,Values=$AMI --query 'Reservations[*].Instances[*].[InstanceId]')
View probem001.mli
(* Ocaml *)
let rec range ?(start=0) len =
if start >= len
then []
else start :: (range len ~start:(start+1))
List.fold_left (+) 0 ( (fun x -> if 0 = x mod 3 or 0 = x mod 5 then x else 0) (range 1000))
List.fold_left (+) 0 (List.filter (fun x -> 0 = x mod 3 or 0 = x mod 5) (range 1000))
View git shortcuts
# get changes on current branch
alias u="git diff --name-status develop.."
# current branch
git branch | awk '/\*/ { print $2; }'
klang /
Created Feb 29, 2016
boto2 forum example for boto3
import boto3, hashlib, json, datetime, time, sys, getopt, threading, logging
import botocore
from boto3.dynamodb.conditions import Key, Attr
logging.basicConfig(filename='forum.log',level=logging.INFO, format="%(threadName)s:%(message)s")
class APIerror(Exception):
klang / README
Created Feb 25, 2016
a control loop keeping several threads alive
virtualenv -p $(which python3) venv
source venv/bin/activate
(venv)[klang@ergates workers]$ python -i
You can’t perform that action at this time.