This file contains hidden or 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
class BigInt | |
attr_accessor :digits | |
def initialize(num_str=nil) | |
@digits = [0] | |
return if num_str.nil? | |
@digits = num_str.split("").reverse.map(&:to_i) |
This file contains hidden or 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
ObjectSpace.each_object(SqsWorkers::Manager).next.thread_list.inspect |
This file contains hidden or 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
#date >> /tmp/MyLaunchdTest.out | |
docker ps -a | grep 'Exited' | awk '{print $1}' | xargs docker rm | |
docker images | grep "^<none>" | awk '{print $3}' | xargs docker rmi |
This file contains hidden or 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
docker ps -a | grep 'Exited' | awk '{print $1}' | xargs docker rm | |
docker images | grep "^<none>" | awk '{print $3}'| xargs docker rmi |
This file contains hidden or 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
#step-by-step function, feel free to follow along in IRB | |
def reverse_each_word(sentence) | |
reverse_each_word = sentence.split(' ') | |
#collect is also known as map in some other languages, basically it takes a set A and transforms it into a set B | |
reversed_words = reverse_each_word.collect { |word| word.reverse } | |
#join does the logical OPPOSITE of split, it takes an array and creates a string according to a split character | |
reversed_words.join(' ') | |
end | |
#even more succinctly, leveraging the power of Ruby idioms and syntatic sugar, the whole function in can be written in ONE LINE |
This file contains hidden or 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
def speaking_grandma(response) | |
#you are close here | |
#if response = downcase | |
if response == response.downcase | |
puts "HUH! SPEAK UP, SONNY!" | |
else | |
puts "NO, NOT SINCE 1938!" | |
end | |
end |
This file contains hidden or 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
def prime? n | |
for d in 2..(n - 1) | |
if (n % d) == 0 | |
return false | |
end | |
end | |
#implicit return of the range from the for loop unless you return a value yourself, as seen below: | |
return true | |
end |
This file contains hidden or 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
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
This file contains hidden or 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
access_key_id: xxx | |
secret_access_key: yyy |
This file contains hidden or 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
#http://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name?page=1&tab=votes#tab-top | |
for table in `mysql -h $host -u root -P $port --password=$password -w -N -e "show tables from $schema"`; do | |
mysql -h $host -u root -P $port --password=$password -w -N -e "rename table $schema.$table to $schema_two.$table"; | |
done; |
NewerOlder