Skip to content

Instantly share code, notes, and snippets.


Garrett B garrettgsb

  • Vancouver | Beijing
View GitHub Profile
garrettgsb /
Created Dec 8, 2018
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 / xml_scrubber.rb
Created Jul 13, 2016
Removes values from XML, leaving just the tree.
View xml_scrubber.rb
# 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 ='input.xml') {|f| Nokogiri::XML(f)}
doc.traverse{|node| node.content = "" if node.class == Nokogiri::XML::Text}
View NotFizzBuzz.sol
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];
View zoodles.rb
require 'pry-nav'
module Can_fly
def initialize
@flight = "Hell yeah"
def can_fly?
View poppin_bottles.rb
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."
View math_game.rb
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
View counting_chars.rb
require 'pry'
## Counts characters, omitting spaces
def char_count(target)
target = target.gsub(" ","")
tally =
target.each_char {|x| tally[x] += 1}
puts char_count('Chi putao bu tu putao pi')
garrettgsb / max.rb
Created Apr 26, 2016
Maximum Value
View max.rb
# 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
View vancouver_yuppie.rb
# 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