Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am benjamin-bader on github.
  • I am bendb ( on keybase.
  • I have a public key whose fingerprint is 0E1F CB12 79F1 21EB F2B1 123F 6681 E17F 3BEA EF7F

To claim this, I am signing this object:

// DSMainViewController.m
// VideoGenie
// Created by Benjamin Bader on 1/29/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
#import "DSMainViewController.h"
open System
open System.IO
let trainingDataFile = @"C:\Users\ben\Downloads\digitssample.csv"
type ImageData = {
ActualNumber: byte
Pixels: float []
benjamin-bader / gist:4049674
Created November 10, 2012 02:58
Pairing operator in F#
// 'a seq -> ('a * 'a) seq
let pair (series: 'a seq) = seq {
use enum = series.GetEnumerator()
if enum.MoveNext() then
let first = ref (Some enum.Current)
while enum.MoveNext() do
if Option.isSome !first then
yield (Option.get !first), enum.Current
first := None
benjamin-bader / interleave.cs
Created April 24, 2012 00:37
Interleave operator
public static IEnumerable<T> Interleave<T>(this IEnumerable<T> collection, IEnumerable<T> other, int thisCount, int thatCount)
if (collection == null)
throw new ArgumentNullException("collection");
if (other == null)
throw new ArgumentNullException("other");
if (thisCount < 1)
throw new ArgumentOutOfRangeException("thisCount", thisCount, "Must be greater than zero.");
benjamin-bader / cycle.cs
Created April 24, 2012 01:00
Cycle operator
public static IEnumerable<T> Cycle<T>(this IEnumerable<T> collection, bool forceToList = false)
var list = collection as IList<T>;
if (list != null)
return CycleList(list);
return forceToList
benjamin-bader / partition.cs
Created April 22, 2012 22:49
Partition Operator
public static IEnumerable<IList<T>> Partition<T>(this IEnumerable<T> collection, int windowSize)
if (collection == null)
throw new ArgumentNullException("collection");
List<T> list;
using (var enumerator = collection.GetEnumerator())
// Break on an empty sequence to avoid a pointless allocation.
if (!enumerator.MoveNext())
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;