{{ message }}

Instantly share code, notes, and snippets.

# nbogie

Created Aug 17, 2011
scala 99 solns poor
View P99.scala
 object P1 { def sampleList() = List(1, 10, 100, 2, 20, 200, 5) def last[A](xs: List[A]): A = xs match { case Nil => sys.error("last on empty list") case x :: Nil => x case x :: rest => last(rest) }
Created Sep 7, 2011
poor soln h99 problems p28
View p28.hs
 import Data.List (elemIndex, sortBy, group, sort) import Data.Ord (comparing) import Data.Maybe (fromJust) main = print demo demo = lsort ["", "ab3","r3","fg3","d3","ijk1","mn","1", "abcdef1"] lsort :: (Ord a) => [[a]] -> [[a]] lsort xs = sortBy (comparing lfreq) xs where
Created Sep 13, 2011
poor soln h99 problemss: p56 - symmetrical binary trees
View p56.hs
 main = print \$ demo demo = isSym tree1 -- test data tree1 = (Branch 'x' (Branch 'x' Empty Empty) (Branch 'x' Empty Empty)) tree2 = (Branch 'x' (Branch 'x' Empty Empty) Empty) data Tree = Branch Char Tree Tree | Empty isSym :: Tree -> Bool
Created Oct 11, 2011
 -- Naive attempt at functional parsing -- (so there is lots of plumbing in each combinator) -- -- NOTE: This is NOT a good example of haskell to learn from. -- import qualified Data.Map as M import Prelude hiding ( (>>=), (>>), return) main = interact \$ unlines . map runTest . tail . lines
Created Nov 2, 2011
Question on typeclasses: Can we make all instances of Enum and Bool instances of Generator?
View typeclass_question.hs
 class Generator a where generate :: [a] data Media = Book | Video deriving (Enum, Bounded, Show) data Category = Fiction | NonFiction deriving (Enum, Bounded, Show) data Item = Item Media Category deriving (Show) instance Generator Media where generate = [minBound..maxBound]
Last active Jun 21, 2016
trim as regex in js
View trim.js
 function trim(str){ return str.replace(/^\s*((?:.|\n)*?)\s*\$/, "\$1"); } var testCases = [ [" a" , "a"], ["A " , "A"], [" a " , "a"], ["a b! " , "a b!"],
Last active Jul 5, 2016
Attempted recreation of @anuteja 's problem.
View problem.component.ts
 //Working towards a minimal demonstration of the problem. //This currently works as expected :( import { Component } from '@angular/core'; @Component({ moduleId: module.id, selector: 'problem', styles: [` .original { color: green; } .different { color: orange; } `],
Last active Feb 13, 2017
applescript and js for midipipe to play/pause youtube video in chrome via a midi event.