Skip to content

Instantly share code, notes, and snippets.

View jamesandariese's full-sized avatar

James Andariese jamesandariese

View GitHub Profile
@jamesandariese
jamesandariese / highernotify.yml
Last active September 17, 2015 18:30
Ansible: Higher Order Notification Handlers
---
# Store the notification in a variable. We'll check it later.
# First, set the variable. We're using "blah".
- hosts: all
gather_facts: false
tasks:
- set_fact: blah=false
# Now do some other stuff. Use notify to get the same behavior as a normal handler.
# Alternatively, just use set_fact with when. They're equivalent.
@jamesandariese
jamesandariese / bin_autoactivate
Created November 3, 2015 17:41
autoactivating venv
#!/bin/sh
# add the following to your .bash_profile
# PROMPT_COMMAND=". ~/bin/autoactivate;$PROMPT_COMMAND"
# when you want to work on a project with a venv,
# run virtualenv venv in the base directory.
# awesomeness will ensue.
pushd . > /dev/null
@jamesandariese
jamesandariese / mosh-clean
Created November 27, 2015 17:25
mosh-clean: cleanup dangling mosh servers
#!/bin/sh
# This kills all mosh-servers not directly the parent of your shell.
# This will not work entirely correctly if your shell isn't being run directly by
# `mosh-server`.
# This next line can either go in your bashrc or the file can be sourced by it.
alias mosh-clean='(ps jp $$ |tail -n +2; ps x |tail -n +2) | awk '"'"'$1 != skippid && rest && $5 ~ /^mosh-server$/ {print $1} !rest {rest=1; skippid = $1}'"'"' | xargs -rt kill'
@jamesandariese
jamesandariese / list-buckets-with-regions.go
Created March 1, 2016 03:37
List Buckets with Regions
package main
import "fmt"
import "log"
import "encoding/json"
import "github.com/aws/aws-sdk-go/aws/session"
import "github.com/aws/aws-sdk-go/service/s3"
import "sync"
@jamesandariese
jamesandariese / ppt.sh
Created April 8, 2016 02:16
Pipe Printing Time
alias ppt='awk '\''{print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush();}'\'''
@jamesandariese
jamesandariese / intersection.jq
Created April 18, 2016 21:28
JQ Intersection
$ echo "[2,3,4,5]" | jq -c 'def intersection($a): . - (.-$a); intersection([1,2,3])' │~
[2,3]
@jamesandariese
jamesandariese / README.md
Last active May 17, 2016 01:00
Bash quoting

Bash Escaping

Description

I constantly am using watch with some hideous chain of jq and awk.

Perhaps I could always have a dashboard or always have my logs exactly the right info and never need to poll a system for something interesting about it that was unexpected -- yeah, right.

#!/bin/bash
set -o pipefail
SNMPWALK=/usr/bin/snmpwalk
SNMPGET=/usr/bin/snmpget
AWK=/bin/awk
IP=
MOUNTPOINT="/"
@jamesandariese
jamesandariese / 1.hs
Last active September 6, 2016 09:09
99 haskells
-- get last item in a list
myLast [] = error "out of range"
myLast (x : []) = x
myLast (_ : r) = myLast r
main = do
putStrLn(show(myLast [1,2,3]))
@jamesandariese
jamesandariese / fizzbuzz.hs
Last active September 12, 2016 03:31
haskell fizzbuzz
-- Return a list of strings of fizzbuzz from [1..]
fizzbuzz :: [[Char]]
fizzbuzz = fizzbuzz' 1
where
fizzbuzz' n =
fizzbuzzer : (fizzbuzz' (n + 1))
where fizzbuzzer
| fb3 = "Fizz"
| fb5 = "Buzz"
| fb3 && fb5 = "FizzBuzz"