Skip to content

Instantly share code, notes, and snippets.

View iamjwc's full-sized avatar

Justin Camerer iamjwc

  • LimeWire, LLC
  • New York City
View GitHub Profile
<!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="" />
class HomeApp < Sinatra::Base
get "/" do
"Hello World!"
end
end
My::Application.routes.draw do |map|
match "/en", :to => HomeApp
end
// ==========================================================================
// Project: Todos.TaskDataSource
// Copyright: ©2010 My Company, Inc.
// ==========================================================================
/*globals Todos */
/** @class
(Document Your Data Source Here)
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
@iamjwc
iamjwc / before-filter-test.rb
Created April 7, 2011 20:29
Using url params in before filters
require 'sinatra'
before do
params[:thing] = params[:thing].uppercase
end
get '/:thing' do
"You said '#{params[:thing]}'"
end
@iamjwc
iamjwc / blownmind.rb
Created April 11, 2011 18:24
my mind is blown...
require 'sinatra'
before do
halt 200, {'Content-Type' => 'text/plain'}, "didnt match and it doesnt matter"
end
get '/hey' do
"hey!"
end
# 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
@iamjwc
iamjwc / before_action.rb
Created April 26, 2011 14:53
before_action.rb
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|
[~/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
@iamjwc
iamjwc / pipe.rb
Created May 11, 2011 20:36
pipe.rb
class Pipe
DestinyNotYetChosenException = Class.new(Exception)
CannotWriteToReaderException = Class.new(Exception)
CannotReadFromWriterException = Class.new(Exception)
def initialize
@readpipe, @writepipe = IO.pipe
end