Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
require 'logger'
require 'rubygems'
require 'wirble'
require 'pp'
Wirble.init
Wirble.colorize
# require 'utility_belt'
if ENV.include?('RAILS_ENV')&& !Object.const_defined?('RAILS_DEFAULT_LOGGER')
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
class User
# ...
def method_missing(sym, *args)
if sym.to_s =~ /\A(.*)\?\z/ && ROLES.include?($1)
roles.include?($1)
else
super
end
end
@iangreenleaf
iangreenleaf / rsync-retry.sh
Created January 18, 2010 07:12
rsync with retries
#!/bin/bash
### ABOUT
### Runs rsync, retrying on errors up to a maximum number of tries.
### Simply edit the rsync line in the script to whatever parameters you need.
# Trap interrupts and exit instead of continuing the loop
trap "echo Exited!; exit;" SIGINT SIGTERM
MAX_RETRIES=50
This example shows how to setup an environment running Rails 3 under 1.9.2 with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2@rails3
@gerhard
gerhard / etc_default_php-fastcgi
Created March 18, 2010 13:44
setting up an ubuntu box for ruby & php stuff. Includes nginx and php-fcgi daemons
#
# Settings for php-cgi in external FASTCGI Mode
#
# Should php-fastcgi run automatically on startup? (default: no)
START=yes
# Which user runs PHP? (default: www-data)
@netzpirat
netzpirat / rubymine.rb
Created April 14, 2010 19:32
Minimal Rails 3 support for RubyMine: Creates the old Rails 2 scripts that simply executes Rails 3 'rails' command.
#!/usr/bin/env ruby
#
# Helper script to temporary fix some RubyMine 2.0.2 functionality by
# creating old-style Rails 2 scripts. This enables me actually to
# run & debug apps and use the Rails console.
#
# On my machine I have to increase the debugger timeout to connect to a
# Rails 3 app on Ruby 1.9.1. This is done for OS X by modify the Info.plist
# to increase the timeout.
#
@toyflish
toyflish / enviroment.rb
Created April 19, 2010 17:25
rails 2.3.5, Activerecord-sessionstore takes session-id from get-vars if passed by shockwave flash (uploadify) using rack-middleware
# part of config/enviroment.rb
...
Rails::Initializer.run do |config|
# Load model files from sub folders
config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? }
# Load middleware - initially used by flash-session-hack
config.load_paths << "#{RAILS_ROOT}/app/middleware"
From 02e5f09f4d96c4f8ac0c2172008aef0117a70f3e Mon Sep 17 00:00:00 2001
From: Ryan Bigg <[email protected]>
Date: Sat, 10 Jul 2010 20:14:30 +1000
Subject: [PATCH] Remove ugly caller trace.
---
lib/i18n/backend/base.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb
@notahat
notahat / kata.rb
Created September 27, 2010 23:06
def kata(digits = [], has_pair = false)
if digits.inject {|sum, digit| sum + digit } == 15
has_pair ? [digits] : []
else
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result + kata(digits + [digit], has_pair) + kata(digits + [digit, digit], true)
end
end
end