Skip to content

Instantly share code, notes, and snippets.

View coffeeaddict's full-sized avatar

Hartog C. de Mik coffeeaddict

View GitHub Profile
#!/usr/bin/env ruby
require 'open3'
begin
stdout, status = Open3.capture2("git status -uno --porcelain")
rescue Errno::ENOENT
abort "Cannot run `git status -uno --porcelain`."
end
@coffeeaddict
coffeeaddict / battery.rb
Created April 16, 2014 07:33
Battery stats
#!/usr/bin/env ruby
#
# Read battery event file and return some numbers
require 'json'
stats = {}
File.open("/sys/class/power_supply/BAT1/uevent", File::RDONLY) do |f|
while(line = f.gets)
(key, value) = line.chomp.split('=')
@coffeeaddict
coffeeaddict / unicorns.cap
Last active December 30, 2015 20:09
unicorns.cap
namespace :unicorns do
def unicorn_command
fetch(:unicorn_command, File.join(shared_path, "bin/unicorn_rails"))
end
def unicorn_pid_file
fetch(:unicorn_pid_file, "/path/to/unicorn.pid")
end
def unicorn_config_file
@coffeeaddict
coffeeaddict / json_lint.rb
Created December 5, 2013 11:42
Pretty print (and validate) json
#!/usr/bin/env ruby
#
# Pretty print (and validate) json
#
# usage: curl http://localhost/api/unreadable.json | json_lint
#
# author: Hartog C. de Mik <[email protected]>
#
require 'json'
@coffeeaddict
coffeeaddict / pizza.txt
Last active December 24, 2015 01:49
Pizza
In de schotel van je roerijzer
300gr meel
met 312ml water
en 1/4 blokje hefe
door roeren tot klontjesvrij en 20 minuten laten staan
meer als 5 en minder als 10 gram zout toevoegen
3-4 minuten roeren/kneden
beetje bij beetje 200gr meel toevoegen
en maar kneden
general {
colors = true
interval = 5
}
order += "ipv6"
order += "disk /"
order += "run_watch DHCP"
order += "run_watch VPN"
order += "wireless eth2"
@coffeeaddict
coffeeaddict / example.rb
Created June 27, 2013 06:42
Some toolbox methods for a ruote developer
>> pdef = <<EOPDEF
define comms_and_hackers
sequence flank: true
start_prism
concurrence
cursor rewind_unless: '${f:conversation_done}'
alice
bob
cursor rewind_unless: '${f:cipher_broken_or_conversation_done}'
@coffeeaddict
coffeeaddict / html2markdown.rb
Created March 8, 2013 08:32
HTML 2 Markdown using a SAX Parser. (WIP)
# html2markdown.rb
require 'nokogiri'
module Html2Markdown
class HtmlDocument < Nokogiri::XML::SAX::Document
MAP = { "b" => "strong", "i" => "em" }
def initialize()
@list = nil
@coffeeaddict
coffeeaddict / Gemfile
Last active December 12, 2015 09:49
manifesto
# A sample Gemfile
source "https://rubygems.org"
gem "nokogiri"
@coffeeaddict
coffeeaddict / README.md
Last active December 11, 2015 04:39
Testing ruote participants with rspec

Testing participants

Introduction

Testing a participant is gory-detail-stuff. You must know a lot about the internals of Ruote. Because; In order to 'test' a participant, we have to mimic the environment the participant lives and is executed in.

Setup

Since we are isolating the participant in our experiment^W... tests we have to prevent the participant from communicating with Ruote. In order to do so we have replace the #reply function with an own singleton.