Skip to content

Instantly share code, notes, and snippets.

View MonoidMusician's full-sized avatar

Verity Scheel MonoidMusician

View GitHub Profile
@mildsunrise
mildsunrise / getPerspectiveTransform.mts
Last active June 24, 2023 15:42
portable / efficient JS version of OpenCV getPerspectiveTransform()
/**
* solve a 2x2 linear system, given its augmented matrix, in place.
* first 2 columns left unchanged.
*/
function solve2x2([ x, y ]: [number[], number[]]) {
let [ a, b, c, d ] = [ x[0], x[1], y[0], y[1] ]
const det = a * d - b * c
if (!det) throw Error('inversion failed')
const k = 1 / det
; (a *= k, b *= k, c *= k, d *= k)
@Lysxia
Lysxia / HTMLParser.hs
Last active September 5, 2022 14:07
Applicative HTML Parser
{-# LANGUAGE GADTs, DeriveFunctor, LambdaCase #-}
import Data.Functor.Product
import Data.Void
import Control.Applicative
type Tag = String
type Attr = String
data HTML
@Gabriella439
Gabriella439 / trans.md
Last active November 28, 2023 06:30
I'm trans

I'm writing this post to publicly come out as trans (specifically: I wish to transition to become a woman).

This post won't be as polished or edited as my usual posts, because that's kind of the point: I'm tired of having to edit myself to make myself acceptable to others.

I'm a bit scared to let people know that I'm trans, especially because I'm not yet in a position where I can transition (for reasons I don't want to share, at least not in public) and it's really shameful. However, I'm getting really

@i-am-the-slime
i-am-the-slime / How to build an Apple Silicon version of the PureScript compiler.md
Last active July 7, 2022 10:06
How to build an Apple Silicon version of the PureScript compiler

How to build an Apple Silicon version of the PureScript compiler

Updates:

2022-07-01

Add prebuilt binary for 0.15.4

2022-06-24

I changed ghc to be installed with ghcup and ghc version to 9.2.3 to match PS 0.15.3 added the RELEASE flag.

@obfusk
obfusk / bdiff.sh
Last active May 6, 2024 02:28
diff + bat
#!/bin/bash
diff -Naur "$@" | bat -p -l diff
@AndrasKovacs
AndrasKovacs / GluedEval.hs
Last active August 18, 2024 21:01
Non-deterministic normalization-by-evaluation in Olle Fredriksson's flavor.
{-# language Strict, LambdaCase, BlockArguments #-}
{-# options_ghc -Wincomplete-patterns #-}
{-
Minimal demo of "glued" evaluation in the style of Olle Fredriksson:
https://github.com/ollef/sixty
The main idea is that during elaboration, we need different evaluation
import Data.Set
type Letter = String
data Term = TTau Integer Letter Relation
| TBox Integer Letter
| TVar Letter
| TSubst Term Letter Term
| TPair Term Term
deriving (Show, Eq)
@monadplus
monadplus / profiling_haskell.md
Last active May 2, 2024 19:41
Haskell: Profiling

Profiling in Haskell

Do not get bogged down in microoptimizations before you've assessed any macro optimizations that are available. IO and the choice of algorithm dominate any low level changes you may make. In the end you have to think hard about your code!

Before starting to optimize:

  1. Is the -O2 flag on ?
  2. Profile: which part of the code is the slow one.
  3. Use the best algorithm in that part.
  4. Optimize: implement it in the most efficient way.
@sellout
sellout / OpClasses.idr
Last active August 20, 2022 01:18
Defining ad-hoc polymorphism using dependently-typed implicits.
-- This illustrates (most of) a new(?) encoding of ad-hoc polymorphism using
-- dependent types and implicits.
--
-- Benefits of this approach:
-- • can have multiple “ambiguous” instances without requiring things like
-- Haskell’s newtypes to distinguish them;
-- • can disambiguate instances with minimal information, rather than having to
-- know some arbitrary instance name as you would with a system like Scala’s
-- implicits;
-- • implementers don’t need to know/provide the full family of instances – they
@i-am-tom
i-am-tom / FizzBuzz.hs
Last active June 26, 2023 16:35
Arguably the fastest implementation of FizzBuzz ever written.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnsaturatedTypeFamilies #-}
import GHC.TypeLits
import Prelude hiding (Functor, Semigroup)
type Main = (Fizz <> Buzz) <$> (0 `To` 100)