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
genericMatchUp :: [ByteString] -> ByteString -> Bool | |
genericMatchUp pats = isJust . foldr1 (>=>) . fmap strip pats | |
strip :: ByteString -> ByteString -> Maybe ByteString | |
strip pat | |
| null pat = Just | |
strip pat = breaker | |
where | |
!patLen = length pat | |
searcher = nonOverlappingIndices pat |
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
-- Эта функция очень похожа на предыдущую. Она находит первое | |
-- вхожение подстроки и возвращает остаток | |
strip :: ByteString -> ByteString -> Maybe ByteString | |
strip pat | |
| null pat = Just | |
strip pat = breaker | |
where | |
!patLen = length pat | |
searcher = nonOverlappingIndices pat | |
breaker str = case searcher str of |
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
matchUp :: ByteString | |
-> ByteString | |
-> Bool | |
matchUp pat | |
| null pat = null | |
matchUp pat = searcher | |
where | |
searcher = case nonOverlappingIndicies pat of -- это библиотечная функция | |
[] -> False | |
_ -> True |
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
------------------ My code -------------------------- | |
fnv1aHash32Word32# :: Word# -> Word# -> Word# | |
fnv1aHash32Word32# base word = | |
let b0 = word `and#` 0xFF## | |
b1 = (word `uncheckedShiftRL#` 8#) `and#` 0xFF## | |
b2 = (word `uncheckedShiftRL#` 16#) `and#` 0xFF## | |
b3 = (word `uncheckedShiftRL#` 24#) `and#` 0xFF## | |
in base <<>> b0 <<>> b1 <<>> b2 <<>> b3 | |
where | |
(<<>>) = fnv1aHash32Base# |
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
hashBS :: ByteString -> Word32 | |
hashBS = B.foldl fnv1aHash32Base fnvOffsetBasis32 | |
hashBS_unpack :: ByteString -> Word32 | |
hashBS_unpack = foldl' fnv1aHash32Base fnvOffsetBasis32 . B.unpack | |
hashBS_С :: ByteString -> Word32 | |
hashBS_С bs = B.unsafeDupablePerformIO $! | |
B.unsafeUseAsCStringLen bs (\ (ptr, l) -> fnv1a_32 (castPtr ptr) l) |
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
--------------------- Idiomatic ------------------------ | |
fnvPrime32 :: Word32 | |
fnvPrime32 = 16777619 | |
fnvOffsetBasis32 :: Word32 | |
fnvOffsetBasis32 = 2166136261 | |
fnv1aHash32Word32 :: Word32 -> Word32 -> Word32 | |
fnv1aHash32Word32 base word = |
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
-- ghc 8.10.7 | |
-- Server code | |
runServer ctx = do | |
bracket (spawnWorkers ctx) (mapM_ killThread) $ const | |
liftIO $ useContext ctx -- At this point context looks uninialized | |
where | |
spawnWorkers = replicateM (ctx ^. number) (fork $ worker ctx) | |
-- The code that works with optimization disabled but but don't with optimization enabled |
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
{ | |
"languageserver": { | |
"haskell": { | |
"command": "haskell-language-server-wrapper", | |
"args": ["--lsp"], | |
"rootPatterns": [ | |
"*.cabal", | |
"stack.yaml", | |
"cabal.project", | |
"package.yaml", |
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
Возьмем для примера Influx Line Protocol, поскольку он прост. Приходят к нам в порт данные и | |
мы должны их как-то распарсить, а потом что-то с ними сделать. Для простоты возьмём только поля (Fileds) и засунем их | |
в Map. | |
> type Name = Text | |
> type Value = Text | |
> type Fields = Map Name Value | |
Это нетипизированные данные, а мы хотим прочитать оттуда RADIUS Packet Attributes которые весьма даже типизированны | |
https://hackage.haskell.org/package/radius-0.6.1.0/docs/Network-RADIUS-Types.html |
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
-- Вариант с последовательным поиском | |
lookupParam :: String -> [(String,String)] -> Maybe String | |
-- реализация | |
lookupEnvVar :: String -> [(String,String)] -> Maybe String | |
-- реализация | |
seqLookup :: String -> [(String,String)] -> [(String,String)] -> Maybe String | |
seqLookup paramName params envVars = do |
NewerOlder