Skip to content

Instantly share code, notes, and snippets.

Suan Yeo suan

Block or report user

Report or block suan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@suan
suan / gist:053fcf4fed8949545275f4553177af4e
Created Jul 9, 2017
Generate unemployment rate vs 3-year moving average chart
View gist:053fcf4fed8949545275f4553177af4e
#!/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 Apr 22, 2014
Rails timestamp with timezone investigation
View 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 Aug 16, 2013
Simple Infinite Array Ruby implementation
View gist:6247795
class InfiniteArray < Array
def initialize(value)
super(1, value)
end
def [](index)
self.first
end
end
@suan
suan / version_number_compare.rb
Created Jun 27, 2013
Compare 2 equal-length version numbers in Ruby
View version_number_compare.rb
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 Dec 17, 2015 — forked from courtenay/STDOUT
View 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>
You can’t perform that action at this time.