Skip to content

Instantly share code, notes, and snippets.

# Nginx+Unicorn best-practices congifuration guide. Now with SPDY!
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
module ActsAsTaggable
module Taggable
def self.included(base)
base.field :tags, :type => Array, :default => []
end
end
module Tagger
def tag(object, tags)

Implement Routing for Subdomains

Rails 3.0 introduced support for routing constrained by subdomains.

A subdomain can be specified explicitly, like this:

match '/' => 'home#index', :constraints => { :subdomain => 'www' } 
@jhjguxin
jhjguxin / Rakefile
Created December 16, 2013 11:09 — forked from vast/Rakefile
require 'my-sinatra-app'
require 'sinatra/activerecord/rake'
desc "run irb console"
task :console, :environment do |t, args|
ENV['RACK_ENV'] = args[:environment] || 'development'
exec "irb -r irb/completion -r my-sinatra-app"
end
# simple ruby code example for running python script
path_to_script = File.dirname(__FILE__)
puts "It's a ruby script"
puts "Run python script with backticks"
puts "Result is available in caller.ru"
puts `python #{path_to_script}/processing.py UserName 37`
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'gosu'
include Gosu
DIMENSION, SPLITS, COLOR = 200, 50, Color::GREEN
# credits to: http://en.wikipedia.org/wiki/Maze_generation_algorithm
class GameWindow < Window
def initialize
super DIMENSION, DIMENSION, false, 1000
self.caption = "Maze"
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'sinatra'
set :port, 3000
set :environment, :production
get '/' do
<<-EOT
<html><head>
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require "selenium-webdriver" # gem install selenium-webdriver
require "highline/import" # gem install highline
def coderwall github_email, github_password, title, content, tags
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://coderwall.com/auth/github"
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh