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
# NAME: authinabox | |
# VERSION: 1.01 (Dec 27, 2008) | |
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ] | |
# DESCRIPTION: An "all in one" Sinatra library containing a User model and authentication | |
# system for both session-based logins OR HTTP Basic auth (for APIs, etc). | |
# This is an "all in one" system so you will probably need to heavily tailor | |
# it to your own ideas, but it will work "out of the box" as-is. | |
# COMPATIBILITY: - Tested on 0.3.2 AND the latest rtomayko Hoboken build! (recommended for the latter though) | |
# - NEEDS DataMapper! | |
# - Less work needed if you use initializer library -- http://gist.github.com/40238 |
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
introduction | |
- brian | |
- brock | |
- nitobi | |
- phonegap | |
the current situation (brian) | |
- the device / platform matrix | |
- we've seen this before |
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
blake:carealot$ irb -rubygems -r myapp.rb -r sinatra/test | |
irb(main):001:0> app = Sinatra::TestHarness.new(Sinatra::Application) | |
=> #<Sinatra::TestHarness:0x10c3d74 @app=Sinatra::Application> | |
irb(main):002:0> app.get '/' | |
=> #<Rack::MockResponse:0x10ae780 @original_headers={"Content-Type"=>"text/html", "Content-Length"=>"7"}, @status=200, @errors="", @headers={"Content-Type"=>"text/html", "Content-Length"=>"7"}, @body="testing"> | |
irb(main):003:0> app.body | |
=> "testing" |
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
[08:48 AM:gist-99771(master)] $ irb -rubygems -r myapp.rb -r rack/test | |
>> app = Rack::Test::Session.new(Sinatra::Application) | |
=> #<Rack::Test::Session:0x17e8820 @headers={}, @app=Sinatra::Application> | |
>> app.get '/' | |
=> #<Rack::Response:0x17ad4dc @block=nil, @writer=#<Proc:0x0189f7b4@/opt/local/lib/ruby/gems/1.8/gems/rack-0.9.1/lib/rack/response.rb:24>, header{"Content-Type"=>"text/html", "Content-Length"=>"7"}, body["testing"], length7, status200 | |
>> app.body | |
NoMethodError: undefined method `body' for #<Rack::Test::Session:0x17e8820> | |
from (irb):3 |
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 'rubygems' | |
require 'open-uri' | |
require 'hpricot' | |
require 'dm-core' | |
require 'dm-timestamps' | |
class Page | |
include DataMapper::Resource | |
property :id, Serial | |
property :url, String, :nullable=>false, :lazy=>false |
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
<script> | |
function getPicture() { | |
navigator.camera.getPicture(getPicture_Success, null, { quality: 10 }); | |
}; | |
function getPicture_Success(imageData) { | |
alert("getpic success"); | |
document.getElementById("test_img").src = "data:image/jpeg;base64," + imageData; | |
} | |
</script> |
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
%w(rubygems hpricot open-uri json).each { |x| require x } | |
doc = Hpricot.parse(open("http://www.nhl.com/schedules/20092010.html#?navid=nav-sch-sea")) | |
data = (doc/'div[@class=skedDataRow]') | |
def parse_game_date(e) | |
(e/'div[@class=skedDataRow date]').innerHTML.gsub(' ',' ').strip | |
end | |
def parse_game_time(e) |
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
// node.js with cramda syntax | |
// -------------------------- | |
// cramda history for your reference: | |
// http://alex.dojotoolkit.org/2009/05/on-js-lambdas/ | |
// http://james.padolsey.com/javascript/custom-javascript-with-parsescripts/ | |
var sys = require('sys'); | |
var http = require('http'); | |
http.createServer(#(req, res) { |
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
// Get that document | |
people.get(me.key, function(r){ | |
console.log(r); | |
}); | |
// Returns all documents as an array to a callback | |
people.all(function(r){ | |
console.log(r); | |
}); |
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
var store = new Lawnchair('things'); | |
store.save({name:'brian'}); | |
store.find('r.name == "brian"', function(r){ | |
console.log(r); | |
}); |