Skip to content

Instantly share code, notes, and snippets.

-- 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 ()
-- 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
-- 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
<html>
<head>
<title>hello</title>
</head>
<body>
<h1>hello</h1>
<p>this is a html webpage.</p>
</body>
</html>
-- 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
-- extensions
{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies, MultiParamTypeClasses #-}
-- call the boss!
import Yesod
import Yesod.Static
staticFiles "static"
data NorthPole = NorthPole
-- 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
-- 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
@qoelet
qoelet / t251.hs
Last active December 21, 2015 16:39
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