Skip to content

Instantly share code, notes, and snippets.

@JamesHayton
JamesHayton / gist:1862587
Created Feb 19, 2012 — forked from jacquescrocker/gist:1318784
google cloud print pointers
View gist:1862587
# this works with oauth 0.5.1
client = OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET,
:authorize_url => "/o/oauth2/auth",
:token_url => "/o/oauth2/token",
:site => 'https://accounts.google.com/')
redirect_uri = "#{SERVER_URL}/oauth2callback"
get '/auth' do
@JamesHayton
JamesHayton / rails content_for caching
Created Feb 14, 2012 — forked from stackng/rails content_for caching
make action and fragment caching of rails3 compatible with content_for
View rails content_for caching
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
View gist:378368
class BaseModel < CouchRest::ExtendedDocument
include ActiveModel::Dirty
use_database DB
def initialize(passed_keys={}, options={})
super(passed_keys, options)
@changed_attributes = {}
end
class <<self
View Faker & couchdb
require "rubygems"
require "faker"
require "couchrest"
DB = CouchRest.database!('http://127.0.0.1:5984/contacts')
class Contact < CouchRest::ExtendedDocument
use_database DB
property :first_name
View _comment.html.erb
<% if can? :destroy, @comment %>
<%= link_to 'Delete', comment_path({:id => comment.id}), :confirm => "Are you sure?", :method => :delete %>
<% end %>
View gist:314377
require 'couchrest'
class Log < CouchRest::ExtendedDocument
database = CouchRest.new
database.default_database = "logger"
use_database database.default_database
property :response_time
property :created_at
View gist:302134
{
"all": {
"map": "function(doc) {\n if (doc['couchrest-type'] == 'BlogUser') {\n emit(doc['_id'],1);\n }\n }"
},
"by_account": {
"map": "function(doc) {\n if ((doc['couchrest-type'] == 'BlogUser') && doc['account']) {\n emit(doc['account'], null);\n }\n}\n"
}
}
View gist:295613
# Installing Rails 3.0.pre in it's own gemset using rvm.
# I use Ruby Enterprise Edition for rails development.
# You might want to replace ree with Your Favorite Ruby Implementation(tm)
rvm use ree%rails3 # Create new gemset called rails3.
gem install rake rack test-spec thor sqlite3-ruby # Get some gems we'll need (rails3 gemset should be empty)
git clone git://github.com/rails/rails.git && cd rails # Get rails source.
git submodule init && git submodule update # Get git dependencies.
rake package && gem install -f */pkg/*.gem pkg/*.gem # Create gems and install
cd arel && thor :build && thor :install && cd ../.. # Install arel
View ContactItemView.js
SC.PoolableClass = {
isPooled: YES,
_objectPool: [],
maxPoolSize: 100,
_pool_default_concat_values: {}, // default values for concatenated properties
create: function() {
// first, check pool