Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mikekelly's full-sized avatar

Mike Kelly mikekelly

View GitHub Profile
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path '.gems/bundler_gems'
# List gems to bundle here:
gem 'rails_dm_datastore'
gem 'rails', "2.3.5"
# Needed for Devise-Plugin
@mikekelly
mikekelly / jsybus_geo_data
Created October 11, 2011 08:40
Bus Stop Geo Location Data
[
"AA BOX,
49.19379,
-2.03498,
2323,
3,
1",
"AALSMEER,
49.22448,
-2.06781,
var GEO_LOCATION = {
watchID: null,
callback: null
};
GEO_LOCATION.mySpot = function(position){
var lat = (position.coords) ? new String(position.coords.latitude) : position.x;
var lon = (position.coords) ? new String(position.coords.longitude) : position.y;
return GEO_LOCATION.callback(lat, lon);
}
@mikekelly
mikekelly / install-pygtk.sh
Created December 18, 2011 12:43 — forked from ches/install-pygtk.sh
Install PyGTK via Homebrew and virtualenv
# This LOOKS pretty straightforward, but it took awhile to sort out issues with
# py2cairo and pygobject, so I hope I've saved you some time :-)
#
# This assumes you already subscribe to a nice clean virtualenvwrapper workflow
# -- see https://gist.github.com/771394 if you need advice on getting there.
# There are some optional dependencies omitted, so if you're going to be doing
# heavy development with these libs, you may want to look into them.
#
# We go to some configure option pains to avoid polluting the system-level
# Python, and `brew link`ing Cairo which is keg-only by default.

Inheritance is a key concept in most object-oriented languages, but applying it skillfully can be challenging in practice. Back in 1989, M. Sakkinen wrote a paper called Disciplined inheritance that addresses these problems and offers some useful criteria for working around them. Despite being more than two decades old, this paper is extremely relevant to the modern Ruby programmer.

Sakkinen's central point seems to be that most traditional uses of inheritance lead to poor encapsulation, bloated object contracts, and accidental namespace collisions. He provides two patterns for disciplined inheritance and suggests that by normalizing the way that we model things, we can apply these two patterns to a very wide range of scenarios. He goes on to show that code that conforms to these design rules can easily be modeled as ordinary object composition, exposing a solid alternative to tradi

@mikekelly
mikekelly / sketch.rb
Created July 4, 2012 06:36 — forked from mattwynne/sketch.rb
sketch for Matt Wynne
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
@mikekelly
mikekelly / rspec_stub_chain_if_spec.rb
Created September 27, 2012 10:50 — forked from deepak/rspec_stub_chain_if_spec.rb
mocking stub chains with an assertion if the final call is made
require 'rspec'
class DevOps
attr_reader :monitor
def initialize(arguments)
@monitor = arguments.fetch(:monitor) { Monitor.new }
end
def check
{
"_links": {
"self": {
"href": "/product/987"
},
"manufacturer": {
"href": "/manufacturer/328764",
"title": "Manufacturer Inc."
}
},
class UsersController < ApplicationController
def create
CreateUserService.new.call(
params[:user],
on_success: public_method(:create_successful),
on_failure: public_method(:create_failure)
)
end
def create_successful(user)
def create
card = current_user.credit_cards.create(card_params)
if card.persisted?
render :success
else
render :failure
end
end