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
klang / variables.tf
Created Jun 21, 2019
Terraform 0.12+ does not support "."'s in hash keys
View variables.tf
locals {
project = "project-name"
env = {
# default.name = "default-workspace-name" # <= tf0.11 notation
default_name = "default-workspace-name" # <= tf0.12 notation
# other.name = "other-workspace-name"
other_name = "other-workspace-name"
}
name = "${lookup(local.env, "${terraform.workspace}_name")}"
}
@klang
klang / .bashrc
Created Feb 26, 2018
resolve dns via local hosts file
View .bashrc
function resolve {
hostfile=~/.hosts
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)):$#}"
return
fi
@klang
klang / 00_destructuring.md
Created Feb 14, 2017 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet
View 00_destructuring.md

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.

Vectors

@klang
klang / config
Created Jan 23, 2017
aws credentials configuration
View config
# ~/aws/config
[profile main-account-with-no-resources]
aws_access_key_id=...
aws_secret_access_key=...
[profile sub-account-with-resources]
region = eu-west-1
role_arn=arn:aws:iam::<account number for sub-account-with-resources>:role/dashsoft-iam
source_profile=dashsoftiam
@klang
klang / call-rest-service-on-caller-machine.sh
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
View call-rest-service-on-caller-machine.sh
#!/bin/bash
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
klang / jenkins-start-compile-service.sh
Created Jun 22, 2016
Make jenkins run an aws instance to take care of a build
View jenkins-start-compile-service.sh
AMI="ami-xxxxxxxx"
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 (List.map (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
klang / forum.py
Created Feb 29, 2016
boto2 forum example for boto3
View forum.py
import boto3, hashlib, json, datetime, time, sys, getopt, threading, logging
import botocore
from boto3.dynamodb.conditions import Key, Attr
logging.getLogger('botocore').setLevel(logging.CRITICAL)
logging.getLogger('boto3').setLevel(logging.CRITICAL)
logging.basicConfig(filename='forum.log',level=logging.INFO, format="%(threadName)s:%(message)s")
class APIerror(Exception):
pass
@klang
klang / README
Created Feb 25, 2016
a control loop keeping several threads alive
View README
virtualenv -p $(which python3) venv
source venv/bin/activate
(venv)[klang@ergates workers]$ python -i tester_run.py
>>>
You can’t perform that action at this time.