Skip to content

Instantly share code, notes, and snippets.

View rjregenold's full-sized avatar

RJ Regenold rjregenold

  • Provider Science
  • Texas
View GitHub Profile
@chrisdone
chrisdone / DBAPI.hs
Last active April 10, 2022 07:26
Defaulting fields in a record in Haskell
{-# LANGUAGE DataKinds #-}
-- | My database API.
module DBAPI where
import Data.Defaults
data ConnSpec p = ConnSpec
{ username :: !(Required p String)
@eNeRGy164
eNeRGy164 / LoremIpsumKeyVault.json
Last active March 19, 2021 06:34
Deployment Template sample adding Secrets to a Azure Key Vault
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.KeyVault/vaults",
"name": "LoremVault",
"apiVersion": "2015-06-01",
"location": "[resourceGroup().location]",
"properties": {
/* discovered njoin on this thread: https://github.com/functional-streams-for-scala/fs2/issues/251 - which also cites (adjusted to match example below):
If we increase maxQueued up to 100, and `handle` emits multiple `A` values, up to 100 will be prefetched
before we block on the consumer of results. (Not actually blocking by occupying a thread, but semantically blocking.)
If we increase maxOpen to 50, then we can have 50 `item` streams processing concurrently.
*/
import scalaz.stream.{Sink,Process,sink,channel}
import scalaz.stream.nondeterminism.njoin
@milessabin
milessabin / gist:25b7b669b5a9ac051a71
Created June 5, 2015 14:32
A safe ADT+shapeless drop-in replacement for the unsafe standard Scala Enumeration ...
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration.
//
// First the unsafe standard Scala Enumeration ...
//
object ScalaEnumDemo extends App {
// Example from scala.Enumeration scaladoc. Terse ...
object WeekDay extends Enumeration {
type WeekDay = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}

A Quick and Dirty Lens primer

Why does Lens exist? Well, Haskell records suck, for a number of reasons. I will enumerate them using this sample record.

data User = User { login    :: Text
                 , password :: ByteString
                 , email    :: Text
                 , created  :: UTCTime
 }
@DamienCassou
DamienCassou / configuration.nix
Created October 22, 2014 13:41
configuration.nix file for NixOS on my macbook pro
{ config, pkgs, ... }:
let
hostname = "luz3";
in {
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
# I use VirtualBox to connect to Windows and Linux guests
{-# LANGUAGE RankNTypes #-}
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r }
stateReturn :: a -> State s a
stateReturn a = State $ \s k -> k a s
stateMap :: (a -> b) -> State s a -> State s b
stateMap f (State sa) = State $ \s kb -> sa s (kb . f)
@YoEight
YoEight / State.hs
Last active August 29, 2015 14:07
A different State encoding (solution here https://gist.github.com/YoEight/0541aa293effbfff8d02)
{-# LANGUAGE RankNTypes #-}
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r }
stateReturn :: a -> State s a
stateReturn = undefined
stateMap :: (a -> b) -> State s a -> State s b
stateMap = undefined
@milessabin
milessabin / gist:6081113
Last active December 20, 2015 05:49
Slicing and dicing tuples in shapeless 2.0.0-SNAPSHOT.
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._
import shapeless._
scala> import syntax.tuple._
import syntax.tuple._
@MichaelXavier
MichaelXavier / Gemfile
Last active December 18, 2015 21:29
Some ruby-based tooling for haskell projects that makes development easier for me. Sandboxing requires cabal >= 0.1.7
source "http://rubygems.org"
gem "guard-shell"
gem "rake"