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
def persist_cache_to_disk(filename): | |
def decorator(original_func): | |
try: | |
cache = pickle.load(open(filename, 'r')) | |
except (IOError, ValueError): | |
cache = {} | |
atexit.register(lambda: pickle.dump(cache, open(filename, "w"))) | |
def new_func(*args): |
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
var nationalities = [ | |
"Afghan", | |
"Albanian", | |
"Algerian", | |
"American", | |
"Andorran", | |
"Angolan", | |
"Anguillian", | |
"Antiguans", | |
"Argentinean", |
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
# If a number is divisible by 3, return "Fizz". | |
# If a number is divisible by 5, return "Buzz". | |
# If a number is divisible by 3 and 5, return "FizzBuzz" | |
def fizzbuzz(x) | |
___ | |
end | |
assert_equal fizzbuzz(3), "Fizz" | |
assert_equal fizzbuzz(50), "Buzz" |
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
# Load DSL and set up stages | |
require 'capistrano/setup' | |
# Include default deployment tasks | |
require 'capistrano/deploy' | |
# Include tasks from other gems included in your Gemfile | |
# | |
# For documentation on these, see for example: | |
# |
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
# config valid only for current version of Capistrano | |
lock '3.3.5' | |
set :application, 'app_name' | |
set :repo_url, '[email protected]:xxx/xxx.git' | |
# Default branch is :master | |
ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp | |
# Default deploy_to directory is /var/www/my_app_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
# server-based syntax | |
# ====================== | |
# Defines a single server with a list of roles and multiple properties. | |
# You can define all roles on a single server, or split them: | |
# production server is xxx.xxx.xxx.xxx | |
server 'xxx.xxx.xxx.xxx', user: 'deployer', roles: %w{app web} | |
# server 'example.com', user: 'deployer', roles: %w{app db web}, my_property: :my_value |
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
#!/bin/sh | |
. /etc/rc.d/init.d/functions | |
. /etc/sysconfig/network | |
[ "$NETWORKING" = "no" ] && exit 0 | |
nginx="/opt/nginx/sbin/nginx" | |
prog=$(basename $nginx) | |
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf" |
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
export app_name="reproduce_rails_routing_bug" | |
echo $app_name | |
rails new ${app_name} | |
cd ${app_name} | |
rails g scaffold foo | |
cd config | |
sed -i '' '/^$/d' routes.rb | |
sed -i '' '/#/d' routes.rb | |
cd .. | |
rails destroy scaffold foo |
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
def self.find_for_facebook_oauth(auth, signed_in_resource=nil) | |
user = User.where(:provider => auth.provider, :uid => auth.uid).first | |
if user | |
return user | |
else | |
registered_user = User.where(:email => auth.info.email).first | |
if registered_user | |
registered_user.update_attributes(:provider => auth.provider, :uid => auth.uid, picture: (URI.parse(auth.info.image.split("?")[0] << "?width=200&height=200") if auth.info.image?) ) | |
return registered_user | |
else |