Skip to content

Instantly share code, notes, and snippets.

View duncan's full-sized avatar
👋

Duncan Davidson duncan

👋
View GitHub Profile

Keybase proof

I hereby claim:

  • I am duncan on github.
  • I am duncan (https://keybase.io/duncan) on keybase.
  • I have a public key ASCDhRLbSB9ctsRt3iOIBe7XZgugq51c9x2YQHmEMPlSbQo

To claim this, I am signing this object:

@duncan
duncan / gist:e897d70e0772c42623b5
Last active August 29, 2015 14:02
Fun with Scala to run something only on a smallish percentage of times
import scala.util.Random
// extracted from a conversation between duncan, chad, and ryan. Don’t take seriously, OK? :)
if (scala.util.Random.nextBoolean && scala.util.Random.nextBoolean) {}
// OR
if((1 to 2).map { _ => scala.util.Random.nextBoolean }.foldLeft(true){(f, v) => f && v }) {}

Keybase proof

I hereby claim:

  • I am duncan on github.
  • I am duncan (https://keybase.io/duncan) on keybase.
  • I have a public key whose fingerprint is A8D9 5B27 516A 71CA 9935 BCBD 21CB 117E AA3D A070

To claim this, I am signing this object:

Orbiter:dailyshoot duncan$ rails c
Loading development environment (Rails 3.0.0)
# To set up this discussion, here's the time I'm running these examples at.
# It's almost 7PM Pacific on Weds, Sept 22.
ruby-1.9.2-p0 > Time.now
=> 2010-09-22 18:56:57 -0700
# Date.today is a Ruby core method. It does what you'd think
Octane:dailyshoot duncan$ rails c
Loading development environment (Rails 3.0.0)
ruby-1.9.2-p0 > Date.today
=> Fri, 17 Sep 2010
ruby-1.9.2-p0 > Date.tomorrow
=> Sun, 19 Sep 2010
ruby-1.9.2-p0 > Date.today + 1
=> Sat, 18 Sep 2010