Skip to content

Instantly share code, notes, and snippets.

View mstksg's full-sized avatar

Justin Le mstksg

View GitHub Profile
foo :: StateT s m Int
bar :: Int -> StateT s m Bool
-- using State appropriately
baz :: StateT s m Bool
baz = do
x <- foo
bar x
@mstksg
mstksg / LawfulMonoid.hs
Last active November 14, 2016 10:41
Monoid typeclass with compiler-enforced laws in Haskell
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
@mstksg
mstksg / GAME_MASTER_v0_1.protobuf
Created July 17, 2016 06:29 — forked from anonymous/GAME_MASTER_v0_1.protobuf
Pokemon Go decoded GAME_MASTER protobuf file v0.1
Result: 1
Items {
TemplateId: "BADGE_BATTLE_ATTACK_WON"
Badge {
BadgeType: BADGE_BATTLE_ATTACK_WON
BadgeRanks: 4
Targets: "\nd\350\007"
}
}
Items {
@mstksg
mstksg / htop-1.0.2-temperature.patch
Created May 30, 2016 23:05 — forked from rstemmer/htop-1.0.2-temperature.patch
Adds a new Meter to htop that displays your core temperatures. You need the lm_sensors package to use this meter. After applying this patch, you have to call ./autogen.sh before configuring and compiling.
diff -urN htop-1.0.2-orig/CRT.c htop-1.0.2/CRT.c
--- htop-1.0.2-orig/CRT.c 2013-03-23 14:10:29.500604247 +0100
+++ htop-1.0.2/CRT.c 2013-03-23 14:11:01.916663508 +0100
@@ -59,6 +59,9 @@
UPTIME,
BATTERY,
TASKS_RUNNING,
+ TEMPERATURE_COOL,
+ TEMPERATURE_MEDIUM,
+ TEMPERATURE_HOT,
{-# language DataKinds, PolyKinds, ScopedTypeVariables, UndecidableInstances,
FlexibleInstances, FlexibleContexts, GADTs, TypeFamilies, RankNTypes,
LambdaCase, TypeOperators, ConstraintKinds #-}
import GHC.TypeLits
import Data.Proxy
import Data.Singletons.Prelude
import Data.Singletons.Decide
import Data.Constraint

Keybase proof

I hereby claim:

  • I am mstksg on github.
  • I am mstksg (https://keybase.io/mstksg) on keybase.
  • I have a public key whose fingerprint is 1BB5 2738 56F8 1236 7977 2D4F 7250 9247 67D5 7F1C

To claim this, I am signing this object:

@mstksg
mstksg / ExprGADT.hs
Last active August 29, 2015 14:25
Type checked lambdas
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
@mstksg
mstksg / PIDs.md
Last active August 29, 2015 14:04
Comparison of PID controller implementation approaches, and a case for a compositional, denotative, locally stateful style

PID Controller: A comparison of approaches

And a case for a compositional, denotative, and locally stateful style.

High Level Description

@mstksg
mstksg / SHO.hs
Created July 31, 2014 05:05
Example of stepping/running an Wire with constant dt
{-# LANGUAGE Arrows #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main (main) where
import Control.Wire
import FRP.Netwire.Move
import Control.Arrow
import Prelude hiding ((.), id, mapM_)
@mstksg
mstksg / gist:aa70c9182c387e6f67b1
Last active August 29, 2015 14:03
Home-made IO+State Monad
andThen :: (s -> IO (a, s)) -> (s -> IO (b, s)) -> (s -> IO (b, s))
andThenWith :: (s -> IO (a, s)) -> (a -> (s -> IO (b, s))) -> (s -> IO (b, s))
-- type synonym:
--
-- > type MIOS s a = s -> IO (s, a)