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 'uri' | |
require 'base64' | |
require 'openssl' | |
# NOTE: Oauth uses a specific unreserved character list for URL encoding. | |
def url_encode(input) | |
unreserved = '-._~0-9A-Za-z' # These are the only characters that should not be encoded. | |
URI.escape(input, Regexp.new("[^#{unreserved}]")) | |
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
!!! | |
%html | |
%head | |
%body{:class => params[:controller], :id => params[:action]} | |
= yield |
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
# NOTE: Remember to add "before_filter :form_authenticity_token" to ApplicationController | |
# and patch ActionView::ActionView::FormTagHelper#token_tag in form_tag_helper.rb | |
class CachingWithRequestForgeryProtection | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
status, headers, response = @app.call(env) |
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
# Expiration Methods | |
cache_control :public, :max_age => 10.seconds | |
expires 10.seconds.from_now | |
# Validation Methods | |
last_modified current_user.updated_at | |
etag current_user.etag |
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
module Document | |
class CannotLoadConfig < Exception; end | |
class DocumentNotValid < Exception; end | |
class DocumentNotFound < Exception; end | |
class InvalidFieldType < Exception; end | |
class InvalidEmbedType < Exception; end | |
def self.hookup | |
@config ||= YAML.load(File.read(Rails.root + "config" + "mongo.yml"))[Rails.env] | |
@db ||= Mongo::Connection.new(@config["host"], @config["port"]).db(@config["database"]) |
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
module Sequel | |
module Plugins | |
module Positioning | |
def self.apply(model, options = {}) | |
options[:field] ||= :position | |
field = options[:field] | |
scope = options[:scope] | |
if scope |
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
[Time.now.to_f.to_s.ljust(16, '0'), Digest::SHA1.hexdigest("request" + rand(0xffffffff).to_s), "#{12}-#{3456}"].join(":") |
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
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
PS1="\u@\h:\W\$(parse_git_branch)$ " |
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
select | |
psut.schemaname, | |
pc.relname, | |
pg_size_pretty(pg_relation_size(pc.relname::varchar)) relsize_pret, | |
pg_size_pretty(pg_total_relation_size(pc.relname::varchar)) total_relsize_pret, | |
pg_relation_size(pc.relname::varchar) relsize, | |
pg_total_relation_size(pc.relname::varchar) total_relsize, | |
pc.reltuples::integer, | |
pc.relpages, | |
coalesce(round((8000 / (nullif(pc.reltuples, 0) / nullif(pc.relpages, 0)))), 0) avg_tuplesize, |
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
create or replace function p_search(search_query text, search_limit int default 10, search_page int default 1) | |
returns table ( | |
id int, | |
model varchar, | |
search_rank real, | |
headlined_name text, | |
headlined_description text, | |
headlined_blank text | |
) as $$ | |
declare |