Skip to content

Instantly share code, notes, and snippets.

View leandro's full-sized avatar
🏠
Working from home

Leandro Camargo leandro

🏠
Working from home
View GitHub Profile
/**
* @description DropDownAnything, drop down menu based on prototype
* @author Leandro N. Camargo; leandro-at-gmail-dot-com
* @version 0.1
* @date 08/09/2008
* @requires prototype.js 1.6
*/
var DDropDown = function(menu, targets, opt) {
var null_fn = function() {}, _this = this, ie = Prototype.Browser.IE, select_callback = false, menu_caller;
module RIndexer
RE_TAG = %r!<([a-z\d_-]+)\s*.*?>!im
def fetch_tags(doc_stream)
tags = Hash.new(0)
doc_stream.scan(RE_TAG).each do |e|
tags[e] += 1
end
tags
end
module RIndexer
RE_TAG = %r!<([a-z\d_-]+)\s*.*?>!im
def fetch_tags(doc_stream)
tags = Hash.new(0)
doc_stream.scan(RE_TAG).each do |e|
tags[e] += 1
end
tags
end
class String
def /(separator)
split separator
end
end
class Object
# with this method you can call stuffs like this Comment.nested_send(:creator, :login)
# it's the same of Comment.creator.login without the need of checking the absense of creator like:
# Comment.creator && Comment.creator.login
def nested_send(*methods)
obj = self
methods.each do |e|
case e
when Array
class Object
# with this method you can call stuffs like this Comment.nested_send(:creator, :login)
# it's the same of Comment.creator.login without the need of checking the absense of creator like:
# Comment.creator && Comment.creator.login
def nested_send(*methods)
obj = self
methods.each do |e|
case e
when Array
require 'matrix'
module FixnumExt
def square?
sqrt = self ** (1.0/2)
(sqrt - sqrt.to_i).zero?
end
end
module MatrixDeterminant
# Matrix#det2 does what Matrix#det doesn't do: calculate correctly a matrix determinant
require 'matrix'
module FixnumExt
def square?
sqrt = self ** (1.0/2)
(sqrt - sqrt.to_i).zero?
end
end
@leandro
leandro / debug.rb
Created October 14, 2009 13:58 — forked from tmm1/debug.rb
# collect information about a running process
# ruby debug.rb <pid>
begin
raise ArgumentError unless pid = ARGV[0]
pid = pid.to_i
Process.kill(0,pid)
rescue TypeError, ArgumentError
raise 'pid required'
rescue Errno::ESRCH
@leandro
leandro / carbon.md
Created November 6, 2009 02:01 — forked from defunkt/carbon.md

Vim

autocmd BufWritePre * :%s/\s\+$//e

Emacs

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Textmate