Skip to content

Instantly share code, notes, and snippets.

View xunker's full-sized avatar

Matthew Nielsen xunker

View GitHub Profile
@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
#
@xunker
xunker / borg.rb
Last active December 17, 2015 23:09
borg.rb - an office productivity enhancer for Mac OS only.
voices = %w[Agnes Alex Bruce Bubbles Fred Junior Kathy Princess Ralph Vicki Victoria]
phrases = [
"We are the Borg.",
"Lower your shields and surrender your ships.",
"We will add your biological and technological distinctiveness to our own.",
"Your culture will adapt to service us.",
"Resistance is futile."
]
@xunker
xunker / first.rb
Created July 5, 2013 17:03
Opal router attempts
require 'opal'
require 'jquery'
require 'opal-jquery'
require 'erb'
require 'vienna'
require 'views/app_view'
require 'views/todo_view'
require 'templates/footer'
@xunker
xunker / JSON Parser module code
Last active December 31, 2015 18:22
knktr: Github webhook functions
JSON = (function()
-- -*- coding: utf-8 -*-
--
-- Simple JSON encoding and decoding in pure Lua.
--
-- Copyright 2010-2013 Jeffrey Friedl
-- http://regex.info/blog/
--
-- Latest version: http://regex.info/blog/lua/json
--