This file contains hidden or 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
-- given a file, read lines and then return unique entries (remove/ignore duplicates) | |
-- outputs cleaned file in same folder: f_name.ext -> f_name_cleaned.ext | |
-- caveat: please us absolute path | |
-- usage example: runhaskell kern_dedupe.hs /home/path/to/paths.txt | |
import System.Environment (getArgs) | |
import Data.List.Split (splitOn) | |
import Data.List (nub, intercalate) | |
main :: IO () |
This file contains hidden or 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
-- using scotty or yesod without the scaffolding etc... still wants minified js? | |
-- usage example: runhaskell minify.hs /path/to/js/myfile.js | |
-- output: myfile-min.js in same folder | |
-- requirements: cabal install hjsmin | |
import System.Environment (getArgs) | |
import Text.Jasmine (minifyFile) | |
import Data.List.Split (splitOn) | |
import qualified Data.ByteString.Lazy as Bsl | |
This file contains hidden or 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
-- prints out article: link (score) if score > n | |
import Network.Curl | |
import Text.XML.HXT.Core | |
import Control.Monad | |
import Control.Applicative | |
import Data.List (isInfixOf, isPrefixOf) | |
getHtmlRespOnly :: (CurlCode, String) -> String | |
getHtmlRespOnly (_, s) = s |
This file contains hidden or 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
<html> | |
<head> | |
<title>hello</title> | |
</head> | |
<body> | |
<h1>hello</h1> | |
<p>this is a html webpage.</p> | |
</body> | |
</html> |
This file contains hidden or 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 Network.Curl | |
import Text.XML.HXT.Core | |
import Control.Monad | |
import Data.List (isPrefixOf) | |
getHtmlRespOnly :: (CurlCode, String) -> String | |
getHtmlRespOnly (_, s) = s | |
main :: IO () | |
main = do |
This file contains hidden or 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
-- consider function f, which evaluates to its argument multiply by 7 | |
ghci> let f = (\f -> f * 7) | |
ghci> f 8 | |
56 | |
-- let's consider another function g, which evaluates the argument mod by 7 | |
ghci> let g = (\g -> g `mod` 7) | |
ghci> g 70 | |
0 |
This file contains hidden or 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
-- extensions | |
{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies, MultiParamTypeClasses #-} | |
-- call the boss! | |
import Yesod | |
import Yesod.Static | |
staticFiles "static" | |
data NorthPole = NorthPole |
This file contains hidden or 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
-- 3sum | |
type TripleInt = (Integer, Integer, Integer) | |
threesum :: [TripleInt] -> Integer | |
threesum [] = 0 | |
threesum ((x,y,z):xs) | x + y + z == 0 = 1 + threesum xs | |
| otherwise = 0 + threesum xs |
This file contains hidden or 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
-- backwards substitution solving | |
type LEq = [Double] | |
type Sol = Double | |
type XVec = [Double] | |
bsolve' :: [LEq] -> [Sol] -> XVec -> XVec | |
bsolve' _ [] _ = [] | |
bsolve' (x:xs) (y:ys) v = let | |
x' = dropWhile (\x -> x == 0) x |
This file contains hidden or 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 Euterpea | |
t251 :: Music Pitch | |
t251 = let dMinor = d 4 wn :=: f 4 wn :=: a 4 wn | |
gMajor = g 4 wn :=: b 4 wn :=: d 5 wn | |
cMajor = c 4 bn :=: e 4 bn :=: g 4 bn | |
in dMinor :+: gMajor :+: cMajor | |
-- solution for exercise 2.1 |