Skip to content

Instantly share code, notes, and snippets.

View newton-migosi's full-sized avatar

Newton Migosi newton-migosi

View GitHub Profile
@newton-migosi
newton-migosi / flakes.nix
Created November 11, 2023 23:57
Setting up miso nix flakes
# Usage:
#
# With nix installed, navigate to the directory containing this flake and run
# `nix develop --impure`. The `--impure` is necessary in order to store state
# locally from "services", such as PostgreSQL.
{
description = "Local library app";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
@newton-migosi
newton-migosi / nix.trace
Created November 11, 2023 22:49
`attribute 'extend' missing` error when running nix develop
warning: Git tree '/home/user/hs/web/mdn-local-library-tutorial' is dirty
error: attribute 'extend' missing
at /nix/store/k066hn412qjzs933n8dk8xqsnpqhj1sb-source/nix/modules/project/outputs.nix:91:23:
90|
91| finalPackages = config.basePackages.extend finalOverlay;
| ^
92|
@newton-migosi
newton-migosi / intest-01.hs
Last active May 23, 2023 18:30
[Haskell-cafe] Fast number parsing with strict bytestrings
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as B
divisibleBy :: Int -> Int -> Bool
a `divisibleBy` n = a `rem` n == 0
main :: IO ()
main = do
[n,k] <- (map int . B.split ' ') `fmap` B.getLine :: IO [Int]
@newton-migosi
newton-migosi / cabal-repl-ghci-dap.errors.log.txt
Last active May 1, 2023 08:27
Error logs when using ghci-dap
[DAP][INFO] start ghci-dap-0.0.20.0.
<command line>: cannot satisfy -package-id relude-1.1.0.0-B6zcHDYI1P31kfRGCmdMyN (Relude as Prelude, Relude.Container.One)
(use -v for more information)
CallStack (from HasCallStack):
withMetadata, called at src/Distribution/Simple/Utils.hs:368:14 in Cabal-3.10.1.0-5sSVeMY5t4HKsrW2wqIvsr:Distribution.Simple.Utils
Error: cabal: repl failed for local-library-0.1.0.0-inplace.
@newton-migosi
newton-migosi / MathError.hs
Last active January 31, 2023 22:26
literal translation of https://doc.rust-lang.org/rust-by-example/std/result.html .. not type checked, for illustration purposes only
data MathError
= DivisionByZero
| NonPositiveLogarithm
| NegativeSquareRoot
deriving Show
type MathResult = Either MathError Double
div :: Double -> Double -> MathResult
div x y =
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens (cloneLens, makeLenses, use, (.=))
import Control.Monad (guard, msum, replicateM)
import Control.Monad.Logic (MonadLogic (msplit), observeT)
import Control.Monad.State.Lazy (MonadState, evalState)
import Data.List (sortOn)
@newton-migosi
newton-migosi / video.purs
Created June 10, 2021 10:20
Purescript Video Component
module App.Video (component) where
-- import Control.Monad (class Bind)
import DOM.HTML.Indexed.InputAcceptType (InputAcceptType, InputAcceptTypeAtom(..))
import Data.Foldable (traverse_)
import Data.Maybe (Maybe(..))
import Data.MediaType (MediaType(..))
import Data.Traversable (for_)
import Effect.Aff.Class (class MonadAff)
@newton-migosi
newton-migosi / solutions.hs
Created December 2, 2020 19:05
Code for generating solutions to the Add23 Puzzle
solution target sides width pool = loop sides 0 []
where
loop 0 runningTotal accumulator = do
let correct = (== sides + 2) . length . concatMap (uncurry intersect)
guard . all correct . chunksOf sides . pairs $ accumulator
return accumulator
loop counter runningTotal accumulator = do
current <- sumTo total width pool
@newton-migosi
newton-migosi / sumTo.hs
Created December 1, 2020 16:41
Find all the ways to add up to a number
sumTo target n pool = loop n 0 []
where
loop 0 runningTotal accumulator = do
guard (runningTotal == target)
return accumulator
loop counter runningTotal accumulator = do
current <- pool
case accumulator of
[] -> guard True
loop 0 runningTotal accumulator = do
guard (runningTotal == target)
return accumulator