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
fonte: http://www.akitaonrails.com/2008/11/10/micro-tutorial-de-ruby-parte-ii | |
contents = File.open(aFile).readlines.inject("") do |buf, line| | |
buf += line | |
end | |
O método ‘readlines’ devolve um Array, onde cada elemento é uma linha do arquivo texto. O método “inject” é um Redutor: ele pega linha a linha do Array e repassa ao bloco, como primeiro parâmetro. O segundo parâmetro, ‘buf’, é um totalizador que é iniciado com o primeiro parâmetro que passamos no método ‘inject’, no caso a string vazia “". Ele repassa sempre esse objeto como segundo parâmetro do bloco. Dentro do bloco podemos fazer o que quiser, mas normalmente queremos que seja um totalizador por isso usamos o operador "+=” que significa “buf = buf + line”. | |
Em Ruby é muito comum utilizar essa maneira de pensar: em vez de pensar em “como vamos iterar elemento a elemento”, partimos do princípio que isso é trivial e daí pensamos “como queremos filtrar elemento a elemento”. Linhas como a seguinte são bastante comuns: | |
>> [1,2,3,4,5].map { |elem| elem * |
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
#add this line to ~/.bash_aliases | |
alias sudo='sudo env PATH=$PATH' |
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
dpkg --get-selections > installed_soft.txt |
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
Sete Atitudes para Hackear a Indústria de Software | |
By Klaus Wuestefeld | |
1) Torne-se excelente. | |
Seja realmente bom em alguma coisa. Não fique só choramingando ou | |
querendo progredir às custas dos outros. Não pense q pq vc sentou 4 | |
anos numa faculdade ouvindo um professor falar sobre software q vc | |
sabe alguma coisa. Jogador de futebol não aprende a jogar bola tendo |
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
# lib/active_admin_views_pages_base.rb | |
class ActiveAdmin::Views::Pages::Base < Arbre::HTML::Document | |
private | |
# Renders the content for the footer | |
def build_footer | |
div :id => "footer" do | |
para "Copyright © #{Date.today.year.to_s} #{link_to('Example.com', 'http://example.com')}. Powered by #{link_to('Active Admin', 'http://www.activeadmin.info')} #{ActiveAdmin::VERSION}".html_safe |
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
#using ruby 1.8 | |
cd ~/.vim/ruby/command-t | |
make clean | |
env ARCHFLAGS="-arch x86_64" ruby extconf.rb | |
env ARCHFLAGS="-arch x86_64" make |
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
(Insinde the gemspecs directory - $RUBYHOME/lib/ruby/gems/1.8/specifications) | |
Finding the problematics gemspecs: | |
grep -i *.gemspec -e '.*s\.date.*=.*%q{\(....-..-..\) \(.*Z\)} | |
Fixing the files: | |
sed -i -e 's/\(.*\)s\.date.*=.*%q{\(....-..-..\) \(.*Z\)}/\1s.date = %q\{\2}/p' ./*.gemspec |
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
If you're using rvm: | |
$ rvm reinstall 1.9.3 --force-autoconf | |
$ gem install ruby-debug19 -- --with-ruby-include="${MY_RUBY_HOME/rubies/src}" | |
$ gem install debugger-linecache -- --with-ruby-include="${MY_RUBY_HOME/rubies/src}" | |
#Using rbenv and ruby 1.9.2 p290 on ubuntu 64 | |
Download the following files from http://rubyforge.org/frs/?group_id=8883 |
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
#source: http://seechrisblog.com/2010/05/18/getting-ack-to-work-in-vim-on-ubuntu/#comment-95 | |
sudo ln -s /usr/bin/ack-grep /usr/local/bin/ack |
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
#source: http://mislav.uniqpath.com/2010/07/git-tips/ | |
Show branches, tags in git log | |
$ git log --oneline --decorate | |
7466000 (HEAD, mislav/master, mislav) fix test that fails if current dir is not "hub" | |
494a414 fix cherry-pick of a commit URL | |
4277848 (origin/master, origin/HEAD, master) whoops | |
d270fae bugfix: git init -g | |
9307af3 test deps |
OlderNewer