Skip to content

Instantly share code, notes, and snippets.

View alexpeits's full-sized avatar

Alex Peitsinis alexpeits

View GitHub Profile
@alexpeits
alexpeits / ApecsReturnVariant.hs
Last active June 2, 2019 16:25
Some extensions to Apecs, working around the TH tuple instances and more lenient return types for systems using Variant/HList
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module ApecsReturnVariant where
import Data.Kind (Constraint, Type)
import qualified Control.Monad.Reader as R
module Parse
( lexeme
, identifier
, reserved
, operator
, reservedOp
, charLiteral
, stringLiteral
, symbol
, whiteSpace
@alexpeits
alexpeits / Exceptions.hs
Last active January 15, 2019 10:49
Exceptions (with Tom's stuff)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
@alexpeits
alexpeits / MergeAeson.hs
Created October 1, 2018 09:17
Merge datatypes with Aeson
{-# LANGUAGE TypeOperators, FlexibleInstances, DeriveGeneric, OverloadedStrings #-}
module JSON where
import GHC.Generics
import Data.Aeson
import qualified Data.HashMap.Lazy as M
data A = A {a :: String} deriving (Show, Generic)
data B = B {b :: Float} deriving (Show, Generic)
@alexpeits
alexpeits / solarized_brighten.py
Last active September 23, 2018 22:12
Make the dark variant of solarized for emacs a bit bright (also create one with black background) (script written in 2 minutes ==> bad)
# Usage:
# python solarized_brighten.py [args]
# args are:
# -b/--black to create another theme with black background
# -a/--amount to tweak the amount of brightness
# -c/--custom custom lisp folder name (not path, inside .emacs.d in my case)
# -t/--themes custom theme folder name (not path, inside .emacs.d in my case)
# This creates 2 files, one in the custom folder and one in the themes folder.
@alexpeits
alexpeits / Eliminate.hs
Last active September 5, 2018 20:04
Haskell Peano Arithmetic
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Eliminate where
data Nat = Zero | Succ Nat | Pred Nat
type family n + m where
@alexpeits
alexpeits / OverloadedLabelsTest.hs
Last active August 4, 2018 09:50
OverloadedLabels
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.Proxy
@alexpeits
alexpeits / EnvAccess.hs
Created May 19, 2018 19:10
Get and set record fields dynamically using DataKinds
{-# LANGUAGE AllowAmbiguousTypes #-} -- GHC prompted me
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-} -- required for the examples
module EnvAccess where
data EnvType = LocalEnv | GlobalEnv
data Env = Env {localEnv :: Int, globalEnv :: Int} deriving Show
@alexpeits
alexpeits / timesheet.org
Last active April 16, 2018 05:53
Simple org file demonstrating how to track work hours per project

Heading

Task