Skip to content

Instantly share code, notes, and snippets.

@mmmries
mmmries / lcds.rb
Created August 7, 2012 04:51
borq2
ssd_map = [
[1,1,1,0,1,1,1], #0
[0,0,1,0,0,1,0], #1
[1,0,1,1,1,0,1], #2
[1,0,1,1,0,1,1], #3
[0,1,1,1,0,1,0], #4
[1,1,0,1,0,1,1], #5
[1,1,0,1,1,1,1], #6
[1,0,1,0,0,1,0], #7
[1,1,1,1,1,1,1], #8
@mmmries
mmmries / bnr_map_point.rb
Last active December 11, 2015 12:48
Whereami sample code for my blog post.
class BNRMapPoint
attr_reader :coordinate, :title
def initialize(coordinate, title)
@coordinate, @title = coordinate, title
end
end
@mmmries
mmmries / merchant_account_spec.rb
Created April 16, 2013 17:20
How can a get good error messages about which parameters I was using when the test failed?
require 'spec_helper'
describe MerchantAccount do
it "can find an appropriate merchant" do
{
'GND130415A' => 'GRAZ_1',
'MIS130417A' => 'GRAZ_2',
'ROA130417A' => 'GRAZ_2',
'LON130417A' => 'GRAZ_3',
}.each do |tour_code, expected_merchant_account_descriptor|
@mmmries
mmmries / strict_tsv.rb
Last active December 16, 2015 16:09
Tab-separated parsing using Ruby 2.0 CSV library
# The main parse method is mostly borrowed from a tweet by @JEG2
class StrictTsv
attr_reader :filepath
def initialize(filepath)
@filepath = filepath
end
def parse
open(filepath) do |f|
headers = f.gets.strip.split("\t")
@mmmries
mmmries / line_reader.v1.rb
Last active December 17, 2015 10:48
Tab-separated Value Reader
module TSV
class LineReader
attr_reader :filepath
def initialize(filepath)
@filepath = filepath
end
def each
buffer = ""
open(filepath) do |f|
@mmmries
mmmries / request_spec.rb
Created June 13, 2013 21:14
rspec test that a request makes certain changes to a model. How can I do something like this?
describe "my request" do
it "should update the model" do
Model.any_instance.should_receive(:save) do
self.changes.should include(:attribute)
self.attribute.should == 'value'
end
xhr :put, model_path(model), {attribute: 'value'}
end
end
@mmmries
mmmries / acts_as_csv.v1.rb
Created January 16, 2014 16:46
Convenient CSV My solution for the homework assignment from the end of chapter 2 in the [Seven Languages in Seven Weeks](http://pragprog.com/book/btlang/seven-languages-in-seven-weeks) book
module ActsAsCsv
def read
@csv_contents = []
filename = self.class.to_s.downcase + '.csv'
file = File.new(filename)
@headers = file.gets.chomp.split(', ')
file.each do |row|
@csv_contents << row.chomp.split(', ')
end
@mmmries
mmmries / gist:9009549
Created February 14, 2014 21:20
rubyhop :(
$ rubyhop
/Users/michael.ries/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require': dlopen(/Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle, 9): Symbol not found: __ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_terminalE (LoadError)
Referenced from: /Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle
Expected in: flat namespace
in /Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle - /Users/michael.ries/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/gosu-0.7.50/gosu.bundle
from /Users/michael.ries/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /Users/michael.ries/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /Users/michael.ries/.rvm/gems/ruby-2.1.0/gems/gos
@mmmries
mmmries / expected_output.txt
Created February 28, 2014 19:59
TCP Server Example
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
$ ruby tmp/tcp_server.rb
Server :: client says: ping
Client :: server says: Hello! Time is 2014-02-28 12:55:54 -0700
Server :: client says: die!
Server :: farewell cruel world!
All Done!
@mmmries
mmmries / Gemfile
Last active August 29, 2015 14:00
Avro Gem Broken??? Or I don't understand it?
source "https://rubygems.org"
gem "avro", "1.7.5"