Skip to content

Instantly share code, notes, and snippets.

@fj
fj / gist:5191226
Created March 18, 2013 22:04
My git alias for logs.
log --format=format:\"%C(yellow bold)%h%Creset @ %C(blue)%cd%C(reset) » %C(white)%s%C(reset) (%C(green)%cN%C(reset)) %+d\" --topo-order --graph --date=iso
@fj
fj / gist:5060434
Created February 28, 2013 21:53
Andrew Mason's firing letter from Groupon. February 28, 2013.
(This is for Groupon employees, but I’m posting it publicly since it will leak anyway)
People of Groupon,
After four and a half intense and wonderful years as CEO of Groupon, I’ve decided that I’d like to spend more time with my family. Just kidding – I was fired today. If you’re wondering why… you haven’t been paying attention. From controversial metrics in our S1 to our material weakness to two quarters of missing our own expectations and a stock price that’s hovering around one quarter of our listing price, the events of the last year and a half speak for themselves. As CEO, I am accountable.
You are doing amazing things at Groupon, and you deserve the outside world to give you a second chance. I’m getting in the way of that. A fresh CEO earns you that chance. The board is aligned behind the strategy we’ve shared over the last few months, and I’ve never seen you working together more effectively as a global company – it’s time to give Groupon a relief valve from the public noise.
For those who are conc

Retrieval of an arbitrary item from a linked list is O(n). Arbitrary means any of the elements are eligible for selection, without loss of generality.

However, retrieval of a specific item from a linked list has nothing to do with how many items are in the list. It is therefore O(1). Retrieving the 50th item from a linked list takes the same amount of time, no matter whether the list has 50 elements, 50M elements, or 50^50! elements.

@fj
fj / example_spec.rb
Created December 12, 2012 20:11
Prove control was yielded to a block via a particular mechanism
class C
def x(&block)
instance_eval &block if block_given?
end
end
describe C do
describe "#x" do
it "executes the block" do
expect{ |p| described_class.x &p }.to yield_control

The Yudkowsky ambition scale for startup pitches; each level is about five to ten times harder to reach than the previous level, and produces about five to ten times as much change in the world as we know it.

  1. "We're going to build the next Facebook!"
  2. "We're going to found the next Apple!"
  3. "Our product will create sweeping political change! This will produce a major economic revolution in at least one country!"
  4. "Our product is the next nuclear weapon. You wouldn't want that in the wrong hands, would you?"
  5. "This is going to be the equivalent of the invention of electricity if it works out."
  6. "We're going to make an IQ-enhancing drug and produce basic change in the human condition."
  7. "We're going to build serious Drexler-class molecular nanotechnology."
  8. "We're going to upload a human brain into a computer."
@fj
fj / gist:3800120
Created September 28, 2012 14:13
Why time zones suck
# Ψ irb --prompt=simple
require 'tzinfo'
# => true
tz = TZInfo::Timezone.get 'Asia/Shanghai'
# => #<TZInfo::DataTimezone: Asia/Shanghai>
tz.local_to_utc Time.mktime(1927, 12, 31, 23, 54, 5)
# => 1927-12-31 15:48:13 UTC

Initially, these four outcomes are equally probable:

older child   younger child
-----------   -------------
    boy            boy         P = 1/4
    boy            girl        P = 1/4
    girl           boy         P = 1/4
    girl           girl        P = 1/4

Now I tell you that one of the children is a boy:

@fj
fj / gist:3274650
Created August 6, 2012 14:03
Comparing Curiosity landing to getting a hole-in-one

Comparing Curiosity landing to getting a hole-in-one

Questions? Ask @superninjarobot.

Some initial data

Golf

  • Size of a golf hole: 11 cm
  • Typical distance of a par-5 golf hole: 425 m
@fj
fj / gist:3140725
Created July 19, 2012 04:20
Unsolvable Ruby Problems example

This example just uses composition: define the methods you like on an Extended object and use those.

class Extended
  def initialize(array)
    @array = array
  end

  def scale(k)
 self.tap do |o|

A representative but thoroughly useless and unscientific way to see how people write short pieces of code.

Write a function, method, or other similar construct in your favorite language that:

  • accepts an array arr and a value v
  • returns the element in arr whose successor is v, if there is such an element; otherwise return nothing

Test cases: