Skip to content

Instantly share code, notes, and snippets.

View snelson's full-sized avatar

Scotty Nelson snelson

View GitHub Profile
@snelson
snelson / gilded_rose.rb
Created April 15, 2020 12:41
Implementation of Gilded Rose
module GildedRose
def self.new(name:, days_remaining:, quality:)
item_class = case name
when "Aged Brie"
AgedItem
when "Sulfuras, Hand of Ragnaros"
LegendaryItem
when "Backstage passes to a TAFKAL80ETC concert"
BackstagePass
when "Conjured Mana Cake"
$(document).on 'click', 'a', (e) ->
$link = $(e.currentTarget)
href = $link.attr('href')
# we only care about links with http protocol
isHttp = $link.prop('protocol').indexOf('http') == 0
# we only care about links to html pages
allowedFormats = ['html']
format = getFormatFromUrl(href)
class App.Router extends Backbone.Router
initialize: (options) ->
# keep track of the first route event so that
# loadNormally doesn't get stuck in an infinite
# redirect loop
@isFirstRoute = true
@once 'route', =>
@isFirstRoute = false
class ApplicationController < ActionController::Base
layout :determine_layout
private
def determine_layout
request.headers['X-PJAX'] ? false : "application"
end
end
$(document).pjax('a', '#pjax-container');
class ApplicationController < ActionController::Base
# ...
around_action :with_timezone
private
def with_timezone
timezone = Time.find_zone(cookies[:timezone])
Time.use_zone(timezone) { yield }
var tz = jstz.determine();
tz.name(); // returns "America/Los Angeles"
@snelson
snelson / contract.md
Last active June 2, 2020 18:06
Contract

[LOGO]

[ADDRESS]

[PHONE]

[CONTACT EMAIL]

[DATE]

@snelson
snelson / banksimple_json_to_ynab_csv.rb
Created July 18, 2013 16:36
A script to convert Simple.com JSON transaction export to a CSV for importing into YNAB.
require 'json'
require 'csv'
class SimpleJsonExport
def initialize(filepath)
@filepath = filepath
end
def transactions
@transactions ||= data['transactions'].collect do |transaction|