Skip to content

Instantly share code, notes, and snippets.

View davekonopka's full-sized avatar
🔊

Dave Konopka davekonopka

🔊
View GitHub Profile

Philadelphia Emerging Technologies for the Enterprise conference, April 2010

Day 1

Keynote - Bad Code, Craftsmanship, Engineering, and Certification, Bob Martin

  • The only way to go fast is to go well.
  • Keep functions as short, single function as possible
  • Function is small enough when it can't get any smaller
  • Keep argument collection small
@davekonopka
davekonopka / description.markdown
Created September 29, 2011 20:49 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@davekonopka
davekonopka / Rakefile.rb
Last active June 22, 2016 04:42
WWW Rake file
namespace :site do
desc "Middleman build"
task :build do
puts "Building site..."
puts `bundle exec middleman build --verbose`
end
desc "Build, deploy, bust cache"
task :deploy => ["site:build", "s3:deploy", "fastly:bust_cache"]
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
module Kernel
alias :__at_exit :at_exit
def at_exit(&block)
__at_exit do
exit_status = $!.status if $!.is_a?(SystemExit)
block.call
exit exit_status if exit_status
end
end
@davekonopka
davekonopka / teamcity_rspec_order.sh
Created March 23, 2013 02:50
TeamCity RSpec Order
echo "##teamcity[setParameter name='env.SEED_NUMBER' value='$(git rev-parse HEAD | tr -d 'a-z' | cut -b 1-5)']"
echo "To replicate the order on your machine:"
echo "rake spec SPEC_OPTS=\"--order random:$(git rev-parse HEAD | tr -d 'a-z' | cut -b 1-5)\""
[18:48:01][Step 3/6] To replicate the order on your machine:
[18:48:01][Step 3/6] rake spec SPEC_OPTS=“–order random:84847”
input = "If you are self-motivated, wow, this world is tailored for you. The boundaries are all gone. But if you're not self-motivated, this world will be a challenge because the walls, ceilings and floors that protected people are also disappearing. That is what I mean when I say \"it is a 401(k) world.\" Government will do less for you. Companies will do less for you. Unions can do less for you. There will be fewer limits, but also fewer guarantees. Your specific contribution will define your specific benefits much more. Just showing up will not cut it. - T. Friedman".downcase
pair = "ou"
third = "r"
pairs = (0..input.length-2).inject({}) do |h,i|
key, val = input[i,2], input[i + 2]
h[key] = {} unless h[key]
h[key][val] = (h[key][val] || 0) + 1 if val
h
end
@davekonopka
davekonopka / pew-pew-pew.json
Created September 14, 2015 17:03
JSON or Missile Command?
]
]
}
]
}
]
}
}
]
}
@davekonopka
davekonopka / 0_reuse_code.js
Created May 2, 2016 15:14
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