This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title></title> | |
<!-- Meta Info --> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<meta name="description" content="" /> | |
<meta name="keywords" content="" /> |
This file contains hidden or 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 HomeApp < Sinatra::Base | |
get "/" do | |
"Hello World!" | |
end | |
end | |
My::Application.routes.draw do |map| | |
match "/en", :to => HomeApp | |
end |
This file contains hidden or 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
// ========================================================================== | |
// Project: Todos.TaskDataSource | |
// Copyright: ©2010 My Company, Inc. | |
// ========================================================================== | |
/*globals Todos */ | |
/** @class | |
(Document Your Data Source Here) |
This file contains hidden or 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
Move = | |
move: (modelOrIndex, endIndex) -> | |
if typeof modelOrIndex == "number" | |
this.__moveIndexTo__(modelOrIndex, endIndex) | |
else | |
this.__moveModelTo__(modelOrIndex, endIndex) | |
__moveModelTo__: (model, endIndex) -> | |
this.__moveIndexTo__ _.indexOf(this.models, model), endIndex |
This file contains hidden or 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 'sinatra' | |
before do | |
params[:thing] = params[:thing].uppercase | |
end | |
get '/:thing' do | |
"You said '#{params[:thing]}'" | |
end |
This file contains hidden or 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 'sinatra' | |
before do | |
halt 200, {'Content-Type' => 'text/plain'}, "didnt match and it doesnt matter" | |
end | |
get '/hey' do | |
"hey!" | |
end |
This file contains hidden or 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
# This script demonstrates an issue with MongoMapper's #update_attributes!. | |
# Should call $set, but instead, just overwrites the entire doc. | |
# | |
# Script outputs: | |
# | |
# doc[:one] # => "uno" | |
# doc[:two] # => nil | |
class Doc | |
include MongoMapper::Document |
This file contains hidden or 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 Sinatra::BeforeAction | |
def before_action(&blk) | |
before { | |
# Find all the routes for the given request method | |
routes = self.class.routes[request.request_method] | |
# Find the route that matches the pattern/conditions of the | |
# request and steal the params. | |
routes.select do |pattern, keys, conditions, block| |
This file contains hidden or 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
[~/programming/sinatra]$ irb | |
ruby-1.8.7-p330 :001 > class Array; def save_map(&blk); self.instance_variable_set(:@map_blk, blk) end; def call_saved_map; self.map(&self.instance_variable_get(:@map_blk)) end end | |
=> nil | |
ruby-1.8.7-p330 :002 > a = [1,2,3] | |
=> [1, 2, 3] | |
ruby-1.8.7-p330 :003 > a.save_map {|i| i * 2 } | |
=> #<Proc:0x00000001003463a8@(irb):3> | |
ruby-1.8.7-p330 :004 > a | |
=> [1, 2, 3] | |
ruby-1.8.7-p330 :005 > a.call_saved_map |
This file contains hidden or 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 Pipe | |
DestinyNotYetChosenException = Class.new(Exception) | |
CannotWriteToReaderException = Class.new(Exception) | |
CannotReadFromWriterException = Class.new(Exception) | |
def initialize | |
@readpipe, @writepipe = IO.pipe | |
end |