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
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
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); |
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
(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))] |
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 | |
import Data.Char | |
main=interact$unlines.map(\x->case x of[]->"NONE";(x:_)->[x]).sortOn toLower.filter(`elem`"aeiouAEIOU")).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
-- 82 | |
main=interact$pure.head.foldl(\x y->tail$dropWhile (/=y) x) (cycle "JFMAMJJASOND") |
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
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 |
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
l=(`rem`10) | |
main=interact$show.l.foldr1((^).l).map read.words |
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.Char | |
import Data.List | |
main=interact$concat.(>>=uncurry (replicate.read).span isDigit).words |
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
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 |
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 (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 |
NewerOlder