Skip to content

Instantly share code, notes, and snippets.

Avatar

Hartog C. de Mik coffeeaddict

View GitHub Profile
View gist:11213880
#!/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
View battery.rb
#!/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('=')
View 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 Dec 5, 2013
Pretty print (and validate) json
View json_lint.rb
#!/usr/bin/env ruby
#
# Pretty print (and validate) json
#
# usage: curl http://localhost/api/unreadable.json | json_lint
#
# author: Hartog C. de Mik <hartog@organisedminds.com>
#
require 'json'
View pizza.txt
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
View i3status.config
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 Jun 27, 2013
Some toolbox methods for a ruote developer
View example.rb
>> 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 Mar 8, 2013
HTML 2 Markdown using a SAX Parser. (WIP)
View html2markdown.rb
# html2markdown.rb
require 'nokogiri'
module Html2Markdown
class HtmlDocument < Nokogiri::XML::SAX::Document
MAP = { "b" => "strong", "i" => "em" }
def initialize()
@list = nil
View Gemfile
# A sample Gemfile
source "https://rubygems.org"
gem "nokogiri"
@coffeeaddict
coffeeaddict / README.md
Last active Dec 11, 2015
Testing ruote participants with rspec
View README.md

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.