Skip to content

Instantly share code, notes, and snippets.

View Twitter_in_Javascript.js
/*
Javascript interface to Twitter search API.
Call it like
Twitter.search({q:'"is down'",
callback:function(data){
doSomethingAwesome(data)
}
})
You can also use any of the other options like lang, since_id, etc.
View rails_not_handle_blank_cookie_well.rb
View gets_pass.rb
#way to stop echoing to console while getting a password
#and to do it w/o pulling in another library
#ref: http://www.ruby-forum.com/topic/107442#243864
# http://stackoverflow.com/questions/133719/how-to-read-a-password-in-ruby
def gets_pass
begin
system "stty -echo"
password = gets.chomp
ensure
system "stty echo"
View time_test.rb
#fun with jruby dates
#
#perhaps related to
# http://jira.codehaus.org/browse/JRUBY-2541
#
require 'date'
puts Time.now.to_s, DateTime.now.to_s
begin
require 'java'
View fun_with_dm_associations.rb
require 'rubygems'
require 'datamapper'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
class A
include DataMapper::Resource
property :id,Serial
has n, :bs
end
View jruby_dm_prop_order_importance.rb
# Either datamapper or data objects has some weird behavior on jruby.
# When an empty text field comes before an integer field in a select,
# the integer field is clobbered.
require 'yaml'
require 'rubygems'
require 'dm-core'
class A
View config.ru
require 'openid_provider_sinatra'
use Rack::Auth::Basic do |username,password|
'secret' == password
end
run OpenIDProvider.new nil, :store=>OpenID::Store::Filesystem.new(Dir.pwd + '/openid-store'),
:user=>Proc.new {|env|
login=env['REMOTE_USER']
return nil unless login
View openid_provider.rb
require 'openid_provider_sinatra'
use Rack::Auth::Basic do |username,password|
'secret' == password
end
run OpenIDProvider.new nil, :store=>OpenID::Store::Filesystem.new(Dir.pwd + '/openid-store'),
:user=>Proc.new {|env|
login=env['REMOTE_USER']
return nil unless login
View openid_id_app_through_env.rb
require 'openid_provider_sinatra'
use Rack::Auth::Basic do |username,password|
'secret' == password
end
class InjectUser
def initialize app
@app=app
end
View openid_provider_single_user.rb
require 'openid_provider_sinatra'
IDENTITY = OpenStruct.new :login=>'Alice',:password=>'secret',:url=>"http://id.example.com/#{login}"
use Rack::Auth::Basic do |username,password|
IDENTITY.password == password && IDENTITY.login == username
end
run OpenIDProvider.new do |provider|
provider.identity IDENTITY
You can’t perform that action at this time.