Skip to content

Instantly share code, notes, and snippets.

View mikekelly's full-sized avatar

Mike Kelly mikekelly

View GitHub Profile
@mikekelly
mikekelly / Backbone-HAL.js.coffee
Created May 28, 2012 11:19
Two small components for making Backbone play nicely with application/hal+json
window.HAL = {}
class HAL.Model extends Backbone.Model
constructor: (attrs) ->
super @parse(_.clone attrs)
parse: (attrs = {}) ->
@links = attrs._links || {}
delete attrs._links
@embedded = attrs._embedded || {}

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

{
"_links": {
"self": { "href": "/orders/123" },
"shipment-type": { "href": "http://api.company.com/logistics/shipmenttypes/2" },
"warehouse": { "href": "http://api.company.com/logistics/warehouses/7449?Country=Australia" },
"products": [{
"href": "http://api.company.com/master/products/87",
"title": "Shirt"
},{
"href": "http://api.company.com/master/products/122",
<resource href="/">
<link rel="events" href="...">
</resource>
<control action="submit-completed-task" href="http://api.email-service.com/messages" method="POST" content-type="application/xml" >
<email>
<message>Tremendous. You finished {{task.name}}</message>
<sender>you@example.com</sender>
<recipient>you@example.com</recipient>
</email>
</control>
{
"_links": {
"self": { "href": "..." },
"productions": { "href": "..." }
}
}
class DashboardController < ResourceController
def get
# show dashboard
end
end
@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.
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 / resource-state.hal.json
Created November 25, 2011 11:10
Example of resource state
{
"name": "A product",
"weight": 400,
"dimensions": {
"width": 100,
"height": 10,
"depth": 100
},
"description": "A great product"
}