Skip to content

Instantly share code, notes, and snippets.

@4rlm
4rlm / postgresql.txt
Last active September 13, 2018 23:43
Postgresql
1) Backup PG
$ pg_dump -U postgres -F t sdf2_development > db/csv/pg_backups/sdf2_development.psql
$ pg_dump -F c -v -U postgres -h localhost sdf2_development -f db/csv/pg_backups/sdf2_development.tar
2) Restore PG:
$ pg_restore -U postgres db/csv/pg_backups/sdf2_development.psql
$ pg_restore -c -C -F c -v -U postgres db/csv/pg_backups/sdf2_development.tar
############ Progress ############
bundle exec tail -f log/development.log
@4rlm
4rlm / ruby_find_anagrams.txt
Created September 13, 2018 23:13
Ruby - Find Anagrams
def word_formatter(word)
word_chars = word.downcase.chars.sort
word_chars.join('')
end
def find_anagrams(possible_anagrams, word)
input_word = word_formatter(word)
detect = false
@4rlm
4rlm / ruby_roman_nums.txt
Created September 13, 2018 23:12
Ruby Roman Nums
require 'pry'
def convert_to_roman(arabic_number, modern = false)
modern ? convert_to_modern(arabic_number) : convert_to_classic(arabic_number)
end
def convert_to_classic(arabic_number)
answer = arabic_number / 1000 # 1
remainder = arabic_number % 1000 # 1
thousands = "M" * answer
@4rlm
4rlm / ruby_ssn.txt
Created September 13, 2018 23:12
Ruby - SSN
# Look at the tests in `spec/social_security_numbers_spec.rb`
# to see a description of how these methods should behave.
# Determine whether a string contains a Social Security Number.
def has_ssn?(string)
arr = string.scan(/\d{3}-\d{2}-\d{4}/)
if arr == nil || arr == []
false
else
string.include?(arr[0])
@4rlm
4rlm / ruby_words_in_file.txt
Created September 13, 2018 23:10
Ruby - Words in File
# def most_frequent_words(filename, count = 5)
# file_parser(filename)
# end
file_path = 'text-files/osiris_myth.txt'
def string_count_sorter(string_count_hash)
rankings = string_count_hash.sort_by {|_key, value| value}
puts rankings.inspect
end
@4rlm
4rlm / ruby_word_search.txt
Created September 13, 2018 23:10
Ruby - Word Search
# def straight_line_include?(word, puzzle)
# end
#
# def snaking_include?(word, puzzle)
# end
############################################
puzzle = [
["a", "w", "o", "l", "v", "e", "s"],
["s", "o", "a", "w", "a", "h", "p"],
@4rlm
4rlm / ruby_thermostat.txt
Created September 13, 2018 23:09
Ruby - Thermostat
# EXERCISE 1
# <Your code here>
first_name = 'Adam'
last_name = 'Booth'
greeting = "My name is #{first_name} #{last_name}."
puts greeting
@4rlm
4rlm / ruby_subset_count.rb
Created September 13, 2018 23:08
Ruby - Subset Count
def fac(n) # => Calculates factorial of number.
if n < 1
1
else
n * fac(n - 1)
end
end
def find_subsets(n, r)
fn = fac(n)
@4rlm
4rlm / ruby_shuffle.txt
Created September 13, 2018 23:08
Ruby - Shuffle
def shuffle(array)
input = array.clone
output = []
len = input.length
while len > 0
r = Random.rand(0..len-1)
output << input[r]
input.delete_at(r)
len = input.length
@4rlm
4rlm / ruby_linear_search.txt
Created September 13, 2018 23:07
Ruby - Linear Search
def linear_search(target, arr)
i = 0
while i < arr.length
if arr[i] == target
return i
else
nil
end