Skip to content

Instantly share code, notes, and snippets.

@yctay
yctay / nginx.conf
Created June 20, 2013 03:14
Example nginx/puma conf file.
upstream example_name {
server unix:///var/www/example_name/shared/sockets/puma.sock;
}
server {
listen 80;
server_name example_name.com;
root /var/www/example_name/current/public;
location / {
@yctay
yctay / seeds.rb
Created November 28, 2013 15:27
Country seed data using data from the 'countries' gem. Table columns: - name - continent - alpha2_code - currency_code - calling_code Adapt for your own use!
# Countries
# `alpha2_code` has unique constraint
countries_seed_file = File.join(Rails.root, 'db', 'seeds', 'countries.yml')
countries = YAML.load_file(countries_seed_file)
countries.each do |country|
country = country[-1]
data = {
name: country['name'],
continent: country['continent'],
@yctay
yctay / app.rake
Created November 28, 2013 18:07 — forked from ChuckJHardy/app.rake
------------ From Rake Task
namespace :app do
# Checks and ensures task is not run in production.
task :ensure_development_environment => :environment do
if Rails.env.production?
raise "\nI'm sorry, I can't do that.\n(You're asking me to drop your production database.)"
end
end
@yctay
yctay / hash.rb
Last active January 1, 2016 16:49
Extension of the `key?` method to check for existence of multiple keys in a hash.
class Hash
# Extension of the `key?` method to check for existence of multiple keys in
# a hash.
#
# Returns true if all keys matches, false if hash has missing keys.
# Returns true if hash has more keys than specified in array.
def keys?(array)
!array.map { |k| self.key?(k) }.include? false
end
end
# A list of possible usernames to reserve to avoid
# vanity URL collision with resource paths
# It is a merged list of the recommendations from this Quora discussion:
# http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
# Country TLDs found here:
# http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains
# Languages found here:
# app/models/concerns/multiparameter_attribute_assignment.rb
module MultiparameterAttributeAssignment
include ActiveModel::ForbiddenAttributesProtection
def initialize(params = {})
assign_attributes(params)
end
def assign_attributes(new_attributes)