Skip to content

Instantly share code, notes, and snippets.

View daveworth's full-sized avatar
🔬
Science!

David E Worth daveworth

🔬
Science!
View GitHub Profile
### Keybase proof
I hereby claim:
* I am daveworth on github.
* I am dworth (https://keybase.io/dworth) on keybase.
* I have a public key ASAFs93Uo_d2oN4aKnPp2P_rEGyNRYpUntFfM1wpS170nAo
To claim this, I am signing this object:

Context: CodeAcademy asked for code like:

var = gets.chomp
var2 = var1.capitalize
var.capitalize!

#...
@daveworth
daveworth / 1_continuations.rb
Created February 5, 2014 20:59
fun with continuations and a puzzler
def square_with_continuation(x, continuation = ->(x) { x })
continuation.call(x*x)
end
@daveworth
daveworth / lambda_and_proc_assertions_spec.rb
Created November 19, 2013 00:35
hoping to help a friend debug what method exactly is called on a proc/lambda when passed to an enumerator..
require 'spec_helper'
describe "First Class Objects are Weird" do
let(:a_lambda) { lambda { |p| puts ["Lambda", p].join(" ") } }
let(:a_proc) { proc { |p| puts ["Proc", p].join(" ") } }
context "wat" do
pending "totally does not work" do
foo = double # was hoping to find out what method was called on this double... it doesn't work
%w(a).each &foo
@daveworth
daveworth / github SSH behavior if you have two different SSH keys!
Created January 20, 2013 14:20
If you have two different SSH keys that GitHub knows about make sure you add yours first if you want your commits to have your name associated with commits! In the below situation I have my ssh key that GitHub knows about and another users in `deploy_id_rsa` which is used for deploying code to production servers and allows any changes made to ch…
$ ssh-add -D
All identities removed.
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /Users/dworth/.ssh/id_rsa:
Identity added: /Users/dworth/.ssh/id_rsa (/Users/dworth/.ssh/id_rsa)
$ ssh -T git@github.com
Hi daveworth! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh-add ~/.ssh/deploy_id_rsa
Identity added: /Users/dworth/.ssh/deploy_id_rsa (/Users/dworth/.ssh/deploy_id_rsa)
class WidgetDecorator::Base < ApplicationDecorator
def display_title
""
end
end
class WidgetDecorator < WidgetDecorator::Base
decorates :widget
def display_title
#...
@daveworth
daveworth / flog_examples.txt
Created September 12, 2012 02:21
Static Analysis Tools Examples
# running flog on an intentionally broken rails app
badapp $ bundle exec flog -g app
76.9: flog total
7.7: flog/method average
20.2: UsersHelper total
20.2: UsersHelper#dynamic_attribute_finder? app/helpers/users_helper.rb:2
18.9: UsersController total
10.4: UsersController#none
@daveworth
daveworth / dstr_sexp.rb
Created September 7, 2012 13:37
Fibonacci in ...
sexp = RubyParser.new.process(ruby)
find_dstrs(sexp)
# produces
[s(:dstr, "foo bar ", s(:evstr, s(:lvar, :baz)), s(:str, " qux"))]
@daveworth
daveworth / gist:3274711
Created August 6, 2012 14:15
reflecticle Alfred extension doh...
$ vim ~/.reflecticle
$ cat ~/.reflecticle
d669464d57d4242b74c7c7f45725b5c1b9e4f35d
$ rspec
....
Finished in 0.03198 seconds
4 examples, 0 failures
$ cat ~/.reflecticle
key
@daveworth
daveworth / thingy.rb
Created July 31, 2012 19:44
Squeel audit components
class Thingy < ActiveRecord::Base
attr_accessible :name, :inty
scope :name_eql_sqli, lambda { |param| where("name = #{param}") }
scope :name_eql_no_sqli, lambda { |param| where("name = ?", param) }
scope :name_eql_squeeli, lambda { |param| where{name == param} }
scope :inty_eql_squeeli, lambda { |param| where{inty == param} }
scope :name_like_sqli, lambda { |param| where("name LIKE '%#{param}%'") }