Skip to content

Instantly share code, notes, and snippets.

View JoeWoodward's full-sized avatar

Joe Woodward JoeWoodward

View GitHub Profile
@trinonsense
trinonsense / sass-modules.md
Last active April 17, 2016 14:27
SASS Modules

SASS Modules

Goals

  • modularity
  • encapsulation
  • predictability
  • extensibility
  • integrability
  • explicitness
@stevenharman
stevenharman / _compose_query_objects.md
Last active December 19, 2017 21:33
Build compose-able query objects by delaying query execution and delegating to the underlying `ActiveRecord::Relation` for everything else. #ruby #rails

Compose-able Query Objects in Rails

Example usage:

old_accounts = Account.where("created_at < ?", 1.month.ago)
old_abandoned_trials = AbandonedTrialQuery.new(old_accounts)

old_abandoned_trials.find_each do |account|
 account.send_offer_for_support
@psebborn
psebborn / countCSSRules.js
Last active April 25, 2023 11:43
Count the number of rules and selectors for CSS files on the page. Flags up the >4096 threshold that confuses IE
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
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.

@erichurst
erichurst / database.yml.example mysql2
Created May 9, 2011 02:58
Rails 3 database.yml examples
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8