a.k.a. what to do when your ISP starts blocking sites :(
Set the SOCKS proxy to local SSH tunnel
networksetup -setsocksfirewallproxy "Ethernet" localhost 8080
To clear the domain and port
#! /usr/bin/env ruby | |
# usage: | |
# $ das_download.rb email password [download_directory] | |
require 'mechanize' | |
# gem 'mechanize-progressbar' | |
email = ARGV[0] or raise('Please provide the email address for your account') | |
password = ARGV[1] or raise('Please provide the password for your account') | |
path = ARGV[2] || './' |
# Returns a new array by joining and removing duplicates | |
# http://www.ruby-doc.org/core-1.9.3/Array.html#7C-method | |
irb(main):001:0> [1, 2, 3] | [1, 2, 3, 4] | |
=> [1, 2, 3, 4] |
require 'rspec' | |
class Module | |
def takes(*arg_names) | |
define_method(:initialize) do |*arg_values| | |
arg_names.zip(arg_values).each do |name, value| | |
instance_variable_set(:"@#{name}", value) | |
end | |
end | |
end |
colordiff -y <(curl http://www.google.fr | tidy) <(curl http://www.google.co.uk | tidy) |
# http://blog.bigbinary.com/2012/06/26/to_str-in-ruby.html | |
# https://github.com/rails/rails/commit/188cc90af9b29d5520564af7bd7bbcdc647953ca | |
class Foo | |
def to_str | |
"to_str" | |
end | |
def to_s | |
"to_s" |
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html | |
# http://coderwall.com/p/kqhlna | |
require 'securerandom' | |
SecureRandom.urlsafe_base64(8) | |
=> "RrFeKH6k-_Y" | |
=> "VGARhfWcbc4" | |
=> "e86ga-WnMtA" |
# Found here http://tenderlovemaking.com/2012/06/18/removing-config-threadsafe.html | |
# Add to Rails / Sinatra controller / action | |
trap(:INFO) do | |
$stderr.puts "Stuff and things" | |
end | |
# Start web process somehow | |
# Send signal to process |
class ActiveRecord::Base | |
mattr_accessor :shared_connection | |
@@shared_connection = nil | |
def self.connection | |
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection } | |
end | |
end | |
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection |
class AttributeCache | |
def fetch(key) | |
get(key) || yield | |
end | |
def get(key) | |
{ 'title' => 'Cached' } | |
end | |
end |