Skip to content

Instantly share code, notes, and snippets.

Leif Warner LeifW

Block or report user

Report or block LeifW

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@LeifW
LeifW / Json.scala
Created May 15, 2019
JSON encoder / decoder deriving with Shapeless
View Json.scala
package json
import shapeless._
import shapeless.labelled.{FieldType, field}
sealed abstract class AST
case object Null extends AST
case class Bool(value: Boolean) extends AST
case class Str(value: String) extends AST
case class Num(value: Double) extends AST
@LeifW
LeifW / gtk_patch.pxsl
Created Jan 26, 2019
Patch for gtk3 package .gir file
View gtk_patch.pxsl
#!/usr/local/bin/#pxsl
stylesheet -version=1.0 -xmlns:xsl=http://www.w3.org/1999/XSL/Transform
output -indent=yes
template -match=<<*[@name = 'get_row_header_cells' or @name = 'get_column_header_cells']>>
template @*|node()
copy
apply-templates @*|node()
@LeifW
LeifW / Decode.scala
Last active Jan 10, 2019
Shapeless generic decode
View Decode.scala
import shapeless._
import shapeless.labelled.{FieldType, field}
abstract class Decode[A] {
def get: A
}
object Decode {
def apply[A](implicit decoder: Decode[A]) = decoder
implicit object getString extends Decode[String] { val get = "A string" }
@LeifW
LeifW / EfiBootEntry.hs
Created Dec 3, 2018
YAML EFI boot entries
View EfiBootEntry.hs
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
import GHC.Generics (Generic())
import Data.Yaml (decodeFileThrow, FromJSON, ToJSON)
import System.Process (callProcess)
import System.Environment (getArgs)
createEntry (BootEntry label kernel args) =
callProcess "sudo" ["efibootmgr", "--disk", "/dev/nvme0n1", "--part", "1", "--create", "--label", label, "--loader", kernel, "-u", unwords args]
@LeifW
LeifW / xmlbf.hs
Created Sep 6, 2018
xmlbf example of rendering an instance as XML
View xmlbf.hs
{-# LANGUAGE OverloadedStrings #-}
import Xmlbf
import Data.HashMap.Strict (empty)
import Data.ByteString.Builder (toLazyByteString)
import Data.Text (Text)
import qualified Data.ByteString.Lazy.Char8 as BSC
import Network.AWS.Data.Text (ToText(toText))
data Person = Person {name :: String, age :: Int} deriving Show
@LeifW
LeifW / for.scala
Last active Aug 23, 2018
Scala do-notation overloading
View for.scala
case class Foo(a: Int) {
def map(f : Int => Int) = Foo(f(a))
def flatMap(f : Int => Bar): Bar = f(a)
}
case class Bar(a: Int) {
def map(f : Int => Int) = Bar(f(a))
def flatMap(f : Int => Bar): Bar = f(a)
}
@LeifW
LeifW / doInt.idr
Created Aug 23, 2018
Do-notation desugaring in Idris
View doInt.idr
-- Apply the callback that is the rest of the lines of code
(>>=) : Int -> (Int -> Int) -> Int
(>>=) x f = f x
i : Int
i = do
x <- 1
y <- 2
x + y
@LeifW
LeifW / Main.hs
Created Jul 23, 2018
running a cabal test
View Main.hs
module Main(main, a) where
a = "foo"
main = putStrLn a
@LeifW
LeifW / aeson_dsl.hs
Created Jul 12, 2018
Aeson ambiguous instance
View aeson_dsl.hs
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson
thing = object [ "foo" .= "bar" ]
View taffybar.hs
module Main where
import System.Taffybar
import System.Taffybar.Information.CPU
import System.Taffybar.Information.Memory
import System.Taffybar.SimpleConfig
import System.Taffybar.Widget
import System.Taffybar.Widget.Workspaces
import System.Taffybar.Widget.Battery
import System.Taffybar.Widget.SNITray
You can’t perform that action at this time.