Skip to content

Instantly share code, notes, and snippets.

@iamvery
iamvery / languages.md
Created October 23, 2014 16:27
Programming languages are good at things

Elixir

Functional programming for a Rubyist

Go

Command-line programs

Haskell

@iamvery
iamvery / quicksort.rb
Last active August 29, 2015 14:07
Quicksort in Ruby
def qsort(list)
return list if list.empty?
x, *xs = list
smaller, larger = xs.partition { |n| n < x }
qsort(smaller) + [x] + qsort(larger)
end
describe 'qsort' do
require 'parslet'
class FooParser < Parslet::Parser
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
rule(:dot) { str('.') >> space? }
rule(:colon) { str(':') >> space? }
rule(:comma) { str(',') >> space? }
rule(:comma?) { comma.maybe }
@iamvery
iamvery / dat-time.rb
Last active August 29, 2015 14:06
Buggy date behavior in Rails 3. Appears to be fixed in Rails 4. When zoned time is a different date from UTC, it is persisted incorrectly.
Loading development environment (Rails 3.2.19)
irb(main):001:0> Time.zone
=> #<ActiveSupport::TimeZone:0x007fa2e4533d68 @name="Osaka", @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: Asia/Tokyo>, @current_period=nil>
irb(main):002:0> p = Plan.new
=> #<Plan id: nil, decided_on: nil>
irb(main):003:0> time = 1.day.ago
=> Fri, 26 Sep 2014 06:31:54 JST +09:00
irb(main):004:0> time.to_date
###
=> Fri, 26 Sep 2014
@iamvery
iamvery / Gemfile
Last active August 29, 2015 14:06
Scopes behavior in ActiveRecord 4
source 'https://rubygems.org'
gem 'activerecord', '~>4.0'
gem 'sqlite3'
@iamvery
iamvery / Gemfile
Last active August 29, 2015 14:06
Scopes behavior in ActiveRecord 3
source 'https://rubygems.org'
gem 'activerecord', '~>3.0'
gem 'sqlite3'
source 'https://rubygems.org'
gem 'activerecord'
gem 'sqlite3'
params = { some: :thing }
oops = {}
def kwargs(some:)
puts some
end
def hash(args)
puts args.fetch(:some)
end
@iamvery
iamvery / foo.rb
Last active August 29, 2015 14:06
require 'active_record'
class Foo < ActiveRecord::Base
establish_connection adapter: 'sqlite3', database: ':memory:'
connection.create_table :foos do |t|
t.string :name, null: false
end
#has_many :bars
@iamvery
iamvery / conway.coffee
Created June 3, 2014 18:59
Game of Life WIP with @nybblr
# Live cells with < 2 living neighbors dies to underpop
# > 3 living neighbors dies to overpop
# Otherwise, lives!
#
# Dead cells with exactly 3 living neighbors is born
# . 0 .
# . 0 .
# . 0 .
#