Skip to content

Instantly share code, notes, and snippets.

Verifying that +ashmoran is my blockchain ID. https://onename.com/ashmoran
@ashmoran
ashmoran / fisherman_registrar_server_resource.rb
Created September 22, 2014 17:06
One of the Webmachine resources in the (unfinished, unpublished) Harvest code that handles signup. service.sign_up_fisherman() is async and returns a Result object, result.on() blocks until an appropriate response message is heard.
require 'json'
module Harvest
module HTTP
module Server
module Resources
class FishermanRegistrarServerResource < Resource
def initialize
@exception_error_code = nil
end
@ashmoran
ashmoran / bitcoin_address_demo.rb
Created November 21, 2013 14:05
Demo of generating a Bitcoin address in Ruby (not production quality code!)
require 'bitcoin'
def hex_string_to_bytes(string)
[string].pack("H*")
end
def bytes_to_hex_string(bytes)
bytes.unpack("H*").first
end
@ashmoran
ashmoran / nil_check_bytecode.rb
Created November 8, 2013 16:02
Disassembled YARV versions of various nil checks in Ruby 2
[
"true unless nil.nil?",
"true if nil != nil",
"true if !!nil",
"true unless nil"
].each do |source|
puts "====="
puts source
puts
@ashmoran
ashmoran / header_row_of_doom.rb
Created October 11, 2013 14:40
Hideous first iteration of an algorithm I wrote
def header_rows(labeller = Labeller.new)
# This won't handle mismatched sizes yet
# Also hack the null case for now
number_of_rows = @fragments.map(&:number_of_dimensions).max || 0
bottom_up_header_rows = [ ]
number_of_rows.times do |row_index|
current_row = bottom_up_header_rows[row_index] = [ ]
@ashmoran
ashmoran / fisherman_registrar_server_resource.rb
Last active December 21, 2015 06:49
FishermanRegistrarServerResource: an example Webmachine resource for my Realm application Harvest
require 'json'
module Harvest
module HTTP
module Server
module Resources
class FishermanRegistrarServerResource < Resource
def trace?
true
end
@ashmoran
ashmoran / harvest.term
Created August 6, 2013 13:28
Example project configuration for Consular ( https://github.com/achiu/consular )
#!/usr/bin/env ruby
window do
setup do
unless ENV['HARVEST_PATH']
puts "You must set the HARVEST_PATH environment variable to your local harvest repo path"
end
end
before do
@ashmoran
ashmoran / have_uncommitted_events_matcher.rb
Last active December 19, 2015 18:39
RSpec matchers: have_uncommitted_events / have_no_uncommitted_events
RSpec::Matchers.define :have_uncommitted_events do |*expected_events|
match do |aggregate_root|
expected_events.all? { |expected_event|
aggregate_root.uncommitted_events.detect { |event|
event.matches?(expected_event)
}
}
end
end
@ashmoran
ashmoran / recursive_ostruct.rb
Created July 8, 2013 16:30
Recursive Hash/Array -> OpenStruct
def recursive_ostruct(object)
case object
when Hash
hash = {}; object.each{|k,v| hash[k] = recursive_ostruct(v)}
OpenStruct.new(hash)
when Array
object.map {|e| recursive_ostruct(e) }
else
object
end
@ashmoran
ashmoran / shell.out
Created July 3, 2013 10:54
Clusterfuck failure trying to install the Node dependencies of GroundworkCSS 1.11.1 with npm https://github.com/groundworkcss/groundwork/tree/1.11.1
╭─ashmoran – MBP-404:groundwork – git:(bf3aadb)✔ – ‹2.0.0-p195› – 0
╰─% npm install --dev
npm http GET https://registry.npmjs.org/grunt-contrib-watch
npm http GET https://registry.npmjs.org/grunt-contrib-concat
npm http GET https://registry.npmjs.org/grunt-contrib-sass
npm http GET https://registry.npmjs.org/grunt-contrib-jade
npm http GET https://registry.npmjs.org/grunt
npm http GET https://registry.npmjs.org/grunt-contrib-coffee
npm http GET https://registry.npmjs.org/grunt-contrib-compass
npm http 304 https://registry.npmjs.org/grunt-contrib-sass