Skip to content

Instantly share code, notes, and snippets.

View aubreylouw's full-sized avatar

Aubrey Louw aubreylouw

  • Chicago, IL
View GitHub Profile
@aubreylouw
aubreylouw / gist:5479588
Created April 29, 2013 03:42
Scala unzip
/* unzip decomposes a list of pairs into a pair of lists.
* The recursive case illustrates pattern-matching the result of the
* recursive call in order to apply an operation to the elements.
*/
def unzip [X,Y] (ps:List[(X,Y)]) : (List[X], List[Y]) = ps match {
case Nil => (Nil, Nil)
case (x, y) :: qs => {
val (xs, ys) = unzip (qs)
(x :: xs, y :: ys)
}
@aubreylouw
aubreylouw / gist:5479552
Created April 29, 2013 03:27
99 Scala problems -> problem 15
def duplicateN [X] (n:Int, xs:List[X]) : List[X] = (n, xs) match {
case (n, xs) if n < 0 => throw new RuntimeException ("illegal op: negative N")
case (_, Nil) => xs
case (0|1, xs) => xs
case (_, h::t) => (h::Nil) ::: copyN(n-1, h::Nil) ::: copyN(n,t)
}
@aubreylouw
aubreylouw / gist:5479547
Last active December 16, 2015 18:39
Scala: recursive & tail recursive list reversals
/* Not tail recursive. */
def reverseSlow [X] (xs:List[X]) : List[X] = xs match {
case Nil => Nil
case y :: ys => reverseSlow (ys) ::: List (y)
}
/* Tail recursive. */
def reverseFast [X] (xs:List[X]) : List[X] = {
def aux (xs:List[X], result:List[X]) : List[X] = xs match {
case Nil => result
@aubreylouw
aubreylouw / WidenNamedRangeListBox
Created May 31, 2012 15:15
VBA - Excel - Widen NamedRange Listbox
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _