Skip to content

Instantly share code, notes, and snippets.

View mjhea0's full-sized avatar

Michael Herman mjhea0

View GitHub Profile
@mjhea0
mjhea0 / rpn_calc.rb
Last active December 16, 2015 22:09
rpn calculator
class RPNCalculator
def evaluate(rpn)
expression = rpn.split
stack = Array.new
unless expression.count > 1
return expression[0].to_i
end
expression.each do |e|
@mjhea0
mjhea0 / hash_ex.rb
Last active December 16, 2015 22:59 — forked from nastysloper/hash_ex.rb
learn ruby the hard way
cities = {'CA' => 'San Francisco', 'MI' => 'Detroit', 'FL' => 'Jacksonville'}
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
def find_city(map, state)
if map.include? state
return map[state]
else
return "Not found."
@mjhea0
mjhea0 / blackjack.rb
Last active December 17, 2015 04:39
dumb blackjack game that needs to be be refactured smarter - https://github.com/mjhea0/blackjack-sinatra
puts
print "What's your name? "
name = gets.chomp
puts "Hi, #{name}, welcome to Blackjack!"
puts
def random_cards()
first_card = Random.rand(1..10)
second_card = Random.rand(1..10)
return both_cards = {"first" => first_card, "second" => second_card}
@mjhea0
mjhea0 / divisible_by_seven.rb
Last active December 17, 2015 04:39
Using if statements, write a loop that prints out a range of numbers that can be divided by 7 without any remainder.
#Using if statements, write a loop that prints out a range of numbers
#that can be divided by 7 without any remainder.
def seven(nums)
for x in nums
puts x if x % 7 == 0
end
end
@mjhea0
mjhea0 / reverse_an_array_the_hard_way.rb
Last active December 17, 2015 04:39
reverse an array the hard way, using push and pop
def reverse_an_array_the_hard_way(array)
new_array = []
length = array.length
for x in (1..length)
new_array << array.pop
end
p new_array
end
@mjhea0
mjhea0 / ruby_recursion.rb
Created May 14, 2013 07:16
BASIC ruby recursion
def recurse(count=0)
return if count == 10
puts count
count += 1
recurse(count)
end
recurse
@mjhea0
mjhea0 / gist:5609403
Created May 19, 2013 22:57
recursion
http://www.backwardsteps.com/Recursion.pdf
@mjhea0
mjhea0 / 1 - sql_interview_questions.md
Last active November 10, 2023 01:06
Jitbit's SQL interview questions
@mjhea0
mjhea0 / python_blackjack.py
Last active May 1, 2024 17:03
python blackjack
import os
import random
deck = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]*4
def deal(deck):
hand = []
for i in range(2):
random.shuffle(deck)
card = deck.pop()
@mjhea0
mjhea0 / installing_easy_install_and_pip.md
Last active June 22, 2018 02:11
installing_easy_install_and_pip.md for unix environments or if you have cygwin installed on your PC

Watch the video if you need help. Keep in mind that your output will look different than mine as I already have these installed on my machine - http://screencast.com/t/NjkrLsKH1gZo

Setup Tools

  • Download setuptools for Python 2.7

      curl -o setuptools-0.6c11-py2.7.egg https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
    
  • Install setup tools