This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Helper | |
{ | |
public static class Convert | |
{ | |
public static int ToInt(object value) | |
{ | |
try | |
{ | |
return System.Convert.ToInt32(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
anemone.focus_crawl do | |
Anemone::Page.fetch("http://www.someurl.com/searchpage/", 'some=params&to=search').links | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function limitChars(textarea, limit, infodiv) { | |
$(textarea).observe("keyup", function(event) { | |
var text = $F(event.element()); | |
var textlength = text.length; | |
var info = $(infodiv); | |
if(textlength > limit) { | |
info.innerHTML = 'You cannot write more then ' + limit + ' characters!'; | |
event.element().setValue(text.substr(0, limit)); | |
event.stop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# instead | |
@object_1.reload | |
@object_2.reload | |
@object_3.reload | |
@object_4.reload | |
# use | |
[@object_1, @object_2, @object_3, @object_4].each(&:reload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ script/performance/benchmarker 50 'Date.new(2009, 1, 1)' | |
user system total real | |
#1 0.000000 0.000000 0.000000 ( 0.001889) | |
$ script/performance/benchmarker 50 'ThirdBase::Date.new(2009, 1, 1)' | |
user system total real | |
#1 0.000000 0.000000 0.000000 ( 0.000731) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## git-publish-branch: a simple script to ease the unnecessarily complex | |
## task of "publishing" a branch, i.e., taking a local branch, creating a | |
## reference to it on a remote repo, and setting up the local branch to | |
## track the remote one, all in one go. you can even delete that remote | |
## reference. | |
## | |
## Usage: git publish-branch [-d] <branch> [repository] | |
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# isso não devia ser assim | |
ActiveRecord::Base.connection.select_all("select count(*) as count from ...;")[0]['count'].to_i | |
# e sim, assim :) | |
ActiveRecord::Base.connection.select_value("select count(*) as count from ...").to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# implementacao | |
def metodo_que_gera_uma_url(text_qualquer, params = {}) | |
# ... inicializa algumas coisas | |
query = params.collect { |k, v| "#{k}=#{v}" }.join('&') | |
url << "?#{query}" | |
end | |
# teste | |
assert_equal "http://host_qualquer.com/?a=1&b=2", metodo_que_gera_uma_url("texto", :a => 1, :b => 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-----+-----+-----+-----+-----+-----+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ | |
| id | age | cla | sal | par | typ | fea | cre | upd | bs | use | pri | str | num | zip | cit | bed | ful | des | con | con | con | pos | str | dir | hea | hal | liv | | |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ | |
| 607 | 0 | L60 | | 141 | Use | tru | Wed | Wed | S | 164 | 434 | | | 606 | 205 | 3 | 2 | Won | Mic | mne | 312 | | | | $43 | 1 | 260 | | |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat thread_test.rb && ruby thread_test.rb | |
Thread.new do | |
while(true) | |
puts "dentro #{Time.now}" | |
end | |
end | |
puts "fora #{Time.now}" | |
dentro Mon May 10 16:17:10 -0300 2010 |