Skip to content

Instantly share code, notes, and snippets.

View tonymorris's full-sized avatar

Tony Morris tonymorris

View GitHub Profile
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data These a b =
This a
| That b
| Both a b
deriving (Eq, Show)
{-# LANGUAGE LambdaCase #-}
import Control.Lens
data Blah a =
Blah1 a
| Blah2 a
| BlahS String
deriving (Eq, Show)
// >>> given([notnull 1,null,notnull 3])
// null
// >>> given([notnull 1,notnull 2,notnull 3])
// notnull [1,2,3]
given(list) {
var r = List.empty
for(var i = 0; i < list.length; i++) {
if(list[i] == null)
return null
else
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y libreoffice imagemagick ghostscript rsync bash pdftk texlive-xetex texlive-luatex ttf-dejavu sudo zlib1g-dev ghc cabal-install
RUN export TZ=Australia/Brisbane
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN export LANG=C.UTF-8
RUN grep write /etc/ImageMagick-6/policy.xml
@tonymorris
tonymorris / Optics Cheatsheet.md
Last active June 1, 2020 10:40 — forked from ChrisPenner/Optics Cheatsheet.md
Optics Cheatsheet
// Which of f or g are more readable, and if possible, why?
def f(x: Seq[Int]): Int =
x.toList match {
case Nil => 99
case lst => lst.sum
}
def g(x: Seq[Int]): Int =
x.toList match {
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Data.Bool
data DataTypeWithMillionsOfConstructors =
DataTypeWithMillionsOfConstructors0
| DataTypeWithMillionsOfConstructors1
| DataTypeWithMillionsOfConstructors2
case class ListZipper[A](lefts: List[A], focus: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
ListZipper(lefts map f, f(focus), rights map f)
def ap[B](f: ListZipper[A => B]): ListZipper[B] =
ListZipper(
f.lefts.zip(lefts).map { case (ff, aa) => ff(aa) }
, f.focus(focus)
, f.rights.zip(rights).map { case (ff, aa) => ff(aa) }
)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www8.garmin.com/xmlschemas/FlightPlan/v1" xmlns:fp="http://www8.garmin.com/xmlschemas/FlightPlan/v1" targetNamespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1" elementFormDefault="qualified">
<xsd:annotation>
<xsd:documentation>
To transform a FlightPlan v1 XML document to GPX format a stylesheet will exist
on the Garmin website.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="flight-plan" type="FlightPlan_t">
<xsd:key name="WaypointIdKey">
data ZeroOrTwo a =
Zero
| Two a a
instance Functor ZeroOrTwo where
fmap _ Zero =
Zero
fmap f (Two a1 a2) =
Two (f a1) (f a2)