Skip to content

Instantly share code, notes, and snippets.

@suan
suan / gist:053fcf4fed8949545275f4553177af4e
Created July 9, 2017 19:51
Generate unemployment rate vs 3-year moving average chart
#!/usr/bin/env ruby
require "json"
require "date"
require "rest-client"
require "axlsx"
BLS_REGISTRATION_KEY = "<get your own from https://data.bls.gov/registrationEngine/>"
# How many spreadsheet rows before the data actually starts
TABLE_OFFSET = 1
@suan
suan / Rails timestamp with timezone investigation
Created April 22, 2014 17:13
Rails timestamp with timezone investigation
# Rails 3
class CreateFoo < ActiveRecord::Migration
def up
create_table :foos
execute "alter table foos add column created_at timestamp with time zone"
execute "alter table foos add column updated_at timestamp with time zone"
end
def down
drop_table :foos
@suan
suan / gist:6247795
Created August 16, 2013 06:46
Simple Infinite Array Ruby implementation
class InfiniteArray < Array
def initialize(value)
super(1, value)
end
def [](index)
self.first
end
end
@suan
suan / version_number_compare.rb
Created June 27, 2013 04:00
Compare 2 equal-length version numbers in Ruby
class VersionNumber
include Comparable
attr_reader :version_parts
def initialize version_string
@version_parts = version_string.split(/[a-zA-Z]/).first.split('.').map(&:to_i)
end
def <=> other
@version_parts.each_with_index do |version_part, i|
@suan
suan / STDOUT
Last active December 17, 2015 23:58 — forked from courtenay/STDOUT
# output
> gh = Redcarpet::Render::GithubStyleTitles.new
> puts Redcarpet::Markdown.new(gh).render "test\n\n# test 1\n\n# test 2\n\n# test 1\n\n# test 1"
=>
<a name="test-1" class="anchor" href="#test-1"><span class="anchor-icon"></span></a><h1 id="test-1">test 1</h1>
<a name="test-2" class="anchor" href="#test-2"><span class="anchor-icon"></span></a><h1 id="test-2">test 2</h1>