Skip to content

Instantly share code, notes, and snippets.

@schmich
schmich / ducky.md
Last active April 5, 2024 14:20
Programming media keys on the Ducky One 2 Skyline

Programming Media Keys on the Ducky One 2 Skyline

To use media keys on the Ducky One 2 Skyline, you must record a macro to bind the media function to a hotkey combination, i.e. Fn plus some key.

Example

Important: In the instructions below, "Press X+Y+Z" means press and hold key X, press and hold key Y, press and hold key Z in that order, and then release all three.

As an example, to bind Fn+PgUp to the play/pause media function:

@non
non / seeds.md
Last active April 12, 2024 09:18
Simple example of using seeds with ScalaCheck for deterministic property-based testing.

introduction

ScalaCheck 1.14.0 was just released with support for deterministic testing using seeds. Some folks have asked for examples, so I wanted to produce a Gist to help people use this feature.

simple example

These examples will assume the following imports:

@dcastro
dcastro / circe_shapeless_record.scala
Created April 27, 2018 14:32
Circe + Shapeless: blacklist fields with type-safety
import shapeless._, record._
import io.circe._
import io.circe.syntax._
import io.circe.generic.encoding._
case class Person(name: String, age: Int)
object Person {
implicit val encodePerson: Encoder[Person] =
ReprObjectEncoder.deriveReprObjectEncoder.contramap { person =>
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GADTs #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
@carymrobbins
carymrobbins / NumericLits.hs
Last active November 16, 2018 23:42
Huge hack to support explicit numeric literals in Haskell
{- TODO: The Num and Fractional instances don't implement all methods.
- In practice this is fine but for completeness they should be done.
-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module NumericLits where
data I = I
i :: I
@dcastro
dcastro / usage.scala
Last active December 6, 2018 12:39
"Newtype" deriving for scala
import org.scalacheck.cats.implicits._
import org.scalacheck.Gen
import io.circe.{Decoder, Encoder}
object Test extends App {
case class X(i: Int)
implicit val x: Encoder[X] = Wrapper[X].deriveInstance[Encoder]
implicit val y: Decoder[X] = Wrapper[X].deriveInstance[Decoder].withErrorMessage("some custom error msg")
val z: Gen[X] = Wrapper[X].lift(Gen.choose(0, 10))
@jkachmar
jkachmar / Main.hs
Last active May 19, 2022 13:20
"Simple" example for how to set up Servant to automatically retry its client requests
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
@ChrisPenner
ChrisPenner / GenericMonoid.hs
Last active February 22, 2019 19:51
Derive Monoid for using Generics
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module GenericMonoid where
import Data.Monoid
import Data.Maybe
@edmundsmith
edmundsmith / writeup.md
Created July 7, 2019 20:47
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust

Intro

I've been fiddling about with an idea lately, looking at how higher-kinded types can be represented in such a way that we can reason with them in Rust here and now, without having to wait a couple years for what would be a significant change to the language and compiler.

There have been multiple discussions on introducing higher-ranked polymorphism into Rust, using Haskell-style Higher-Kinded Types (HKTs) or Scala-looking Generalised Associated Types (GATs). The benefit of higher-ranked polymorphism is to allow higher-level, richer abstractions and pattern expression than just the rank-1 polymorphism we have today.

As an example, currently we can express this type:

@chrisdone
chrisdone / Intro.md
Last active May 20, 2024 12:44
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type