Skip to content

Instantly share code, notes, and snippets.

@creisor
creisor / simple_http_server.rb
Created April 30, 2014 16:33
simple_ruby_web_server
#!/usr/bin/env ruby
# simplest possible web server
# client example:
# curl -X POST -H "Content-type: application/json" -d '{"yomama":"sofat"}' http://localhost:8080 && echo
require 'webrick'
class EchoServlet < WEBrick::HTTPServlet::AbstractServlet
def do_POST(request, response)
@creisor
creisor / capture_stderr.rb
Created February 10, 2016 12:02
Capture stderr in specs
# When you using rspec for commandline tools, and you want to capture stderr in a test,
# this method allows you to do it.
# It could also be adapted to stdout.
#
# Use like:
# stderr = capture_stderr do
# expect{ MyClass.new(arg1, arg2).to raise_error(SystemExit, "my abort message here")
# end
#
# Then you can make expectations based on the variable stderr
@creisor
creisor / swap.sh
Created April 18, 2016 17:24
Shows the swap usage of each process
#!/bin/bash
#
# swap.sh: Shows the swap usage of each process
# Author: Robert Love
swap_total=0
for i in /proc/[0-9]*; do
pid=$(echo $i | sed -e 's/\/proc\///g')
swap_pid=$(cat /proc/$pid/smaps |
awk 'BEGIN{total=0}/^Swap:/{total+=$2}END{print total}')
@creisor
creisor / Gemfile
Created April 26, 2016 22:41
Typhoeus webhook simulator
source 'https://rubygems.org'
gem "typhoeus", '0.6.9'
@creisor
creisor / basic_ansible.yml
Created June 9, 2016 14:54
Most basic ansible playbook for testing stuff
# run with: ansible-playbook -i 'localhost,' -c local -e 'ROLE=docker-host' test.yml
---
- hosts: all
gather_facts: False
tasks:
- name: Set env var
set_fact:
roles: "{{ROLE}}"
- name: Debug
@creisor
creisor / bunpacker.rb
Created April 26, 2016 22:38
Hookshot log unpacker for pulling useful data
#!/usr/bin/env ruby
require ::File.expand_path("../../config/load", __FILE__)
require 'active_support/core_ext/object/blank'
filename = ARGV[0]
if filename.present?
log = Hookshot::Log.decode(File.read(filename))
if log['hook_response'].eql?('Invalid HTTP Response: 0')
@creisor
creisor / .screenrc
Created March 3, 2017 12:18
My screenrc
#se: Setup file for program "(GNU) screen"
# written by: Sven Guckes <guckes-screen@math.fu-berlin.de>
# Latest change: Mon May 19 01:11:11 CEST 2003
# Latest user version: screen-3.9.15 [2003-03-13]
# Length and size: 678 lines and ca 24KB
# ===============================================================
#
# ===============================================================
# SEE ALSO:
@creisor
creisor / macos_bash_reminder.sh
Created May 8, 2017 20:36
A function for popping up a dialog at you
function reminder() {
# reminder 5 "remove tea bag"
seconds=$(($1 * 60))
sleep $seconds && osascript -e "tell app \"System Events\" to display dialog \"$2\"" 2>&1 > /dev/null
}
@creisor
creisor / playbook_inception.yml
Created February 15, 2019 22:44
This is how you run a playbook within a playbook, and only register change when the "inner playbook" registers a change.
- name: Run AWX Installer
local_action: "command ansible-playbook -i awx_repo/installer/inventory awx_repo/installer/install.yml --limit \"{{ ansible_limit }}\""
become: no
tags:
- awx_deploy
- awx-deploy
- deploy
- install
register: awx_installer_output
changed_when: ((awx_installer_output.stdout_lines[-1] | regex_search('changed=(\\d+)', '\\1'))[0] | int) > 0
@creisor
creisor / just-tell-me-how-to-use-go-modules.md
Last active November 22, 2019 15:57
just-tell-me-how-to-use-go-modules - one of the most useful blog posts rescued from 404 obliteration

JUST TELL ME HOW TO USE GO MODULES

This was not written by me. It was very useful and then one day I got a 404, so I dug it up from the wayback machine: https://web.archive.org/web/20190425012016/http://www.kablamo.com.au/blog/2018/12/10/just-tell-me-how-to-use-go-modules


I recently started using Go’s new inbuilt vendoring tool, Go Modules, and having come from both govendor and dep, this new tool was more of a change than I expected.

I’m a fan of quick guides – just tell me what to do so I can start using it now. I don’t need an essay on why I should be using it or painful detail on the tool’s inner workings.