Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@jdhom
jdhom / mistel-barocco-md600.md
Last active August 16, 2025 17:25
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
@konn
konn / Data.Aeson.Generic.DerivingVia.hs
Last active December 7, 2020 21:06
Type-driven safe derivation of ToJSON and FromJSON, using DerivingVia in GHC 8.6 and some type-level hacks
{-# LANGUAGE ConstraintKinds, DataKinds, DeriveGeneric, DerivingVia #-}
{-# LANGUAGE ExplicitNamespaces, FlexibleContexts, FlexibleInstances #-}
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds, ScopedTypeVariables, StandaloneDeriving #-}
{-# LANGUAGE TypeApplications, TypeFamilies, TypeInType, TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
module Data.Aeson.Generic.DerivingVia
( StrFun(..), Setting(..), SumEncoding'(..), DefaultOptions, WithOptions(..)
, -- Utility type synonyms to save ticks (') before promoted data constructors
@twopoint718
twopoint718 / RandomEnum.hs
Created June 3, 2018 18:05
Select a random element of a bounded, enumerable datatype. If you know that a datatype has a way to generate a list of items, a way to determine the minimum and maximum values, then you should be able to select a random element from that datatype.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
module RandomEnum where
import System.Random
enumRandomR :: (RandomGen g, Enum e) => (e, e) -> g -> (e, g)
@gvolpe
gvolpe / shared-state-in-fp.md
Last active March 15, 2022 20:27
Shared State in pure Functional Programming

Shared State in pure Functional Programming

Newcomers to Functional Programming are often very confused about the proper way to share state without breaking purity and end up having a mix of pure and impure code that defeats the purpose of having pure FP code in the first place.

Reason why I decided to write up a beginner friendly guide :)

Use Case

We have a program that runs three computations at the same time and updates the internal state to keep track of the

-- Copyright 2018 Google LLC.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE FlexibleContexts #-}
import Control.Applicative
import Control.Monad.Writer
data Expr = Lit Int | Plus Expr Expr | Times Expr Expr
deriving (Eq, Show)
@Icelandjack
Icelandjack / SystemF.hs
Last active November 27, 2018 02:00
System F
-- SYSTEM F
-- http://homepages.inf.ed.ac.uk/slindley/papers/embedding-f.pdf
--
-- Type-level lambdas
-- https://gist.github.com/AndrasKovacs/ac71371d0ca6e0995541e42cd3a3b0cf
{-# language TemplateHaskell, ScopedTypeVariables, RankNTypes,
TypeFamilies, UndecidableInstances, DeriveFunctor, GADTs,
TypeOperators, TypeApplications, AllowAmbiguousTypes,
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
module LMS where
import Data.Generics.Product
@taktoa
taktoa / haskell-pain-points.md
Last active October 26, 2019 04:18
A rant about pain points in Haskell, written as a response to https://redd.it/7rwuxb

I started writing this polemic to answer your question, but I ended up touching on most of my gripes with Haskell in general, not just in a corporate context.

GHC

GHC is a modern compiler with an amazing RTS and tons of features, but I have some issues with it.

Monolithic and Hard to Contribute To

@ekmett
ekmett / StateComonad.hs
Created January 6, 2018 15:53
The State Comonad
-- http://comonad.com/reader/2018/the-state-comonad/
-- https://www.reddit.com/r/haskell/comments/7oav51/i_made_a_monad_that_i_havent_seen_before_and_i/
{-# language DeriveFunctor #-}
import Control.Comonad
import Data.Semigroup
data Store s a = Store { peek :: s -> a, pos :: s } deriving Functor
{-# language TypeInType, GADTs, TemplateHaskell, ExistentialQuantification,
TypeApplications, TypeFamilies, TypeOperators, StandaloneDeriving, FlexibleContexts,
RankNTypes #-}
import Data.Kind
import Data.Singletons
import Data.Singletons.TH
data Sigma a f = forall (x :: a). Sigma (Sing x) (Apply f x)