This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trim(str){ | |
return str.replace(/^\s*((?:.|\n)*?)\s*$/, "$1"); | |
} | |
var testCases = [ | |
[" a" , "a"], | |
["A " , "A"], | |
[" a " , "a"], | |
["a b! " , "a b!"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; } | |
`], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on runme(message) | |
tell application "Google Chrome" | |
if (item 1 of message = 191) then | |
# Play or pause a video. | |
repeat with t in tabs of windows | |
tell t | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on runme(message) | |
tell application "Google Chrome" | |
if (item 1 of message = 191) then | |
# Play or pause a video. | |
repeat with t in tabs of windows | |
tell t | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#VLC is bad at being controlled by applescript. | |
# Consider instead using Transcribe! for studying videos - it offers lots of midi control. | |
#returns true if the message represents a positive change of | |
# the given controller number, as will happen when depressing buttons a midi keyb. | |
# We ignore messages with value bytes 0, as those are sent on button releases. | |
on isMidiButtonPressed(msg, controllerNumber) | |
return (isControlChange(msg, controllerNumber) and (item 3 of msg > 0)) | |
end isMidiButtonPressed |