Skip to content

Instantly share code, notes, and snippets.

View dpickett's full-sized avatar

Dan Pickett dpickett

View GitHub Profile
@dpickett
dpickett / player_pseudo.js
Last active August 29, 2015 14:03
players
function KeyHandler(){
//handy underscoreJS function
_.bindAll(this, 'handleUpKey', 'handleKey');
this.handleUp = function(e){
//we can use jQuery to trigger events on plain ol' JavaScript objects
$(this).trigger('up');
}
this.handleKey = function(e){
@dpickett
dpickett / migration.rb
Last active August 29, 2015 14:01
contrived migration
class UpdatePosts < ActiveRecord::Migration
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
def change

Guess The Number

In this assignment you'll create a simple guessing game using some of the Ruby fundamentals you've learned.

Learning Goals

  • Create and run a simple Ruby program.
  • Extract requirements from the given user stories.
  • Utilize Ruby's looping constructs.
  • Read user input from the command-line.
@dpickett
dpickett / 0_reuse_code.js
Created December 30, 2013 15:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dpickett
dpickett / create_planet_destruction_event_spec.rb
Last active December 17, 2015 21:49
Actual integration spec from a live coding session at Launch Academy. No planets were harmed in the fulfillment of this acceptance criteria.
require 'spec_helper'
describe 'creating a planet destruction event' do
# As a grand moff of mass destruction
# I want to record planet destruction events
# So that I can demonstrate imperial awesomeness
# Acceptance Criteria
# * I must specify a planet name, star system, casualty count,
# and description
#propagates association validations to their foreign keys
#rails makes bad assumptions about forms and foreign key validations, so validate the proper way,
#but allow for the ability to propagate validation errors to foreign keys
module ValidatesAssociatedWith
extend ActiveSupport::Concern
included do
class_attribute :associations_validated
self.associations_validated = []
before_validation :flush_propagated_association_errors
@dpickett
dpickett / subdomain_helper.rb
Created February 6, 2013 02:11
subdomain handling
module PartnerSpecHelper
def with_partner_site_for(partner, &block)
old_host = Capybara.default_host.dup
old_app_host = Capybara.app_host.try(:dup)
host = "#{partner.subdomain}.example.com"
Capybara.default_host = "http://#{host}"
set_host!(host)
#Capybara.app_host = "http://#{partner.subdomain}.example.com:7171" if Capybara.current_driver == :webkit
@dpickett
dpickett / timestamp_fix.rb
Created September 27, 2012 16:18
timestamp_fix.rb
class FixTimestamps < ActiveRecord::Migration
def up
Dir.glob(Rails.root.join("app/models/**/*.rb")) do |f|
require f
end
ActiveRecord::Base.send(:subclasses).each do |klass|
[
"created_at",
"updated_at"
@dpickett
dpickett / resque_spec_helpers.rb
Created September 26, 2012 20:55
resque spec helpers
module ClassMethods
def run_all_with_inline_worker
before(:all) do
Resque.inline = true
end
after(:all) do
Resque.inline = false
end
end
@dpickett
dpickett / rewrite.rb
Created March 30, 2012 23:21
rewrite
run lambda do |env|
req = Rack::Request.new(env)
Rewrite.find_each do |rewrite|
if request.path =~ Regexp.new(rewrite.source)
return [301, {'Content-Type'=>'text/html', 'Location'=>"#{rewrite.destination}"}, ['Redirecting...']]
end
end
super
end