Skip to content

Instantly share code, notes, and snippets.

@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 / 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
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 / 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
@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 / bio.md
Last active August 29, 2015 14:09
Conference abstracts

Bio

I have been programming for about 10 years. 3 of those years I have been writing Ruby. Recently I have developed a deep interest in good software design, appropriate levels of testing, and other programming paradigms.

I am a consultant and (Ruby) instructor at Big Nerd Ranch. I am one of a handful of nerds that who works remotely full-time. I love working remotely, but it is not without its challenges! My wife

@iamvery
iamvery / things.md
Last active August 29, 2015 14:13
Things done.

I've done things.

I'm not a huge fan of resumes, but alas I do, in fact, do (and have done) things in case you're interested. Find me at http://iamvery.com.

Dynetics 2006-2010

IT Support

  • helped users with day-to-day issues involving their desktop and network
  • deployed new VOIP phones
@iamvery
iamvery / .rspec
Last active August 29, 2015 14:15
app configuration files
--color
-r turnip/rspec
@iamvery
iamvery / deduce.swift
Last active August 29, 2015 14:16
Extend Swift's Array#reduce behavior to provide reasonable initial values
extension Array {
func deduce (initial: T? = nil, _ combine: (T, T) -> T) -> T? {
if let initial = initial {
return reduce(initial, combine: combine);
}
if count > 1 {
var rest = self[1..<count]
return rest.reduce(first!, combine: combine)
} else {

Rubyist Does Swift

The most fundamental concepts in Swift that should be presented up front:

  • variables and constants
  • type safety
  • type inference

Helpful:

  • println
  • assert