Skip to content

Instantly share code, notes, and snippets.

View JohnFord's full-sized avatar

John Ford JohnFord

View GitHub Profile

Keybase proof

I hereby claim:

  • I am johnford on github.
  • I am bc_johnford (https://keybase.io/bc_johnford) on keybase.
  • I have a public key ASAM63beLhMhbeal0ASFwb1cpM6Z3FTdPDPAlVwMxwuQuQo

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am johnford on github.
* I am ghettocode (https://keybase.io/ghettocode) on keybase.
* I have a public key ASBk4vB1sOyTElveKVCD8XviX05du-Mch1Oomlc_zr2I-Qo
To claim this, I am signing this object:
@JohnFord
JohnFord / gist:48c701741417476e2eca
Created September 2, 2014 18:45
Unzip a list of List[List[Any]]?
import scala.collection.mutable.ListBuffer
val diffs: ListBuffer[List[Any]] = new ListBuffer[List[Any]]()
diffs.append(List("field1", 1, 2))
diffs.append(List("field2", 3, 4))
diffs.append(List("field3", 5, 6))
/* At this point, I'd like to do something like: diffs.toList.unzip and wind up with List("field1", "field2", "field3"), List((1,2), (3,4), (5,6))
But that thows an exception: "error: No implicit view available from List[Any] => (A1, A2)." */
@JohnFord
JohnFord / doit.rb
Created April 28, 2012 23:13
Challenge from a friend: "Design a function that selects the top k from n items using a reduce." This is my naive 5-min solution.
def doit(k, array)
array.reduce([]) do |memo,o|
if memo.length < k
memo << o
elsif (min = memo.min) < o
memo[memo.index(min)] = o
end
memo
end
end
@JohnFord
JohnFord / multi_store_finder.rb
Created April 17, 2011 04:13 — forked from sarchertech/multi_store_finder.rb
An atlrug member asked for a code-review so I made a couple of changes and suggestions
require 'yaml'
class Store
attr_accessor :name, :address, :city, :state, :zip, :phone_number
end
def list_of_stores
files = Dir.glob('*.yml')
stores = []