Skip to content

Instantly share code, notes, and snippets.

View mchav's full-sized avatar

Michael Chavinda mchav

View GitHub Profile
-- Sort of like Java's step builder pattern.
-- https://medium.com/@castigliego/step-builder-pattern-3bcac4eaf9e8
-- A type that encodes that Y doesn't exist.
data NeedY
-- A type that encodes that a chart is ready.
data Ready
data Plot (s :: *) where
@mchav
mchav / Eventlog.hs
Last active December 10, 2025 07:35
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Control.Monad (when)
import qualified Data.ByteString.Lazy as L
import Data.List (foldl')
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ImportQualifiedPost #-}
module Main (main) where
import Chart
import Data.Text (Text)
import Prelude as P
@mchav
mchav / DataFrame.hs
Created September 6, 2025 04:29
A minimal definition of a columnar dataframe with a closed.
module DataFrame where
-- Column space with a closed type universe.
data Column = CInt [Int]
| CDouble [Double]
| CString [String]
instance Show Column where
show (CInt xs) = show xs
show (CDouble xs) = show xs
@mchav
mchav / Correlation.hs
Created January 17, 2025 15:34
Non-allocating pearson's correlation
correlation :: T.Text -> T.Text -> DataFrame -> Maybe Double
correlation first second df = do
(UnboxedColumn (f :: VU.Vector a)) <- getColumn first df
(UnboxedColumn (s :: VU.Vector b)) <- getColumn second df
Refl <- testEquality (typeRep @a) (typeRep @Double)
Refl <- testEquality (typeRep @b) (typeRep @Double)
let n = VG.length f
let
go (-1) acc = acc
go i (mX :: Double, mY :: Double) = go (i - 1) (mX + f VU.! i, mY + s VU.! i)
@mchav
mchav / Day3.hs
Created December 3, 2024 06:14
AOC 2024 Day 3
module Day3 where
import Data.List ( isPrefixOf )
import Data.List.Split ( splitOn )
import Data.Char ( isDigit )
run :: IO ()
run = do
instructions <- readFile "./data/day3/input"
let tuples = parseInstructions instructions
@mchav
mchav / DataFrame.hs
Created January 22, 2024 18:02
DataFrames using GADTs and Dynamic Typing
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs #-}
module Main where
import Data.Map (Map)
import Data.Type.Equality
import Data.Typeable (Typeable)
import Type.Reflection
@mchav
mchav / AxisAligned.hs
Created January 1, 2022 20:10
A visualization proving that axis aligned rectangles are PAC learnable.
import Control.Monad
import Data.Array
-- A class for axis-aligned rectangles.
-- The rectangle is defined by the left and right most x
-- coordinates. And the left and rightmost y coordinates.
type Point = (Int, Int)
data Rectangle = Rectangle {
project.afterEvaluate {
extensions.compileFrege = {
description = 'Compile Frege to Java'
javaexec {
android.dexOptions.setJavaMaxHeapSize("4g")
android.defaultConfig.setMultiDexEnabled(true)
def libs = project.rootDir.path + "/app/libs".replace('/' as char, File.separatorChar)
def froid = new File(libs + "/froid.jar".replace('/' as char, File.separatorChar))
@mchav
mchav / proguard-rules.pro
Last active April 26, 2017 03:14
Proguard rules for froid apps.
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-keepattributes *Annotation*