Skip to content

Instantly share code, notes, and snippets.

View devdatta's full-sized avatar

Devdatta Kane devdatta

View GitHub Profile
@devdatta
devdatta / backup.sh
Created July 25, 2012 16:57
MySQL Backup with stored procedures + GZip
mysqldump -h localhost -u root -p --routines <database> | gzip -9 > <backupfile.sql.gz>
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@devdatta
devdatta / .gitignore
Created May 16, 2011 04:48 — forked from karmi/.gitignore
Import your Gmail messages into ElasticSearch and search them with a simple web application.
.DS_Store
*.log
Gemfile.lock
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base

Copy this script to ".git/hooks/post-checkout" in your repository and make it executable:

chmod +x .git/hooks/post-checkout

Tweak it at will. I'm refreshing the bundle and restarting the app server because the Gemfile is different on my "hosted" branch than on other branches.

Copy this script to ".git/hooks/post-checkout" in your repository and make it executable:

chmod +x .git/hooks/post-checkout

Tweak it at will. I'm refreshing the bundle and restarting the app server because the Gemfile is different on my "hosted" branch than on other branches.

@devdatta
devdatta / first.rb
Created June 21, 2010 05:28 — forked from mtodd/first.rb
def get_bread_crumb(request, separator = " &raquo; ", breadcrumb = [], so_far = '/')
url = request.respond_to?(:request_uri) ? request.request_uri : request
elements = url.split('/')
elements.each_with_index do |element, i|
is_last = i == elements.size - 1 # whether this is the last item or not
so_far += element + '/' # the URL for this element
breadcrumb << # append this element to the breadcrumb
case element
class ApplicationHelper
def breadcrumbs
result = "".html_safe
association_chain.each_with_index do |item, index|
# note that .name works for both classes and objects
result << link_to(item.name.humanize.titlecase, association_chain[0..index])
result << " &raquo; ".html_safe
end
#
# Inspired by
# http://dev.rubyonrails.org/svn/rails/plugins/account_location/lib/account_location.rb
#
module SubdomainAccounts
def self.included( controller )
controller.helper_method(:account_domain, :account_subdomain, :account_url, :current_account, :default_account_subdomain, :default_account_url)
end
protected
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role? :admin
can :manage, :all
else
can :read, :all