Skip to content

Instantly share code, notes, and snippets.

Embed File in template haskell 2.16.0 and up

embedFile :: FilePath -> Q Exp
embedFile fp = do
    T.qAddDependentFile fp                    -- adding a file dependency for reloading
    bs <- T.runIO $ B.readFile fp             -- runIO to run IO in the Q Monad
    [|unsafePerformIO $ unsafePackAddressLen $(size bs) $(bytes bs)|]
  where
    size  = pure . T.LitE . T.integerL . fromIntegral . B8.length
const defaultChunkSize = 1 * 1024 * 1024; // 1 MB
const chunkBlob = ({chunkSize = defaultChunkSize, blob}) => {
function* go(offset, chunkId) {
if(offset < blob.size) {
const nextOffset = offset + chunkSize + 1;
yield {
chunkId,
chunk: file.slice(offset, nextOffset)
};
yield* go(nextOffset, chunkId + 1);
(ns Solution
(:gen-class))
(defn -main [& args]
(let [keys {\^ [0 1]
\> [1 0]
\v [0 -1]
\< [-1 0]}
f (fn [position key]
(map + (keys key) position))]
import Data.List
import Data.Char
main=interact$unlines.map(\x->case x of[]->"NONE";(x:_)->[x]).sortOn toLower.filter(`elem`"aeiouAEIOU")).tail.lines
-- 82
main=interact$pure.head.foldl(\x y->tail$dropWhile (/=y) x) (cycle "JFMAMJJASOND")
l1 f (a,b)=(f a,b)
g "inc"=l1 (+1)
g "dec"=l1 (subtract 1)
g "double"=l1 (*2)
g "half"=l1 (`div`2)
g "print"=\(v,s)->(v,s<>show v)
main=interact$snd.foldl (flip g) (0,"").takeWhile (/="exit").words
l=(`rem`10)
main=interact$show.l.foldr1((^).l).map read.words
import Data.Char
import Data.List
main=interact$concat.(>>=uncurry (replicate.read).span isDigit).words
resolver: lts-16.1
packages:
- .
extra-deps:
- ghcjs-dom-0.9.4.0
- jsaddle-warp-0.9.7.0
- warp-3.2.28
- http2-1.6.5
- ghcjs-dom-jsaddle-0.9.4.0
- jsaddle-0.9.7.0
import Data.List (intercalate)
consecutivesStrings :: [Int] -> String
consecutivesStrings = intercalate "," . map f . groupBy' (\a b -> a + 1 == b)
where
f [x] = show x
f xs = "[" ++ show (head xs) ++ "-" ++ show (last xs) ++ "]"
groupBy' :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy' p (x : xs) = go [x] xs