Skip to content

Instantly share code, notes, and snippets.

@creisor
creisor / add_users.yml
Created May 5, 2017 15:11
Ansible tasks for adding users to hosts, and adding their authorized keys to other users so they can login as those users
---
- name: add users
user:
name: "{{ item.name }}"
state: present
groups: "{{ item.groups }}"
shell: /bin/bash
with_items: "{{ users }}"
- name: add authorized keys
@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 / Vagrantfile
Created February 27, 2017 18:52
Vagrant file for installing ruby with rbenv
# -*- mode: ruby -*-
# vi: set ft=ruby :
RUBY_V = File.open("./.ruby-version") { |f| f.read }.chomp
$apt_script = <<SCRIPT
sudo apt-get update
sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev libmysqlclient-dev
SCRIPT
@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 / Gemfile
Created April 26, 2016 22:41
Typhoeus webhook simulator
source 'https://rubygems.org'
gem "typhoeus", '0.6.9'
@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 / 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 / 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 / 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)