Skip to content

Instantly share code, notes, and snippets.

View mbleigh's full-sized avatar

Michael Bleigh mbleigh

View GitHub Profile
# Let's say we have this:
class User < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :user
end
Some Definitions
================
BDD: Behavior Driven Development
TDD, but focusing on how the application behaves instead of code structure.
CDD: Conference Driven Development
Proposing talks for libraries and code that isn't written yet, then using said
talk's acceptance as an impetus to actually write the code.
PDD: Plane Driven Development
Hacking together a small project entirely while in the air.
class SoundWalk < ActiveRecord::Base
belongs_to :user
named_scope :from_users, lambda{ |users| {:conditions => ["user_id IN (?)", users.collect{|u| u.id}]} }
end
class User < ActiveRecord::Base
def friend_soundwalks
SoundWalk.from_users(self.friends)
end
# Just kidding!
teams.voteable.each do |team|
if team == my_team
team.vote!(5,5,5,5)
else
team.vote!(rs,rs,rs,rs)
end
end
def rs
require 'fakeweb'
FakeWeb.allow_net_connect = false
class SomethingThatUsesNetHTTP
def self.some_http_method
# => does hidden-away HTTP stuff
end
end
# Once you've included your Jeweler tasks and your Jeweler::Gemcutter tasks...
namespace :release do
%w(patch minor major).each do |level|
desc "Tag a #{level} version and push it to Gemcutter."
task level.to_sym => ["version:bump:#{level}", "release", "gemcutter:release"]
end
end
# Now, to tag a new version, push it to GitHub and release your project on Gemcutter, you just have to do:
module Rack
class Pictopus
def initialize(app, output_path)
@app = app
@root = ::File.expand_path(output_path)
raise ArgumentError, "#{output_path} is not a directory." unless ::File.directory?(@root)
end
def call(env)
unless env["PATH_INFO"] =~ /.*\/images\/pictopus\/.*\/.*/

CSS3 for SASS

This is a simple SASS file that provides a number of useful mixins to achieve CSS3 effects cross-browser. For each rule, the styles are implemented for as many browsers as possible.

Note: You must use haml >= 3.0 for this to work as it uses the dollar assignment operator and equals-less assignment. This may mean installing the --pre version of HAML until its official release.

Box Effects

Rounded Corners

Feature: 3.5.2.1 - Client Requests Authorization
In order for the end user to grant the client access, the client
sends the end user to the authorization server.
Background:
Given a registered client "desktop" with id "abc" and secret "def"
And a user named "bob" with password "example"
And a request path of "/oauth/authorize"
And a "type" parameter of "web_server"
And a "client_id" parameter of "abc"
// generated by npm, please don't touch!
var i = require.paths.indexOf(__dirname)
if (i && i + 1) require.paths.splice(i, 1)
if (i) require.paths.shift(__dirname)
exports["express"] = require('./'+"express")
,exports["oauth"] = require('./'+"oauth")
,exports["ejs"] = require('./'+"ejs")