Skip to content

Instantly share code, notes, and snippets.

@seagreen
seagreen / cities.json
Created February 24, 2024 15:34 — forked from Miserlou/cities.json
1000 Largest US Cities By Population With Geographic Coordinates, in JSON
[
{
"city": "New York",
"growth_from_2000_to_2013": "4.8%",
"latitude": 40.7127837,
"longitude": -74.0059413,
"population": "8405837",
"rank": "1",
"state": "New York"
},
src/EasyTest.hs:213:1: error: bool is unused
211 ┃
212 ┃ bool :: Test Bool
213 ┃ bool = random
214 ┃
215 ┃ word8 :: Test Word8
Delete this definition or add ‘EasyTest.bool’ as a root to fix this error.
@seagreen
seagreen / with2.hs
Created January 25, 2020 22:30
temp temp temp
{-# LANGUAGE ScopedTypeVariables #-}
-- Based off of: https://github.com/ajnsit/concur/issues/17#issuecomment-516804859
module Lib where
import Control.Applicative
import Concur.Core
import Concur.Replica (HTML)
import Control.Concurrent.STM
import Prelude
@seagreen
seagreen / TinyServant.hs
Created September 16, 2019 20:51 — forked from kosmikus/TinyServant.hs
Implementation of a small Servant-like DSL
{-# LANGUAGE DataKinds, PolyKinds, TypeOperators #-}
{-# LANGUAGE TypeFamilies, FlexibleInstances, ScopedTypeVariables #-}
{-# LANGUAGE InstanceSigs #-}
module TinyServant where
import Control.Applicative
import GHC.TypeLits
import Text.Read
import Data.Time
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 32744 bytes for ChunkPool::allocate
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
@seagreen
seagreen / nixos.md
Created May 22, 2017 05:05 — forked from martijnvermaat/nixos.md
Installation of NixOS with encrypted root
@seagreen
seagreen / exchange-formats.md
Created April 2, 2017 05:30 — forked from gelisam/exchange-formats.md
A list of every data exchange formats I could find

At work, I just spent the last few weeks exploring and evaluating every format I could find, and my number one criteria was whether they supported sum types. I was especially interested in schema languages in which I could describe my types and then some standard specifies how to encode them using an on-the-wire format, usually JSON.

  1. Swagger represents sum types like Scala does, using subtyping. So you have a parent type EitherIntString with two subtypes Left and Right represented as {"discriminator": "Left", value: 42} and {"discriminator": "Right", value": "foo"}. Unfortunately, unlike in Scala in which the parent type is abstract and cannot be instantiated, in Swagger it looks like the parent type is concrete, so when you specify that your input is an EitherIntString, you might receive {"discriminator": "EitherIntString"} instead of one of its two subtypes.
  2. JSON-schema supports unions, which isn't quite the same thing as sum types because
@seagreen
seagreen / json_schema_failures.md
Last active January 13, 2017 03:48
Designing Quality JSON Schema Errors

Intro

The JSON Schema spec doesn't speak on error construction at all (which is absolutely the right decision).

This means that each library author has to figure out how to construct informative errors individually.

This document is meant to sketch out some best practices.

Example

Version 1.1.2 x86_64 hpack-0.14.1
2016-08-06 21:11:59.162271: [debug] Checking for project config at: /home/traveller/code/mine/tf-random/stack.yaml @(stack-1.1.2-DgLojysm1GF2dDrMpykv6D:Stack.Config src/Stack/Config.hs:811:9)
2016-08-06 21:11:59.163222: [debug] Loading project config file stack.yaml @(stack-1.1.2-DgLojysm1GF2dDrMpykv6D:Stack.Config src/Stack/Config.hs:829:13)
2016-08-06 21:11:59.166053: [debug] Using a nix-shell environment from file: /home/traveller/code/mine/tf-random/shell.nix @(stack-1.1.2-DgLojysm1GF2dDrMpykv6D:Stack.Nix src/Stack/Nix.hs:111:6)
2016-08-06 21:11:59.166215: [debug] Run process: nix-shell --pure /home/traveller/code/mine/tf-random/shell.nix --run "'/nix/store/i4nrh5f31a67ijpn9vf587lrlssg5mgq-stack-1.1.2/bin/stack' $STACK_IN_NIX_EXTRA_ARGS '--internal-re-exec-version=1.1.2' 'haddock' '--verbose'" @(stack-1.1.2-DgLojysm1GF2dDrMpykv6D:Stack.Exec src/Stack/Exec.hs:64:5)
Version 1.1.2 x86_64 hpack-0.14.1
2016-08-06 21:12:00.438458: [debug] Checking for project config at: /home/t