Skip to content

Instantly share code, notes, and snippets.

Avatar

Gil Mizrahi soupi

View GitHub Profile
@soupi
soupi / client.hs
Created Jul 1, 2020
Echo server/client haskell
View client.hs
module Main (main) where
import Control.Monad (forever, unless)
import qualified Data.ByteString.Char8 as C
import Network.Socket
import Network.Run.TCP (runTCPClient)
import Network.Socket.ByteString (recv, sendAll)
import System.IO (hFlush, stdout)
main :: IO ()
@soupi
soupi / bfs.hs
Created May 10, 2020
shortest path using bfs
View bfs.hs
{-# LANGUAGE ViewPatterns, TupleSections #-}
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Seq
import Control.Monad.Except
type User = String
type From = User
type To = User
View setup-stack-ghc-shortcuts.sh
#!/bin/bash
if [ ! -f ~/.local/bin/ghc ]; then
echo '#!/bin/bash' > ~/.local/bin/ghc;
echo 'stack exec -- ghc $@' >> ~/.local/bin/ghc;
chmod +x ~/.local/bin/ghc;
echo "~/.local/bin/ghc created."
else
echo "~/.local/bin/ghc already exists."
fi
@soupi
soupi / cmus_now_playing.hs
Last active Jul 21, 2020
Fancily write to file which song is playing in cmus (can be read from obs using textmonitor script)
View cmus_now_playing.hs
#!/usr/bin/env stack
-- stack --resolver lts-15.7 script --package text --package process
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import qualified Data.Text as T
import qualified Data.Text.IO as T
import System.Process
View Plate-for-dump.hs
-- stack exec --package uniplate --package criterion -- ghc Plate.hs -O2 -ddump-simpl -dsuppress-all > /tmp/Plate-dump.hs
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
import GHC.Generics
import Transform
data Expr
View Plate-dump.hs
[1 of 2] Compiling Transform ( Transform.hs, Transform.o ) [Optimisation flags changed]
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 353, types: 864, coercions: 374, joins: 0/0}
-- RHS size: {terms: 4, types: 9, coercions: 3, joins: 0/0}
gtransform
gtransform = \ @ a_a1p2 @ struct_a1p3 v_B1 -> v_B1 `cast` <Co:3>
@soupi
soupi / generic-transform.hs
Last active Jan 30, 2020
implementation of transform using generics
View generic-transform.hs
data Expr
= Lit Int
| Add Expr Expr
| Mul Expr Expr
| Div Expr Expr
| Sub Expr Expr
| Neg Expr
deriving (Show, Eq, Generic)
@soupi
soupi / Main.hs
Created Jun 14, 2019
stack exec does not find executable after stack build --profile
View Main.hs
module Main where
main :: IO ()
main = print 5
@soupi
soupi / Plate.hs
Last active Jan 30, 2020
Uniplate.Data vs hand written Lens.Plated vs generic-lens
View Plate.hs
-- stack exec --package uniplate --package criterion -- ghc Plate.hs -O
-- ./Plate --output=results.html
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE MonoLocalBinds #-}
You can’t perform that action at this time.