Skip to content

Instantly share code, notes, and snippets.

View klang's full-sized avatar
🏠
Working from home

Karsten Lang klang

🏠
Working from home
View GitHub Profile
(ns one-lineres)
;; 1. Multiple Each Item in a List by 2
(map #(* 2 %) (range 1 11))
;; 2. Sum a List of Numbers
(reduce + (range 1 1001))
;; 3. Verify if Exists in a String
(def words #{"scala" "akka" "play framework" "sbt" "typesafe"})
@klang
klang / variables.tf
Created June 21, 2019 06:48
Terraform 0.12+ does not support "."'s in hash keys
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 February 26, 2018 07:47
resolve dns via local hosts file
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 February 14, 2017 07:14 — forked from john2x/00_destructuring.md
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.

Vectors

@klang
klang / config
Created January 23, 2017 13:59
aws credentials configuration
# ~/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 January 12, 2017 05:58
user is logged in on a ssh connection and has to call a rest service running on his local machine
#!/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 June 22, 2016 13:10
Make jenkins run an aws instance to take care of a build
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]')
@klang
klang / probem001.mli
Last active June 7, 2016 08:17
Project Euler - Problem 1 - https://projecteuler.net/problem=1
(* 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))
# get changes on current branch
alias u="git diff --name-status develop.."
# current branch
git branch | awk '/\*/ { print $2; }'
@klang
klang / forum.py
Created February 29, 2016 10:12
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.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