Filipe Costa filipebarcos

View string.rb
1 2 3 4 5 6 7 8 9
require 'benchmark'
 
n = 1000000
Benchmark.bm(15) do |x|
x.report("assign single") { n.times do; c = 'a string'; end}
x.report("assign double") { n.times do; c = "a string"; end}
x.report("concat single") { n.times do; 'a string ' + 'b string'; end}
x.report("concat double") { n.times do; "a string " + "b string"; end}
end
View das.rb
1 2 3 4 5 6 7 8 9
module ClassMethods
def self.method2
end
end
 
module InstanceMethods
def method1
end
end
View speaker.md
View example.rb
1 2 3 4 5 6 7 8 9 10
#in real life this is going until column 98
@my_variable = MyVeryLongClassName.method("three", "arguments", "method") || default_value_method
 
# or
 
@my_variable = MyVeryLongClassName.method("three", "arguments", "method")
@my_variable ||= default_value_method
 
# or
@my_variable = MyVeryLongClassName.method("three", "arguments", "method")
View test.rb
1 2 3 4 5 6 7 8 9 10
module Bar
def self.method1
end
def method2
end
end
 
class Foo
include Bar
View tune_postgres.sh
1 2 3 4 5 6 7 8 9 10
#! /bin/bash
 
#with your postgresql setup up, with you postgres user too, let's do this o improve your postgresql performance
cd ~
wget http://pgfoundry.org/frs/download.php/2449/pgtune-0.9.3.tar.gz
tar -zxvf pgtune-0.9.3.tar.gz
cd pgtune-0.9.3
#first parameter is where your postgresql.conf is
./pgtune -i /etc/postgresql/9.0/main/postgresql.conf -o ~/postgresql.conf.pgtune --type Web
cp /etc/postgresql/9.0/main/postgresql.conf /etc/postgresql/9.0/main/postgresql.conf.bkp
View brakeman.sh
1 2 3 4
bash -l -c 'rbenv local 1.9.3-p125 &&
gem install brakeman --no-ri --no-rdoc &&
brakeman -o brakeman-output.tabs --no-progress --separate-models &&
rbenv local --unset'
View what_i_did.sh
1 2 3 4 5 6 7 8 9 10
# when I tried to start postgres, I had an error telling me there were no postgres clusters created
# so I had to create one using the `pg_createcluster` command, like the following
pg_createcluster 9.1 main --start
 
#after creating the cluster, it will start the server because of `--start`
#so I had to change to postgresql user
sudo su - postgres
 
#to change it's pasword, doing `psql -d <database_name> -U <username>
psql -d postgres -U postgres
View version.rb
1 2
database = SQLite3::Database.new('your_database.db')
version = database.execute("SELECT sqlite_version() AS 'SQLite Version';").flatten # it returns [['3.x.x']]
View hash.rb
1 2 3 4 5 6 7 8 9 10
class Hash
def symbolize_keys
self.inject({}) { |acc, elem| acc.merge!(elem[0].to_sym => elem[1]) }
end
def deep_symbolize_keys
self.inject({}) do |acc, elem|
acc.merge! elem[0].to_sym => elem[1].class == Hash ? elem[1].deep_symbolize_keys : elem[1]
end
end
Something went wrong with that request. Please try again.