Skip to content

Instantly share code, notes, and snippets.

@LeifW
LeifW / Brightness.hs
Created August 22, 2020 06:43
Modify screen brightness from Haskell (for use from XMonad)
module Brightness (inc, dec) where
import System.IO
import Control.Monad.IO.Class (MonadIO, liftIO)
modifyFile :: (String -> String) -> Handle -> IO ()
modifyFile f h = f <$> hGetLine h >>= hPutStr h
modifyBrightness :: MonadIO m => (Int -> Int) -> m ()
modifyBrightness f = liftIO $ withFile "/sys/class/backlight/intel_backlight/brightness" ReadWriteMode $ modifyFile (show . f . read)
label: Arch Linux new norename
kernel: /vmlinuz-linux
args:
- root=/dev/nvme0n1p2
- rw
- initrd=intel-ucode.img
- initrd=initramfs-linux.img
- net.ifnames=0
import Interfaces.Verified
%default total
data Face = Frown | Smile
Semigroup Face where
Smile <+> Smile = Smile
Smile <+> Frown = Frown
Frown <+> Smile = Frown
Frown <+> Frown = Frown
import Data.Vect
types : Vect 3 Type
types = [Int,Bool,Int]
nthType : {n: Fin 3} -> Type
nthType = index n types
@LeifW
LeifW / Main.purs
Last active March 5, 2020 19:53
Purescript UI w/ Flare
module Main where
import Prelude
import Effect (Effect)
import Flare (UI, string, runFlare)
greet :: String -> String
greet name = "Hello, " <> name
flare :: UI String
@LeifW
LeifW / Json.scala
Created May 15, 2019 00:11
JSON encoder / decoder deriving with Shapeless
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 January 26, 2019 22:40
Patch for gtk3 package .gir file
#!/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 January 10, 2019 10:28
Shapeless generic decode
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 December 3, 2018 05:52
YAML EFI boot entries
{-# 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 September 6, 2018 01:41
xmlbf example of rendering an instance as XML
{-# 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