Skip to content

Instantly share code, notes, and snippets.

Joseph Siefers josephsiefers

  • Joinery Housing
  • New York, NY
Block or report user

Report or block josephsiefers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@josephsiefers
josephsiefers / bigint.rb
Last active Mar 23, 2016
BigInt Implementation
View bigint.rb
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 Jan 20, 2016
Object Space Thread Introspection
View thread_inspection.rb
ObjectSpace.each_object(SqsWorkers::Manager).next.thread_list.inspect
@josephsiefers
josephsiefers / dockercleanup.sh
Created Jan 12, 2016
Clean Unused Docker Containers and Images
View dockercleanup.sh
#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 Oct 28, 2015
Remove Exited Docker Containers and Untagged Docker Images
View dockercleanup.sh
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 Sep 24, 2015
Reverse Each Word
View word_reverse.rb
#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
View grandma.rb
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
View simple_prime.rb
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
View capybara cheat sheet
=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')
View config.yml
access_key_id: xxx
secret_access_key: yyy
@josephsiefers
josephsiefers / transfer_mysql.sh
Last active Aug 29, 2015
Transfer tables from one MySQL table to another
View transfer_mysql.sh
#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;
You can’t perform that action at this time.