Skip to content

Instantly share code, notes, and snippets.

View MaherSaif's full-sized avatar

Maher Saif MaherSaif

View GitHub Profile
module RuleBook
def RuleBook.add_rules(object, instance_or_class, rules)
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class)
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash)
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing.
object.instance_variable_set(:@_rulebook_initiated, true)
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class
end
match '/:id', :to => proc { |env|
id = env["action_dispatch.request.path_parameters"][:id]
model = Slug.find_by_slug(id).model
controller = [model.pluralize.camelize,"Controller"].join.constantize
controller.action("show").call(env)
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
# Usage:
respond_to :rss, :only => [:index]
def index
@deals = Deal.by_city(@city).limit(15)
respond_with(@deals) do |format|
format.rss { render :rss => @deals, :title => "KupiKon", :item => { :title => :title, :description => :description }}
end
end
ActiveRecord::Base.connection.increment_open_transactions
ActiveRecord::Base.connection.begin_db_transaction
at_exit do
ActiveRecord::Base.connection.rollback_db_transaction
ActiveRecord::Base.connection.decrement_open_transactions
end
# .railsrc for Rails 3, encoding: utf-8
# see http://rbjl.net/49-railsrc-rails-console-snippets
if !Rails.application then warn "Rails isn't loaded, yet... skipping .railsrc" else
# # #
def ripl?; defined?(Ripl) && Ripl.instance_variable_get(:@shell); end
# # #
# loggers
@MaherSaif
MaherSaif / .gitignore
Created May 22, 2011 16:31 — forked from ledermann/.gitignore
rake deploy and rake cache_assets for Heroku (storing JS minimized and gzipped on Amazon S3)
# Add this
public/javascripts/all.js
@MaherSaif
MaherSaif / rvm_install.sh
Created July 19, 2011 07:49 — forked from abarringer/rvm_install.sh
RVM Ubuntu Install
#!/bin/bash
#Based on http://railsapps.github.com/installing-rails-3-1.html
cd ~
sudo apt-get -y install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev curl git-core
bash < <(curl -sk https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
@MaherSaif
MaherSaif / gist:1095938
Created July 20, 2011 21:06 — forked from croaky/gist:1089598
Transfer data from production to staging on Heroku
heroku addons:add pgbackups --remote staging
heroku addons:add pgbackups --remote production
heroku pgbackups:capture --remote production
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging
@MaherSaif
MaherSaif / gist:1105889
Created July 26, 2011 03:27
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules: