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
| # Matches patterns such as: | |
| # https://www.facebook.com/my_page_id => my_page_id | |
| # http://www.facebook.com/my_page_id => my_page_id | |
| # http://www.facebook.com/#!/my_page_id => my_page_id | |
| # http://www.facebook.com/pages/Paris-France/Vanity-Url/123456?v=app_555 => 123456 | |
| # http://www.facebook.com/pages/Vanity-Url/45678 => 45678 | |
| # http://www.facebook.com/#!/page_with_1_number => page_with_1_number | |
| # http://www.facebook.com/bounce_page#!/pages/Vanity-Url/45678 => 45678 | |
| # http://www.facebook.com/bounce_page#!/my_page_id?v=app_166292090072334 => my_page_id | |
| # http://www.facebook.com/my.page.is.great => my.page.is.great |
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
| // Check if an element has a class | |
| var hasClass = function (elem, className) { | |
| return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' '); | |
| } | |
| // Add a class to an element | |
| var addClass = function (elem, className) { | |
| if (!hasClass(elem, className)) { | |
| elem.className += ' ' + className; | |
| } |
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
| mkdir -p ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript | |
| cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript | |
| curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Syntaxes/CoffeeScript.tmLanguage | |
| curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Preferences/CoffeeScript.tmPreferences |
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 'action_dispatch/middleware/static' | |
| module Middleware | |
| class FileHandler < ActionDispatch::FileHandler | |
| def initialize(root, assets_path, cache_control) | |
| @assets_path = assets_path.chomp('/') + '/' | |
| super(root, cache_control) | |
| end | |
| def match?(path) |
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
| module Mongoid | |
| class Criteria | |
| def each_by(by, &block) | |
| idx = 0 | |
| total = 0 | |
| set_limit = options[:limit] | |
| while ((results = ordered_clone.limit(by).skip(idx)) && results.any?) | |
| results.each do |result| | |
| return self if set_limit and set_limit >= total |
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
| class InvitationsController < Devise::InvitationsController | |
| # GET /resource/invitation/accept?invitation_token=abcdef | |
| def edit | |
| if params[:invitation_token] && self.resource = resource_class.to_adapter.find_first( :invitation_token => params[:invitation_token] ) | |
| session[:invitation_token] = params[:invitation_token] | |
| render :edit | |
| else | |
| set_flash_message(:alert, :invitation_token_invalid) | |
| redirect_to after_sign_out_path_for(resource_name) |
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
| # Usage: redis-cli publish message.achannel hello | |
| require 'sinatra' | |
| require 'redis' | |
| conns = Hash.new {|h, k| h[k] = [] } | |
| Thread.abort_on_exception = true | |
| get '/' do |
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
| # Usage: redis-cli publish message hello | |
| require 'sinatra' | |
| require 'redis' | |
| conns = [] | |
| get '/' do | |
| erb :index | |
| end |
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
| after "deploy:symlink", "deploy:restart_workers" | |
| ## | |
| # Rake helper task. | |
| # http://pastie.org/255489 | |
| # http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/ | |
| # http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/ | |
| def run_remote_rake(rake_cmd) | |
| rake_args = ENV['RAKE_ARGS'].to_s.split(',') | |
| cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}" |
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
| // FROM: http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29 | |
| // | |
| // db.collection.update( criteria, objNew, upsert, multi ) | |
| // criteria - query which selects the record to update; | |
| // objNew - updated object or $ operators (e.g., $inc) which manipulate the object | |
| // upsert - if this should be an "upsert"; that is, if the record does not exist, insert it | |
| // multi - if all documents matching criteria should be updated | |
| // | |
| // SQL VERSION: | |
| // UPDATE myTable SET dateField = '2011-01-01' WHERE condField = 'condValue' |