Skip to content

Instantly share code, notes, and snippets.

@luckydev
luckydev / deploy.rb
Created December 27, 2010 08:21
To track deployments using New Relic RPM
# If you have installed new relic as a gem
# add this to the bottom of your deploy file (deploy.rb)
require 'new_relic/recipes'
set :newrelic_appname, "YourAppNameAsItAppearsInNewRelicAccount"
after "deploy:update", "newrelic:notice_deployment"
@luckydev
luckydev / rspec --help
Created January 6, 2011 16:21
rspec command line options.
Usage: rspec [options] [files or directories]
-b, --backtrace Enable full backtrace
-c, --[no-]color, --[no-]colour Enable color in the output
-d, --debug Enable debugging
-e, --example PATTERN Run examples whose full descriptions match this pattern
(PATTERN is compiled into a Ruby regular expression)
-f, --format FORMATTER Choose a formatter
[p]rogress (default - dots)
[d]ocumentation (group and example names)
[h]tml
@luckydev
luckydev / rspec
Created January 6, 2011 16:21
to format test cases into a neat documentation
$ rspec spec --format documentation
@luckydev
luckydev / rspec
Created January 6, 2011 16:22
To get the same text in a file
$ rspec spec --format documentation > ~/myproject.txt
@luckydev
luckydev / rspec help
Created January 6, 2011 16:26
rspec help
$ rspec --help
@luckydev
luckydev / application.js
Created February 1, 2011 21:48
Prototype technique for implementing jQuery live method
Event.observe(window,'load',function(){
$('parent-id').observe('click',function(event){
var element = event.findElement('css_selector_of_our_target_newly_arrived_element');
if(element.tagName == 'tag_in_caps'){
//do anything
}
});
});
Event.observe(window,'load',function(){
$('content').observe('click',function(event){
var element = event.findElement('a.item');
if(element.tagName == 'A'){
alert("got you.....");
}
});
});
@luckydev
luckydev / irb.rb
Created February 21, 2011 18:46
GoShortener v1.2
> require "rubygems"
=> true
> require "goshortener"
=> true
> go = GoShortener.new("yourapikeyfromgoogle")
=> #<GoShortener:0x10056e6a8 @base_url="https://www.googleapis.com/urlshortener/v1/url", @api_key="yourapikeyfromgoogle">
> go.shorten("http://github.com/luckydev")
=> "http://goo.gl/TCZHi"
> go.lengthen("http://goo.gl/TCZHi")
=> "http://github.com/luckydev"
@luckydev
luckydev / person.rb
Created April 9, 2011 17:09
traditional/usual way to define class
class Person
def say_hi
puts "Hi, Do you like Ruby?"
end
end
john = Person.new
john.say_hi
@luckydev
luckydev / person.rb
Created April 9, 2011 17:12
Ruby classes are first class objects!
Person = Class.new
module PersonInstanceMethods
def say_hi
puts "Hi, Do you like Ruby?"
end
end
Person.send(:include, PersonInstanceMethods)
john = Person.new