Skip to content

Instantly share code, notes, and snippets.

View mstksg's full-sized avatar

Justin Le mstksg

View GitHub Profile
@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,
@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 / 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 #-}
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
data ProdMap :: (a -> b -> Type) -> [a] -> [b] -> Type where
PMZ :: ProdMap f '[] '[]
PMS :: f a b -> ProdMap f as bs -> ProdMap f (a ': as) (b ': bs)
data Slice :: Nat -> Nat -> Type where
Slice :: Sing l -> Sing c -> Sing r -> Slice (l + c + r) c
slice
:: (SingI ns, SingI ms)
=> ProdMap Slice ns ms
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
@mstksg
mstksg / prep-ghcjs.md
Created May 20, 2017 09:37
Preparing GHCJS for Stack

Hello

Just writing this down so I don't go crazy and forget later. Let's build a fresh copy of ghcjs from scratch and package it in a way that stack appreciates.

$ git clone git@github.com:ghcjs/ghcjs.git
$ cd ghcjs
$ git checkout ghc-8.0
$ echo "resolver: lts-7.22" &gt; stack.yaml
data Auto1 a b = A1 { runAuto :: a -> (b, Auto1 a b) }
data Auto2 a b = forall s. A2 s ((a, s) -> (b, s))
sumFrom1 :: Int -> Auto1 Int Int
sumFrom1 n = A1 $ \x -> (x + n, sumFrom1 (x + n))
sumFrom2 :: Int -> Auto2 Int Int
sumFrom2 n0 = A2 n0 $ \(x, n) -> (x + n, x + n)
{-# language DeriveFunctor #-}
{-# language UndecidableInstances #-}
{-# language TypeInType #-}
{-# language TypeOperators #-}
{-# language TemplateHaskell #-}
{-# language KindSignatures #-}
{-# language DataKinds #-}
{-# language ViewPatterns #-}
{-# language GADTs #-}
{-# language TypeFamilies #-}
@mstksg
mstksg / ReflectEq.hs
Created August 23, 2017 21:47
reflection for dynamic Eq instances
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Proxy
import Data.Reflection
data EqDict a = EQD { withEqDict :: a -> a -> Bool }