Skip to content

Instantly share code, notes, and snippets.

View xunker's full-sized avatar

Matthew Nielsen xunker

View GitHub Profile
@xunker
xunker / gist:194aa382ebfd75ce14a3
Last active August 29, 2015 14:02
Ruby/Raspi ping-pong PoC code
require 'pi_piper'
include PiPiper
trigger_pin = PiPiper::Pin.new(pin: 25, direction: :out)
trigger_pin.off
sense_pin = PiPiper::Pin.new(pin: 18, direction: :in)
while true
sense = sense_pin.read
puts sense
@xunker
xunker / zipruby_test.rb
Created October 2, 2014 21:46
Compare zipruby memory consumption with others
#!/user/bin/env ruby
#
# Demonstrates memory behaviour with zipruby vs rubyzip vs exec('unzip').
# Tested with mri 1.8.7/1.9.3/2.1.2, zipruby 0.3.6 and rubyzip 1.1.6.
#
# Usage: ruby zipruby_test.rb <test method>
#
# Test methods are:
# read_zipruby read file from zip using zipruby gem
# read_rubyzip read file from zip using rubyzip gem
source ~/.git-prompt.sh
PS1="[\$(date +%H:%M:%S)]\[\033[0;37m\]\[\033[0;32m\]\w\[\033[0;37m\]\$(__git_ps1) \$ "
@xunker
xunker / gist:1679021
Created January 25, 2012 21:51
my phonegap json call functions
function apiGet(api_path, get_params, callback_function) {
console.log("apiGet: path:" + api_path + ' params:' + h2s(get_params));
$.ajax({
"type": "GET",
"dataType": "JSON",
"accepts": "JSON",
"url": api_path,
"data": get_params,
"success": callback_function,
"error": parseApiCallError
@xunker
xunker / gist:1691595
Created January 27, 2012 23:36
skip csv lines with errors
tmpfile = Tempfile.new('csv_file_with_errors')
FasterCSV.open(tmpfile.path, "r", :headers => true) do |output|
loop do
begin
break unless row = output.shift
next unless row.field_row?
# do your thing here
@xunker
xunker / gist:2481976
Created April 24, 2012 17:50
RVM Error with gemset
#!/usr/bin/env ruby
require 'rubygems'
require 'rvm'
require 'trollop'
opts = Trollop::options do
opt :ruby, "ruby interp to use", :type => :string, :required => true
opt :gem_name, "gem", :type => :string, :required => true
opt :gem_version, "gem", :type => :string, :required => true
end
@xunker
xunker / gist:3659267
Created September 6, 2012 18:32
Question about Rspec post with rocket_pants

I know you have to supply { :version => nnn } with each, but either that doesn't work with post or the post method is getting confused about which argument is the version number and which is the post payload. Didn't see anything in the docs about post(), only get() with rspec.

First, here are my routes:

api :version => 1 do
 resource :authenticate, :controller => "authenticate", :only => [ :show, :create, :update, :destroy ]
end
@xunker
xunker / gist:3709873
Created September 12, 2012 20:57
Classic RSpec vs rspec-given
#
# Classic Rspec Style
#
describe User do
before(:each) do
@user = User.new
end
describe '#last_login' do
@xunker
xunker / gist:4177581
Created November 30, 2012 18:27
The case for named arguments in Ruby
# Usage:
#
# def foo(opts = {})
# opts.require_keys!(:bar)
# puts 'yay'
# end
#
# foo()
# => MissingRequiredHashKeyError: Hash key ':bar' missing
#