Skip to content

Instantly share code, notes, and snippets.

View chessai's full-sized avatar

chessai chessai

View GitHub Profile
@chessai
chessai / ParseFooA.core
Created January 9, 2019 18:11
fixedparser core inspection
[1 of 1] Compiling ParseFooA ( foo.hs, foo.o )
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 816, types: 382, coercions: 40, joins: 0/9}
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
$trModule4
$trModule4 = "main"#
[chessai@chessai-kudu:~/Development/summoner/summoner-cli]$ cat default.nix
{ compiler ? "ghc863" }:
with rec {
pkgs = (import ./nix/nixpkgs.nix {
inherit compiler;
});
drv = pkgs.haskellPackages.summoner-cli;
};
[nix-shell:~/Development/containers]$ ./dist/build/sequence-benchmarks/sequence-benchmarks
benchmarking splitAt/append/10
time 691.1 μs (690.4 μs .. 692.4 μs)
1.000 R² (1.000 R² .. 1.000 R²)
mean 693.1 μs (691.5 μs .. 696.5 μs)
std dev 7.658 μs (2.571 μs .. 12.73 μs)
benchmarking splitAt/append/100
time 4.301 ms (4.295 ms .. 4.308 ms)
1.000 R² (1.000 R² .. 1.000 R²)
@chessai
chessai / ByteArrayToByteString.hs
Created January 18, 2019 22:30
convert a (pinned) bytearray to a bytestring without copying
byteArrayToByteString :: ByteArray -> ByteString
byteArrayToByteString (ByteArray b#) =
let contents# = byteArrayContents# b#
fp = ForeignPtr contents# (PlainPtr (byteArrayToMutableByteArray b#))
len = lenAddr contents#
in PS fp 0 len
byteArrayToMutableByteArray :: ByteArray# -> MutableByteArray# RealWorld
byteArrayToMutableByteArray = unsafeCoerce#
fibs10 :: [NUI]
fibs10 = take 10 fibs
fibs :: [NUI]
fibs = unPolynomial $ star (Polynomial [NUI 0, NUI 1, NUI 1])
-- | \mathbb{N} \bigcup \infty
data NUI = NUI Word | Inf
deriving (Eq, Show)
-- | JSON parse helper.
--
-- data Foo = Foo { fooIntBar :: Int, fooStringBar :: String }
-- deriving (Generic)
--
-- -- This will make 'Foo''s fields get parsed as
-- -- 'int_bar', 'string_bar', etc.
-- instance FromJSON Foo where
-- parseJSON = parseJSONFielded
parseJSONFielded :: forall a. (Generic a, Typeable a, AE.GFromJSON AE.Z
@chessai
chessai / ci.sh
Last active January 30, 2019 15:28
# recursively replace all occurrences of something.
find dir -type f -name '*.hs' -print0 | \\
xargs -0 sed -i 's/Find/Replace/g'
# recursively remove all trailing whitespace
find dir -type f -print0 | \\
xargs -0 sed -i 's/[ \t]*S//'
# recursively add newlines to the end of files that don't have them.
find dir -type f -print0 | xargs -0 sed -i -e '$a\'
reverseBits :: Word8 -> Word8
reverseBits b' =
let b = fromIntegral b' :: Word32
!x = ((((b * 0x0802 .&. 0x22110) .|. ((b * 0x8020) .&. 0x88440)) * 0x10101) `unsafeShiftR` 16
in fromIntegral x
{-# language BangPatterns #-}
{-# language ScopedTypeVariables #-}
{-# language UnboxedTuples #-}
module Array (mapMaybe) where
import Control.Monad.ST
import Data.Primitive.Array
data Alls = AllNothing | NotAllNothing
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.choogle;
hoogleEnv = pkgs.buildEnv {
name = "hoogle";