Skip to content

Instantly share code, notes, and snippets.

View jubishop's full-sized avatar
🎼
Making a podcast app.

Justin Bishop jubishop

🎼
Making a podcast app.
View GitHub Profile
@jubishop
jubishop / probs.rb
Created September 4, 2012 18:47
Girl Probability
girl = 0
boy = 1
at_least_one_girl = 0
all_girls = 0
1000000.times{
one_girl = false
num_girls = 0
3.times {
@jubishop
jubishop / Dollar.rb
Created September 16, 2015 02:59
Dollar class for dealing with dollars and cents without damnable floating points.
def Dollar(val)
Dollar.createRoundedDollar(val.kind_of?(Dollar) ? val.raw : val)
end
def getDollar
input = gets.chomp
return nil if (input.empty?)
Dollar.createRoundedDollar(input)
end
@jubishop
jubishop / Factors.rb
Created September 29, 2015 03:58
Factors Example
# This program is a demo of how to find factors for numbers
# But it's highly inefficient. Can you think of how to make it faster?
# Print message to ask the user for a number
puts 'What number shall we find factors for? '
# Get input from user and store in a variable we've decided
# to name number_to_factor.
# 'gets' is the name of the function that takes input from the user.
# By default 'gets' returns a variable that's called a "string" which means its just text
@jubishop
jubishop / Factors.rb
Created September 29, 2015 04:06
Factors
# This program is a demo of how to find factors for numbers
# Print message to ask the user for a number
puts 'What number shall we find factors for? '
# We want to get input from user and store in a variable.
# We've decided to name our variable number_to_factor.
# 'gets' is the name of the function that takes input from the user.
# By default 'gets' returns a variable that's called a "string" which means its just text.
# But we actually need our variable to be a number for calculations, so adding
puts 'What number shall we find factors for? '
number_to_factor = gets.to_i
puts "Factors for #{number_to_factor} are:"
1.upto(number_to_factor) { |number_to_test|
if (number_to_factor % number_to_test == 0)
puts number_to_test
end
@jubishop
jubishop / Factors.rb
Last active September 29, 2015 04:34
# This program is a demo of how to find factors for numbers
# Print message to ask the user for a number
# "puts" is shorthand for "put string".
# It's how we output text to the user.
puts "What number shall we find factors for? "
# We want to get input from the user and then store that input
# in a "variable" so that we can access it again later.
# We've decided to name our variable "number_to_factor".
require 'irb/completion'
require 'utility_belt'
require 'interactive_editor'
require 'awesome_print'
AwesomePrint.irb!
class Object
def interesting_methods
def expn(a, b)
a = a.to_r
b = b.to_i
d = 1.to_r
while(b > 0)
d *= a if (b % 2 == 1)
b /= 2
a *= a if (b > 0)
d = d.round(100)
@jubishop
jubishop / analysis.rb
Last active February 23, 2019 22:05
RL Replay Analysis
require 'json'
require 'PP'
class Player
attr_accessor :name, :assists, :goals, :saves, :score, :shots, :teamID
def initialize(stats)
@name = stats['Name']['value']['str']
@assists = stats['Assists']['value']['int']
@goals = stats['Goals']['value']['int']
@saves = stats['Saves']['value']['int']
class Point
attr_accessor :x, :y
def initialize(x, y)
@x = x
@y = y
end
def ==(point)
return (@x == point.x and @y == point.y)
end