Skip to content

Instantly share code, notes, and snippets.

View invisiblefunnel's full-sized avatar

Danny Whalen invisiblefunnel

View GitHub Profile
@invisiblefunnel
invisiblefunnel / grab_sudoku_solutions.rb
Created October 6, 2010 21:09
Sends an unsolved sudoku puzzle to the sudokuwiki.org solver and scrapes the answer.
# Assign an unsolved sudoku to the string my_puzz. Blanks must be represented by 0's.
my_puzz = '046000000050001000203590040000000900700000300000804710020068100500000072000902000'
# cURL the sudokuwiki.org solver with the given sudoku
system 'curl -o solved.txt --url http://www.sudokuwiki.org/S/WebSudoku.dll?solutions\&0,' + my_puzz + ' >/dev/null 2>&1'
# The solved puzzle is pulled from the 6th line of the returned file.
puts File.open("solved.txt").readlines[6]
<%= f.buttons :class => 'medium-green-button' do %>
<%= f.commit_button "Save", :button_html => {:class => 'medium-green-button'} %>
<% end %>
@invisiblefunnel
invisiblefunnel / destutter.rb
Created September 28, 2011 18:35
Remove sequential duplicates recursively
def destutter list
if list.length < 2
list
else
a = list.shift
a == list[0] ?
destutter(list) :
destutter(list).unshift(a)
end
end
@invisiblefunnel
invisiblefunnel / cons_car_cdr.rb
Created September 28, 2011 22:28
Scheme's cons, car, and cdr in Ruby
# A possible implementation of
# Scheme's cons, car, and cdr in Ruby
def cons x, y
lambda do |pick|
case pick
when 1; x
when 2; y
end
end
end
@invisiblefunnel
invisiblefunnel / hacker_news_api.rb
Created October 25, 2011 17:35
Quick look at the HN front page via the ihackernews.com API
require "net/http"
require "uri"
require "json"
class Story
@@stories = []
@@endpoint = URI.parse("http://api.ihackernews.com/page")
@@fetched_at = nil
attr_accessor :title, :url, :id, :commentCount, :points, :postedAgo, :postedBy
@invisiblefunnel
invisiblefunnel / createToken.js
Created April 25, 2012 19:17
stripe.js create token
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, responseHandler);

Version 1.7.8

[~]$ mkdir temp && cd temp
[temp]$ rvm use 1.9.3@temp --create
Using /Users/dwhalen/.rvm/gems/ruby-1.9.3-p327 with gemset temp
[temp]$ gem list

*** LOCAL GEMS ***
@invisiblefunnel
invisiblefunnel / benchmarks.md
Last active December 14, 2015 03:38
Benchmarks for stripe_event

Benchmarks

This document is a basic comparison of the performance of the stripe_event gem given different Rails Controller setups. StripeEvent::WebhookController only needs the head method provided by the ActionController::Head module. This means the controller can inherit from ActionController::Metal rather than ActionController::Base if ActionController::Head is included. I'd like to have some data to support this decision.

Performance will be measured with the Apache HTTP server benchmarking tool using the unix utility ab. The ab that ships with OS X Lion seems to be broken, so I installed the version with Homebrew: brew install ab.

The benchmarks will be run on a MacBook Air with the following specs:

  • OS X Lion 10.7.5 (11G63b)
  • 1.7 GHz Intel Core i5
@invisiblefunnel
invisiblefunnel / cards.md
Last active December 14, 2015 08:29
Shuffling and dealing cards in CoffeeScript
class Card
  @ranks = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
  @suits = ['C', 'D', 'H', 'S']

  constructor: (@rank, @suit) ->
  toString: -> "#{@rank}#{@suit}"
@invisiblefunnel
invisiblefunnel / isolate_namespace_issue.md
Last active December 14, 2015 20:59
Reproduce isolate_namespace error
$ rails _3.2.12_ new test_app --skip-bundle --quiet && cd test_app
$ curl -o Gemfile https://gist.github.com/marcamillion/b34999069f88190017d3/raw/d2dea64f72ac1b09a11b70295e970aeaea5e8f74/Gemfile.rb
$ bundle --quiet
$ ruby -r./config/environment.rb -e "puts method(:singleton_class).source_location"
/Users/dwhalen/.rvm/gems/ruby-1.9.3-p392/gems/serel-1.1.1/lib/serel/exts.rb
17
$ cat >> Gemfile

gem 'sextant', :group =&gt; :development