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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get changes on current branch | |
alias u="git diff --name-status develop.." | |
# current branch | |
git branch | awk '/\*/ { print $2; }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
virtualenv -p $(which python3) venv | |
source venv/bin/activate | |
(venv)[klang@ergates workers]$ python -i tester_run.py | |
>>> |