Skip to content

Instantly share code, notes, and snippets.

View josephsiefers's full-sized avatar

Joseph Siefers josephsiefers

  • Joinery Housing
  • New York, NY
View GitHub Profile
@josephsiefers
josephsiefers / bigint.rb
Last active March 23, 2016 23:27
BigInt Implementation
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)
@josephsiefers
josephsiefers / thread_inspection.rb
Created January 20, 2016 16:10
Object Space Thread Introspection
ObjectSpace.each_object(SqsWorkers::Manager).next.thread_list.inspect
@josephsiefers
josephsiefers / dockercleanup.sh
Created January 12, 2016 20:51
Clean Unused Docker Containers and Images
#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
@josephsiefers
josephsiefers / dockercleanup.sh
Created October 28, 2015 20:36
Remove Exited Docker Containers and Untagged Docker Images
docker ps -a | grep 'Exited' | awk '{print $1}' | xargs docker rm
docker images | grep "^<none>" | awk '{print $3}'| xargs docker rmi
@josephsiefers
josephsiefers / word_reverse.rb
Last active September 24, 2015 02:02
Reverse Each Word
#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
@josephsiefers
josephsiefers / grandma.rb
Created September 24, 2015 01:32
Annoying Grandma
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
@josephsiefers
josephsiefers / simple_prime.rb
Last active September 24, 2015 01:21
Simple Prime
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
=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')
access_key_id: xxx
secret_access_key: yyy
@josephsiefers
josephsiefers / transfer_mysql.sh
Last active August 29, 2015 14:06
Transfer tables from one MySQL table to another
#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;