Skip to content

Instantly share code, notes, and snippets.

@bjorand
bjorand / panic_catch.go
Created April 9, 2017 09:56
Golang catch panic
for {
func() {
defer func() {
if r := recover(); r != nil {
fmt.Printf("panic: %v\n", r)
}
}()
// CODE here
}
}
@bjorand
bjorand / ansible-retry-example.yml
Created January 4, 2017 18:07
Ansible retry task example
---
- hosts: all
connection: local
tasks:
- shell: exit 1
register: task_result
until: task_result.rc == 0
retries: 10
delay: 1
ignore_errors: yes
@bjorand
bjorand / bash-uuid.sh
Last active December 29, 2016 10:15
Generate UUID with bash
od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
@bjorand
bjorand / detect-os.sh
Created December 20, 2016 16:17
Helper for Detecting OS with bash
OS="$(uname -s)"
case $OS in
"Darwin")
echo dar
;;
"Linux")
echo lin
;;
*)
#!/usr/bin/env python
import re
import sys
import random
interrupts = {}
count = int(sys.argv[1])
@bjorand
bjorand / wait_tcp_port.sh
Last active June 22, 2016 19:14
Wait for a TCP port, Bash style
wait_tcp_port() {
local host="$1" port="$2"
# see http://tldp.org/LDP/abs/html/devref1.html for description of this syntax.
while ! exec 6<>/dev/tcp/$host/$port; do
echo "$(date) - still trying to connect to $host:$port"
sleep 1
done
exec 6>&-
}
import base64
import binascii
s = 'MDAxMDAwMDEwMTExMDEwMTAxMTAxMTExMDExMTEwMDEwMDEwMDAwMDAxMTEwMTAwMDExMDExMTAwMTEwMDAwMTAxMTEwMTExMDAxMDAwMDAwMTEwMDEwMTAxMDEwMTEx'
binary = int(base64.b64decode(s), 2)
ascii = binascii.unhexlify('%x' % binary)
print ascii[::-1]
@bjorand
bjorand / compile.rb
Last active April 20, 2016 16:02
Chef solo compile attribute
require 'mixlib/cli'
require "chef"
require "chef/config"
require "chef/config_fetcher"
require 'chef/workstation_config_loader'
class MyCLI
include Mixlib::CLI
@bjorand
bjorand / cleanup-ami.py
Last active September 10, 2015 16:29 — forked from marvinpinto/cleanup-ami.py
Python script to clean up and update the Jenkins AMIs after a successful Packer run
#!/usr/bin/python
import requests
import os
import boto.ec2
import sys
import re
build_url = os.environ['BUILD_URL']
jenkins_base_url = os.environ['JENKINS_URL']
#!/bin/bash
awk 'BEGIN{ser=strftime("%Y%m%d",systime() )*100+1} /serial/{sub($1,$1 < ser ? ser : $1+1)}1' $1