Skip to content

Instantly share code, notes, and snippets.

@kam1kaze
kam1kaze / tips_and_tricks.sh
Last active May 7, 2018 08:27
troubleshooting tools
sysdig -s 2000 -A -c echo_fds proc.name=chef-client and fd.type=ipv4
chef-shell> node.run_list.expand(node.chef_environment).run_list_trace.each { |k,v| puts "#### " + k.to_s + "\n"+ v.join("\n") if v.grep(/___PATTERN___/).any? }
# Disable the stupid auto-logout (https://stackoverflow.com/questions/17397069/unset-readonly-variable-in-bash/21294582#21294582)
unset TMOUT &> /dev/null
if [[ $? -ne 0 ]]; then
comm=$(echo -e "attach $$\ncall unbind_variable(\"TMOUT\")\ndetach\nquit")
gdb="gdb -q -n"
@kam1kaze
kam1kaze / json_to_line
Last active August 29, 2015 14:19
json to one line
#!/usr/bin/env ruby
# Usage:
# cat some.json | ruby -e "$(curl -s https://gist.githubusercontent.com/kam1kaze/5002bd42e07694251c4b/raw/json_to_line)"
require 'json'
r = JSON.parse(ARGF.read)
def extract(hash, parent)
@kam1kaze
kam1kaze / shell_template.sh
Created April 28, 2015 23:43
Template for shell script with logging
set -o pipefail
set -o errtrace
set -o nounset
set -o errexit
exec 1> >(while IFS= read -r line; do echo "$(date) [DEBUG] $line"; done >>/tmp/test)
exec 2> >(while IFS= read -r line; do echo "$(date) [ERROR] $line"; done >>/tmp/test)
date
function finish {
@kam1kaze
kam1kaze / setup.sh
Created June 10, 2015 19:15
setup_ubuntu
PPA=()
PKG=()
PKG+=(
pv
mc
wget
curl
whois
vim-nox
yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
sysctl -w net.ipv4.ip_forward=1
http://wiki.hetzner.de/index.php/Netzkonfiguration_CentOS/en#Routed_.28brouter.29
http://docs.openstack.org/image-guide/content/ch_modifying_images.html
https://github.com/clauded/virt-tools/blob/master/virt-install-cloud.sh
@kam1kaze
kam1kaze / chef.sh
Last active November 10, 2015 10:43
chef
# Add item to runlist
export item='recipe[job::redis]'
knife exec -E 'nodes.find("chef_environment:staging") {|n| puts n.run_list << ENV["item"] unless n.run_list.include?(ENV["item"]); n.save }'
# Delete item from runlist
export item='recipe[job::redis]'
knife exec -E 'nodes.transform("chef_environment:staging") {|n| puts n.run_list.remove(ENV["item"]); n.save }'
# Replace item in runlist
export item_from='recipe[base::nginx]'
@kam1kaze
kam1kaze / ansible
Created March 24, 2016 19:19
ansible
Problems:
- lack of group nesting. Scope of group vision is flat due to ini format.
- problem with handling SSH host key prompts http://toroid.org/ansible-ssh-locking
@kam1kaze
kam1kaze / osx
Last active November 7, 2017 10:42
# Turn on "three finger drag"
# https://support.apple.com/en-us/HT204609
# Get back three finger tap to lookup the text
# http://notebooks.com/2015/10/05/how-to-get-back-three-finger-tap-os-x-el-capitan/
# OS X per windows language
# http://superuser.com/questions/33741/os-x-per-windows-language
### Install brew
#!/usr/bin/env bash
# Example
# find ./ -type f -iname '*.jpg' | ./fix_date '+1388 days+9 hours'
set -o pipefail
set -o nounset
set -o errexit
# time difference
#!/usr/bin/env ruby
require 'yaml'
def parse_yaml(cl, align = '')
puts align + cl
reclass_dir = '/srv/salt/reclass'
yaml_file = if cl =~ /\.yml$/
cl
elsif File.exist?(reclass_dir + '/classes/' + cl.tr('.', '/') + '/init.yml')