Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@danidiaz
danidiaz / Flexbox_and_Margins.tsx
Created June 26, 2022 17:57
CSS & Tailwind snippets
export default function Flexy() : JSX.Element {
return (<div className="flex flex-row">
<div className = "outline outline-black">
<p>Foo</p>
</div>
<div className = "outline outline-black">
<p>Bar</p>
</div>
<div className = "ml-auto outline outline-black" >
<p>Baz</p>
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE ImportQualifiedPost #-}
module Main where
import Data.Array.Mutable.Linear (Array, set)
import Data.Array.Mutable.Linear qualified as Array
import Prelude.Linear (Ur(..), (&), (.))
quicksort :: Array Int ⊸ Array Int
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE KindSignatures #-}
module Main where
import Control.Lens ( (^.), (&), (.~), Lens )
import Data.Generics.Product.Fields qualified as G
import GHC.Records (HasField (..))
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Main where
import Dep.Has (Has(dep), asCall) -- from the "dep-t" package
import Control.Monad.IO.Class
@danidiaz
danidiaz / Override.hs
Last active March 17, 2022 22:07
Modeling Nix's "override" and "overrideAttrs" in Haskell
-- | Derivations in Nixpkgs are usually the result of a chain of function calls.
-- Typically, a function receives some input derivations as arguments (the "inputs
-- pattern") and it eventually calls the 'mkDerivation' function, which produces the
-- actual derivation value that is put into Nixpkgs.
--
-- Turns out that derivation values in Nixpkgs keep a "memory" of how they were produced at
-- those two stages: which functions were called, and with which arguments. They
-- also provide "hooks" that allow re-running the stages with (partially or
-- totally) different arguments, resulting in a new derivation.
--
@danidiaz
danidiaz / mistel-barocco-md600.md
Created January 7, 2022 14:11 — forked from jdhom/mistel-barocco-md600.md
Mistel Barocco MD600 Programming and Firmware

Mistel Barocco MD600 RGB Split Keyboard

keyboard firmware

What I remap

CapsLock is RCTRL    ... i do this on all keyboards
FN CapsLock is RCTRL ... was accidently toggling capslock with fn+capslock
LCTRL is FN ... arrow/pg/home on right half, FN+arrow I now prefer on ALL keyboards... so nice
@danidiaz
danidiaz / ConstrainingCoerce.hs
Created December 14, 2021 12:21
constraining "coerce" using type families
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
-- | Examples of how to constrain "coerce" using type families so that only the
-- types that we really want to change might change, and not some unexpected
-- newtype.
module Main where
{-# LANGUAGE BlockArguments, DeriveGeneric #-}
module Main where
import Data.Function ((&))
import System.IO
import Data.List.NonEmpty (NonEmpty ((:|)))
import GHC.Generics
-- from "dep-t-advice"
import Control.Monad.Dep.SimpleAdvice (AspectT(..), advising, advise, adviseRecord, Top)
import Control.Monad.Dep.SimpleAdvice.Basic (printArgs)
@danidiaz
danidiaz / Main.hs
Last active October 9, 2021 08:21
dependency injection in Haskell with a record-of-functions, but no ReaderT
-- Dependency injection using a record-of-functions, but no ReaderT.
--
-- Download in an empty folder, then run with:
--
-- $ cabal install --lib --package-env . dep-t-0.4.4.0
-- $ runghc Main.hs
--
-- Some interesting aspects:
--
-- - No ReaderT transformer! Just plain functions (wrapped in helper datatypes).
@danidiaz
danidiaz / Main.hs
Last active June 6, 2021 18:20
profiling confusion
{-# LANGUAGE NumDecimals, BangPatterns #-}
module Main where
import Data.Array
import Control.Concurrent
import System.Mem
type A = Array Integer Integer
{-# NOINLINE makea #-}