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
tanner@radical-edward:~/Code/tell-your-friends/app$ rake tyf:test(in /home/tanner/Code/tell-your-friends/app) | |
Account Model | |
- should exist | |
- should create via :new | |
Main Pages | |
- should load the index | |
- should have a login form | |
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
# To use with thin | |
# thin start -p PORT -R config.ru | |
require 'sinatra' | |
# include our Application code | |
require File.join(File.dirname(__FILE__), 'sample.rb') | |
# disable sinatra's auto-application starting | |
disable :run |
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 sinatra/base instead of sinatra to avoid some of the magic | |
require 'sinatra/base' | |
module Sample | |
class Main < Sinatra::Base | |
# Pretty normal application here | |
get '/' do | |
erb :index | |
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
# This method is heavily adapted from the Rails method of determining the subdomain. | |
require 'rubygems' | |
require 'sinatra' | |
require 'rack/request' | |
# We re-open the request class to add the subdomains method | |
module Rack | |
class Request | |
def subdomains(tld_len=1) # we set tld_len to 1, use 2 for co.uk or similar |
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
# 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 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
Test::Unit::TestCase.send :include, Sinatra::Test | |
class Waste < Sinatra::Base | |
get '/' do | |
puts session[:test] | |
end | |
end | |
describe 'Waste' do | |
before { @app = Waste } |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
gem 'rack', '=0.9.1' | |
gem 'thin', '=1.0.0' | |
require 'sinatra/base' | |
## To run this just run thin -R config.ru start | |
## The default tests pass, allowing the app to start. If the tests failed, the app would not even attempt to start. | |
## | |
## Wrap up our sample app in a class, this let's us keep the entire app |
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
#This should insert all the rack test methods into your current test context. | |
#Modify as appropriate for your specific test framework. | |
#If you're including the Sinatra::Test in each of your tests, you'll need to | |
#include Rack::Test::Methods instead. | |
Test::Unit::TestCase.send :include, Sinatra::Test | |
#becomes | |
Test::Unit::TestCase.send :include, Rack::Test::Methods |
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
import android | |
import httplib | |
import urllib | |
while(True): | |
droid = android.Android() | |
code = droid.scanBarcode() | |
isbn = code['result']['SCAN_RESULT'] | |
sleep(5) | |
if not isbn: # Scan failed for some reason, bail. |
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
<? | |
//This is terribly insecure. We don't even pretend that we're authenticating here. | |
//We take parameters straight from _GET. | |
//Don't actually use this as is, please. | |
//Simple UPC -> ISBN code | |
function parseUPC($upc) { | |
if(false !== strstr($upc,'978')){ | |
$isbn = substr($upc,3,9); | |
$xsum=0; |
OlderNewer