Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@MaherSaif
MaherSaif / nginx_rails_3_1
Created October 20, 2011 15:00 — forked from shapeshed/nginx_rails_3_1
Nginx Config for Rails 3.1 with Unicorn and Asset Pipeline
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@MaherSaif
MaherSaif / capistrano_database_yml.rb
Created October 21, 2011 01:42 — forked from weppos/capistrano_database_yml.rb
Provides a couple of tasks for creating the database.yml configuration file dynamically when deploy:setup is run.
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <[email protected]>
# Copyright:: 2007-2010 The Authors
# Make a user that we'll add a book to.
user = User.create!
controller.stub(:current_user) { user }
# This prints []. The book list is empty.
p user.books
# Expect a book to be added to the user. This fails (see below)
expect {
post :create, :id => asin
@MaherSaif
MaherSaif / ci_hook.bat
Created December 5, 2011 01:36 — forked from infertux/ci_hook.bat
EC2 Windows CI hackish scripts
@echo off
REM If you edit this file, make sure to run `unix2dos` to fix those fucking CRLF.
REM Let's keep this script as dumb as possible and do all the logic with a true language.
REM Basically, this should be no more than a sort of remote control.
echo Initializing hook...
:begin
@MaherSaif
MaherSaif / redis_usage.rb
Created December 24, 2011 22:06 — forked from mikhailov/redis_usage.rb
Rails on Redis - is all about high performance
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts.all_cached # Retrive only at once by every 5 minutes
expires_in 5.minutes, :private => false, :public => true
end
end
# app/models/post.rb
Class Post
@MaherSaif
MaherSaif / application.rb
Created January 4, 2012 23:37 — forked from arunthampi/application.rb
assets cdn example
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module GetDenso
class Application < Rails::Application
@MaherSaif
MaherSaif / set_asset_fingerprint.rb
Created January 4, 2012 23:38 — forked from arunthampi/set_asset_fingerprint.rb
Set Asset Fingerprint as part of the deployment workflow
def set_asset_fingerprint!
# -- First see if the files have changed
puts "-----> Calculating Asset Fingerprint"
fingerprint_method = "find public -type f -exec md5 {} + | awk '{print $0}' | sort | md5"
current_fingerprint = %x{#{fingerprint_method}}
fingerprint_file = Rails.root.join('assets.fingerprint')
if !File.exists?(fingerprint_file) || current_fingerprint != File.read(fingerprint_file)
execute("#{fingerprint_method} > #{fingerprint_file}")
# -- Add it to production
@MaherSaif
MaherSaif / deploy.rb
Created January 6, 2012 18:09 — forked from stympy/deploy.rb
Skip asset pre-compilation when deploying if the assets didn't change
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
@MaherSaif
MaherSaif / nginx.conf
Created January 9, 2012 04:04
Nginx configuration file for reference
server {
listen 80;
server_name www.example.com example.com;
root /var/www/www.example.com/web;
if ($http_host != "www.example.com") {
rewrite ^ http://www.example.com$request_uri permanent;
}
index index.php index.html;