Skip to content

Instantly share code, notes, and snippets.

@nbryan
nbryan / differ.sh
Created March 19, 2018 17:11
Check for changes in a file
#!/bin/bash
# chmod +x differ.sh before running
curl https://projects.fivethirtyeight.com/trump-approval-data/approval_topline.csv > new_data.csv
diff old_data.csv new_data.csv
mv new_data.csv old_data.csv

Keybase proof

I hereby claim:

  • I am nbryan on github.
  • I am nbryan (https://keybase.io/nbryan) on keybase.
  • I have a public key whose fingerprint is C61B 6098 3569 2879 A629 008B 28A4 F548 73BB 2260

To claim this, I am signing this object:

@nbryan
nbryan / when.coffee
Created April 22, 2013 23:32
This is in CoffeeScript rather than JavaScript, but hopefully it should be clear. In our app we typically have to load multiple things before rendering a page. Using jQuery's Deferred objects the pattern is very simple. This is probably the most basic example we use. I've got some more interesting cases as well, such as fetching many records in …
# With deferred objects
$.when(loadSomething1(), loadSomething2(), loadSomethingElse())
.done(-> renderPage())
.fail(-> renderFailure())
# With callbacks, can't operate in parallel, error cases repeated
loadSomething1(
success: loadSomething2(
success: loadSomethingElse(
success: renderPage(),
@nbryan
nbryan / nominate.rb
Created November 21, 2011 19:35
Nominate Adaptly for some useless TechCrunch Crunchie awards
#!/bin/ruby
require 'net/http'
require 'uri'
values = {
"form_1" => "Adaptly", # Best Technology Achievement
"form_17" => "Nikhil Sethi and Garrett Ullom (Adaptly)", # Founder of the Year
"form_18" => "Nikhil Sethi (Adaptly)", # CEO of the Year
"form_20" => "Adaptly" # Best Overall Startup of 2011
# Factory Girl doesn't traverse down directories, make sure these factories get loaded.
Dir[File.join(File.dirname(__FILE__), 'factories', '**/*.rb')].each {|file| require file}
class Person
def self.section(str, &blk)
self.class_eval(&blk)
end
end
class Joe < Person
def name; "Joe"; end
20) Error:
test: A user sentinel instance should know when it's destroyable. (UserSentinelTest):
NoMethodError: undefined method `user_credentials' for #<UserMailer:0x103532060>
app/observers/user_observer.rb:3:in `after_create'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/observer.rb:185:in `notify_observers'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/observer.rb:184:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/observer.rb:184:in `notify_observers'
vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/proxy/create.rb:5:in `result'
vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb:293:in `run'
vendor/gems/thoughtbot-factory_girl-1.2.1/lib/factory_girl/factory.rb:237:in `create'
require "mathn"
number, primes, factors = 600851475143, Prime.instance, []
for i in primes
if number % i == 0
factors << i
number = number / i
redo
elsif i > Math.sqrt(number)