Skip to content

Instantly share code, notes, and snippets.

View emmanueldenloye's full-sized avatar

Emmanuel Denloye-Ito emmanueldenloye

  • New York, New York
View GitHub Profile
#!/usr/bin/env cabal
{- cabal:
build-depends: base
, dependent-sum
, mtl
-}
{-# language GADTs #-}
{-# language LambdaCase #-}
case _dbNotification_message notification of
NotifyTag_Baker :=> Identity (bid, mBaker) -> handleBaker bid mBaker
NotifyTag_BakerDetails :=> Identity bakerDetails -> handleBakerDetails bakerDetails
NotifyTag_BakerRightsProgress :=> Identity (_x, y, _z) -> handleBakerAddress (_bakerRightsCycleProgress_publicKeyHash y)
NotifyTag_ErrorLog tag :=> Identity eid ->
logAssume tag $ handleErrorLog (errorLogIdForErrorLogView . (tag :=>) . Identity) tag eid
NotifyTag_ProtocolIndex :=> Identity eid -> handleParameters eid
NotifyTag_MailServerConfig :=> Identity (_eid, cfg) -> handleMailServer cfg
NotifyTag_NodeExternal :=> Identity (eid, ent) -> (<>) <$> handleNodeExternal eid ent <*> alsoEveryBakerSummary
NotifyTag_NodeInternal :=> Identity (eid, ent) -> (<>) <$> handleNodeInternal eid ent <*> alsoEveryBakerSummary
(defun haskell-quick-nix-build ()
(interactive)
(when-let ((original-directory (file-name-directory (buffer-file-name))))
(let ((current-directory original-directory))
(while (and
(not
(or
(string= current-directory (expand-file-name "~"))
(string= current-directory (expand-file-name "/"))))
(not (directory-files current-directory nil "cabal$")))
@emmanueldenloye
emmanueldenloye / reload.el
Created December 3, 2018 23:41
Reload your init file without restarting emacs
(defun unsafe-reload-init-file
()
"Reload init.el file"
(interactive)
(let
((debug-on-error t))
(load user-init-file)
(message "Reloaded init.el OK.")))
guardTable :: Show n => FunApp -> Term n -> Eval e ()
guardTable i TTable {..} = do
r <- uses evalCallStack (alaf Last foldMap (firstOf (sfApp . _Just . _1 . faModule . _Just)))
case r of
(Just mn) | mn == _tModule -> enforceBlessedHashes i _tModule _tHash
_ -> do
m <- getModule (_faInfo i) _tModule
enforceKeySetName (_faInfo i) (_mKeySet m)
guardTable i t = evalError' i $ "Internal error: guardTable called with non-table term: " ++ show t
@emmanueldenloye
emmanueldenloye / haskell-process-use-presentation-mode.el
Created November 29, 2018 18:55
Get a nice pop-up buffer with `haskell-process-do-info' interactive command.
(setq haskell-process-use-presentation-mode t)
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
import Data.Monoid
data Same a
= Same a
| NotSame
| EmptySame
deriving (Eq, Show)
@emmanueldenloye
emmanueldenloye / collectMaxs.hs
Last active December 19, 2017 23:28
collect maximum elements of a list in one pass
-- Got inspiration from http://izzycecil.com/posts/2015-07-29-circular.html
trace :: (a -> c -> (b, c)) -> a -> b
trace f a = b
where (b, c) = f a c
collect' :: (Ord a) => (a -> a -> a) -> [a] -> a -> ([a],a)
collect' f [x] m = ([m],x)
collect' f (x:xs) m =
let (replaced, m') = collect' f xs m
@emmanueldenloye
emmanueldenloye / CartesianTree.hs
Created November 27, 2017 00:50
Cartesian Tree
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ExistentialQuantification #-}
module CartesianTree where
import Control.Lens
@emmanueldenloye
emmanueldenloye / shortestPathsMatrix.hs
Last active March 19, 2016 02:46
(Using FGL) Determine the shortestPath matrix if and only if the graph is fully connected.
import Control.Monad.ST
import Data.Graph.Inductive
import qualified Data.Graph.Inductive.PatriciaTree as GP
import Data.Maybe
import Data.STRef
import Numeric.LinearAlgebra
import Numeric.LinearAlgebra.Devel
-- The result is wrapped in a Maybe just in case, the graph is not fully connected.
-- There is a function to test for connectivity in FGL, but in my use case,