Skip to content

Instantly share code, notes, and snippets.

View Elvecent's full-sized avatar

Kirill Valiavin Elvecent

View GitHub Profile
@Elvecent
Elvecent / Main.hs
Last active August 10, 2022 06:11
lens-aeson madness
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Data.Foldable
import Data.Aeson.Lens
import Data.Aeson.Encode.Pretty
import Data.Aeson.QQ
import Control.Lens
@Elvecent
Elvecent / setup.el
Created May 30, 2022 19:54
Org roam setup
(use-package org
:config
(add-hook 'text-mode-hook #'visual-line-mode)
:custom
(org-hide-leading-stars 't)
(org-startup-folded 'content ))
(use-package org-roam-ui)
(defun my-org-journal-new-entry (prefix)
@Elvecent
Elvecent / Main.hs
Created October 25, 2021 08:37
Reflex collection of counters
data AddRemove = Add Int | Remove Int deriving Show
currentId :: AddRemove -> Int
currentId = \case
Add n -> n
Remove n -> n
toMap :: AddRemove -> M.Map Int (Maybe ())
toMap = \case
Add n -> M.singleton n (Just ())
@Elvecent
Elvecent / Main.hs
Last active October 5, 2021 08:33
Async fused
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@Elvecent
Elvecent / Main.hs
Last active March 20, 2021 10:02
Selecting
import Control.Lens
import Data.Monoid
import Data.List.Extra
import Data.Foldable
select as fbs f s =
flip as s $ \a -> a <$ (
flip (fbs a) s $ \b ->
snd <$> f (a,b)
)
@Elvecent
Elvecent / Main.hs
Last active March 20, 2021 09:54
Parsing
import Data.Void
import Text.Megaparsec
import Text.Megaparsec.Char
type Parser = Parsec Void String
main :: IO ()
main = case runParser p "bruh" "\"123\", \"321\" , ," of
Left err -> print err
Right res -> print res
@Elvecent
Elvecent / default.nix
Created November 16, 2020 20:36
Haskell Nix
{ nixpkgs ? import ./nix/nixpkgs-2020-09.nix
, hls ? true
, hoogle ? true
}:
let
packageName = "template";
overlay = self: super: {
myHaskellPackages =
@Elvecent
Elvecent / Main.hs
Last active August 15, 2020 21:34
Functor list product or idk
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ConstraintKinds #-}
@Elvecent
Elvecent / Server.hs
Created December 6, 2019 13:34
WebSocket chat that fails
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Server (talk, newServer, Server) where
import Control.Concurrent.Async
import Control.Concurrent.STM
import Control.Exception
import Control.Monad
import Data.Foldable (traverse_)
import Data.Functor (void)
@Elvecent
Elvecent / Main.hs
Created November 13, 2019 06:02
Minesweeper
module Main where
-- from "monoidal-containers" package
import qualified Data.IntMap.Monoidal.Strict as M
-- The thing with this IntMap is that whenever
-- its elements form a semigroup, the IntMaps
-- containing those elements themselves form
-- a monoid that works "pointwise"
-- Just type synonyms