Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Kelly mikekelly

View GitHub Profile
@mikekelly
mikekelly / example.rb
Last active Aug 29, 2015
Greppable, prefixed delegation
View example.rb
# un-greppable delegate API
class Foo
delegate :qux, to: :bar, prefix: true
end
# possible fixes to the API to make it greppable
class Foo
delegate :bar_qux, to: :bar, prefixed: true
View gist:a7ce2ed97a291917daef
def create
card = current_user.credit_cards.create(card_params)
if card.persisted?
render :success
else
render :failure
end
end
View orders.json
{
"links":{
"self":"/orders",
"link-docs":[
{
"name":"v1",
"href":"http://api.example.com/docs/v1/{link}",
"templated":true
}
],
View gist:232891
dir structure:
/lib/
/tmp/
/views/
/public/
/config.ru
/blog.rb
--
View nodular_ponderings.js
/*
I want to be able to build a DSL for node.js so that I can define app routes for an HTTP interface like this:
*/
{
"/blog" : {
GET: function(request) {
// List blog posts
},
View gist:369466
#(entry point)
> GET /
< 200 OK
< Link: </lists/some-list>; rel="http://example.com/rels/list",
< </foobars/another-list>; rel="http://example.com/rels/list"
< {...}
<html>
<head>
View hal-list.xml
(GET /list)
<link rel="self" href="/list">
<link rel="description" href="/list/description" />
<link rel="search" href="/list/search/{search_term}" />
<created_at>2010-01-16</created_at>
<updated_at>2010-02-21</updated_at>
<summary>An example list</summary>
<link rel="owner" href="/people/mike">
<name>Mike</name>
View Gemfile
# 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
View jotting ideas.js
// (/app/resources/useraccount.js)
Resource({
respond_to: ["html", "xml", "json"],
http: {
GET: function() {
user = User.find(params.user);
respond_with(user);
},
PUT: function() {
View list.xml
<resource rel="self" href="/list">
<resource rel="description" href="/list/description" />
<resource rel="search" href="/list/search/{search_term}" />
<created_at>2010-01-16</created_at>
<updated_at>2010-02-21</updated_at>
<summary>An example list</summary>
<resource rel="owner" href="/people/mike">
<name>Mike</name>
<age>36</age>
</resource>