This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; example rails like console for compojure showing params, etc. for each request | |
(ns bus.core | |
(:use compojure.core | |
ring.adapter.jetty | |
... | |
... | |
(:use ring.middleware.params)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Original here http://www.poetryfoundation.org/poem/171612) | |
Did I ever tell you that Programmer McCave | |
Had twenty-three variables and he named them all `a` | |
Well, he did. And that wasn't a smart thing to do. | |
You see, when he wants wants to add `a` to 2 | |
He doesn't get a number oh no no no | |
All twenty-three `a`s cause a buffer overflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Given an array of numbers i.e. [1,2,3...1000], find out all possible combinations that add up to any given number i.e. 51437 | |
#start with empty db | |
# start with 1st transaction -> write {key = 1, value => 1 } | |
# for the second transaction write { key => 1.2 => value => 3 } | |
# { key = 2, value => 3 } | |
# for the third transaction write { key => 1.2.3 => value => 6 } | |
# { key = 1.3, value => 4 } | |
# { key = 2.3, value => 5 } | |
# { key = 3, value => 3 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assuming your execute command is more complex than a simple puts, | |
# you will need separate classes | |
class GoodbyeCommand | |
def execute | |
# complex logic here | |
end | |
end | |
class TwitterCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GamesController | |
class Index < ControllerAction | |
def get | |
[200, {}, Game.all.to_json] | |
end | |
def params | |
super.except(:deleted_at) # no need for strong_params. specify what goes and what doesn't by overriding the params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FoosController | |
class Index < ControllerAction | |
def get | |
@foos = Foo.all | |
succeed_with(FooPresenter.new(@foos).to(format)) # if you want more control over presentation, hand off to the presenter | |
end | |
end # Index | |
class Create < ControllerAction | |
def post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FoosController < ApplicationController | |
def index | |
### | |
end | |
def show | |
### | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/core_ext/string/inflections' | |
class Router | |
attr_reader :env, :route | |
def initialize(routes, env) | |
@env = env | |
@routes = routes | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChessApp | |
def self.routes | |
@routes ||= ActionDispatch::Routing::RouteSet.new.tap do |r| | |
r.draw do | |
resources :games, :only => [:index, :create, :show, :update] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@routes ||= ActionDispatch::Routing::RouteSet.new.tap do |r| | |
r.draw do | |
resources :games, :only => [:index, :create, :show, :update] | |
end | |
end | |
@routes.recognize_path("/games", {:method => 'GET'}) # => {:action => "index", :controller => "games"} |
NewerOlder