Skip to content

Instantly share code, notes, and snippets.

View garrettgsb's full-sized avatar

Garrett B garrettgsb

  • Vancouver | Beijing
View GitHub Profile
@garrettgsb
garrettgsb / dontstopbelievin.py
Created December 8, 2018 00:29
How many words are in Don't Stop Believin'?
dsb = """Just a small town girl
Livin' in a lonely world
She took the midnight train goin' anywhere
Just a city boy
Born and raised in South Detroit
He took the midnight train goin' anywhere
A singer in a smokey room
The smell of wine and cheap perfume
@garrettgsb
garrettgsb / xml_scrubber.rb
Created July 13, 2016 23:31
Removes values from XML, leaving just the tree.
# Parses XML file with Nokogiri,
# removes text from all nodes,
# prints out new 'clean' file
# Change 'input.xml' to whatever
# file you want to scrub.
require 'nokogiri'
doc = File.open('input.xml') {|f| Nokogiri::XML(f)}
doc.traverse{|node| node.content = "" if node.class == Nokogiri::XML::Text}
contract NotFizzBuzz {
//By Garrett B
function selectionSort(uint[] x) returns (uint[]){
uint length = x.length;
for (var i = 0; i < length-1; i++) {
for (var j = i; j < length; j++) {
if (x[i] > x[j]) {
uint a = x[i];
uint b = x[j];
@garrettgsb
garrettgsb / .DS_Store
Last active May 13, 2016 00:21
Contact Manager
require 'pry-nav'
module Can_fly
def initialize
@flight = "Hell yeah"
end
def can_fly?
true
end
def newBottle(b, p) # b = number of bottles, t = type of trade
@bottle_tally += 1
@bottlecaps += 1
@emptybottles += 1
@report = "F: #{@bottle_tally} E: #{@emptybottles} Caps: #{@bottlecaps}"
if p == true
puts "#{@report} New bottle purchased."
elsif p == false
puts "#{@report} New bottle redeemed."
end
require "pry-nav"
##TODO: Refactor such that there is a "Player" class that has attributes for
## 'lives' and 'score,' put players in a "players" array and iterate through
## it to pass turns.
class Game
def initialize
@player_1_lives,
@garrettgsb
garrettgsb / counting_chars.rb
Created April 27, 2016 21:24
Counting Characters
require 'pry'
## Counts characters, omitting spaces
def char_count(target)
target = target.gsub(" ","")
tally = Hash.new(0)
target.each_char {|x| tally[x] += 1}
tally
end
puts char_count('Chi putao bu tu putao pi')
@garrettgsb
garrettgsb / max.rb
Created April 26, 2016 19:53
Maximum Value
# Find the maximum
def maximum(arr)
# My first method... Uses 0 as a default value, so
# kind of doesn't work for an array full of elements
# that are less than zero.
y = 0
arr.each do |x|
if x > y
y = x
@garrettgsb
garrettgsb / vancouver_yuppie.rb
Created April 26, 2016 19:52
Vancouver Yuppie
# must be baller and either furnished or rent cheaper than 2100
def rent?(baller, furnished, rent)
# This is going to evaluate to either true or false anyway,
# so we don't need to explicitly return true or false.
baller && (furnished || rent < 2100)
# Old clunky version
# if baller && (furnished || rent < 2100) # <--Put brackets around this bad boy