Skip to content

Instantly share code, notes, and snippets.

@jmac522
jmac522 / keybase.md
Created February 13, 2023 19:44
keybase
@jmac522
jmac522 / queries.sql
Created May 27, 2015 18:56
Hollywood
-- 1. What are the top 50 worst rated movies? The results should
-- include the movie title and rating and be sorted by the worst
-- rating first.
SELECT title as movie_title, rating
FROM movies
ORDER BY rating
LIMIT 50;
-- movie_title | rating
@jmac522
jmac522 / dic_sort
Created March 22, 2015 08:21
Dictionary Sort
def dictionary_sort arr
rec_dict_sort arr, []
end
def rec_dict_sort unsorted, sorted
if unsorted.length <= 0
return sorted
end
smallest = unsorted.pop
still_unsorted = []
@jmac522
jmac522 / shuffle
Created March 22, 2015 08:20
Shuffle
def shuffle arr
shuf = []
while arr.length > 0
rand_index = rand(arr.length)
curr_index = 0
new_arr = []
arr. each do |item|
if curr_index == rand_index
shuf.push item
@jmac522
jmac522 / sort_2
Created March 22, 2015 08:19
Rite of Passage
def sort arr
rec_sort arr, []
end
def rec_sort unsorted, sorted
if unsorted.length <= 0
return sorted
end
smallest = unsorted.pop
still_unsorted = []
@jmac522
jmac522 / roman_modern
Created March 22, 2015 08:18
Modern Roman Numerals
def
thous = (num /1000)
hunds = (num % 1000/ 100)
tens = (num % 100 / 10)
ones = (num % 10 )
roman = 'M' * thous
if hunds == 9
roman = roman + 'CM'
elsif hunds == 4
@jmac522
jmac522 / roman_old
Created March 22, 2015 08:18
Old Roman Numerals
def old_roman_numeral num
roman = ''
roman = roman + 'M' * (num /1000)
roman = roman + 'D' * (num % 1000/ 500)
roman = roman + 'C' * (num % 500/ 100)
roman = roman + 'L' * (num % 100/ 50)
roman = roman + 'X' * (num % 50/ 10)
roman = roman + 'V' * (num % 10/ 5)
roman = roman + 'I' * (num % 5/ 1)
@jmac522
jmac522 / ask_1
Created March 22, 2015 08:17
Ask Method
def ask question
while
puts question
reply = gets.chomp.downcase
if reply == yes
return true
end
if reply == no
return false
end
@jmac522
jmac522 / table_1
Created March 22, 2015 08:16
Table of Contents
title= 'Table of Contents'
chapters= [['Unoriginal Title', 1],['Less Unoriginal Title', 10],['Least Unoriginal Title', 25]]
puts title.center(100)
puts
chapter_num=1
chapters.each do |chap|
@jmac522
jmac522 / array_1
Created March 22, 2015 08:15
Sorting Array
array= []
puts 'Type as many words as you want. When you\'re done press enter'
while true
word= gets.chomp
array.push word.downcase
if word == ''
break
end
end
puts array.sort