Skip to content

Instantly share code, notes, and snippets.

View kapso's full-sized avatar

Kapil kapso

View GitHub Profile
@kapso
kapso / move_to_rds.rb
Created October 4, 2011 05:48 — forked from guenter/move_to_rds.rb
A quick and dirty script to move a database into Amazon RDS (or any other database). Can transfer part of the data beforehand.
require 'fileutils'
start_time = Time.now
SOURCE_DB = {
:name => 'db_name',
:user => 'db_user',
:password => 'db_pass',
:host => 'localhost'
@kapso
kapso / dabblet.css
Created December 21, 2011 20:47
CSS3 Border-Radius with Border - Circle Avatars
/**
* CSS3 Border-Radius with Border - Circle Avatars
*/
/* General Styles */
body { background: url(http://subtlepatterns.com/patterns/white_texture.png);
font: 100 14px sans-serif;
color: #444555; text-shadow: 0 2px white;
text-align: center;
@kapso
kapso / dabblet.css
Created December 22, 2011 09:41 — forked from fatgy/dabblet.css
Logo of some exhibition http://goo.gl/EK4Yp
/* Logo of some exhibition http://goo.gl/EK4Yp
from https://www.facebook.com/iCAREClub?ref=ts
*/
body {
font-size: 16px;
background-color: #DFE0E2;
color: #BA9254;
}
begin
# some code here that generates an exception, this code is my model class
logger.info "Some error..."
rescue => e
logger.error "Some error - #{e.message}"
Airbrake.notify e
end
class CreateFriends < ActiveRecord::Migration
def option_1
create_table :friends do |t|
t.string :user_guid, null: false
t.string :friend_guid, null: false
t.boolean :reciprocal, default: false
t.string :name, null: false
end
@kapso
kapso / Instrument Anything in Rails 3.md
Created June 20, 2012 19:52 — forked from mnutt/Instrument Anything in Rails 3.md
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@kapso
kapso / gist:3005776
Created June 27, 2012 18:09
Ruby parameter passing by value or reference? (its by REF)
class Car
def start(options)
options[:speed] = 60
puts "running @ #{options[:speed]}"
end
end
op = { speed: 50 }
puts op.inspect
Car.new.start op
@kapso
kapso / gist:3005829
Created June 27, 2012 18:20
Ruby by reference or value? (in this example it created a copy)
class Car
def start(speed)
speed = 60
puts "running @ #{speed}"
end
end
speed = 40
puts speed
Car.new.start speed
@kapso
kapso / gist:3061752
Created July 6, 2012 18:13 — forked from toamitkumar/gist:952211
Inspect and test routes on console (Rails 3)
$ rails console
Loading development environment (Rails 3.0.6)
ruby-1.8.7-p334 :001 > r = Rails.application.routes
Gives you a handle of all the routes (config/routes.rb)
#Inspect a named route:
ruby-1.8.7-p334 :005 > r.recognize_path(app.destroy_user_session_path)
=> {:action=>"destroy", :controller=>"sessions"}
@kapso
kapso / gist:3455336
Created August 24, 2012 20:36
Paths
{
"connections/paths": [
{
"user_ids": ["4e4b1547a876e66e41000033", "4e4b1547a876e66e41000011"],
"connectors": [
{
"via": "facebook",
"type": "friend",
OR
"in": true,