Skip to content

Instantly share code, notes, and snippets.

@alexsergeyev
alexsergeyev / Capfile
Created April 16, 2015 00:08
rails4_capistrano
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Optional
require 'capistrano/eye'
require 'capistrano/dotgpg'
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
#require 'rubygems'
require 'pp'
#require 'ap' # Awesome Print
class Object
# expects [ [ symbol, *args ], ... ]
def recursive_send(*args)
args.inject(self) { |obj, m| obj.send(m.shift, *m) }
end
end
{
"id":"tag:search.twitter.com,2005:181865366610382848",
"body":"No one wants to carry laptops any more, but we lose IPads and they are not secure. The Sweden PM ran the country for a week on an ipad.",
"verb":"post",
"link":"http://twitter.com/ProfNikiEllis/statuses/181865366610382848",
"generator":{
"link":"http://twitter.com/#!/download/ipad",
"displayName":"Twitter for iPad"
},
"postedTime":"2012-03-19T22:10:56.000Z",
{
"id":"tag:search.twitter.com,2005:181865366610382848",
"body":"No one wants to carry laptops any more, but we lose IPads and they are not secure. The Sweden PM ran the country for a week on an ipad.",
"verb":"post",
"link":"http://twitter.com/ProfNikiEllis/statuses/181865366610382848",
"generator":{
"link":"http://twitter.com/#!/download/ipad",
"displayName":"Twitter for iPad"
},
"postedTime":"2012-03-19T22:10:56.000Z",
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@alexsergeyev
alexsergeyev / api.rb
Created March 21, 2011 18:57
Sinatra metal with Rails authentification
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
require 'sinatra'
class Api < Sinatra::Application
helpers do
def protected!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
throw(:halt, [401, "Not authorized\n"])
module AutoLocale
module Helpers
def switch_to_lang(lang)
lang == options.locales.first ? request.path_info : request.path_info.sub(/^\//, "/#{lang}/")
end
def has_locale?(url)
url =~ /^\/(#{options.locales.join('|')})\/?/
end