Skip to content

Instantly share code, notes, and snippets.

providerName =
case global.selectedProvider of
Nothing -> "(None)"
provider.name
-- Same as
providerName = Maybe.unwrap "(None)" .name global.selectedProvider
@RobertFischer
RobertFischer / Unwrapping.elm
Created November 15, 2017 17:29
The goal is to get a MilestonesMsg created from a GlobalModel instance.
milestoneBtnMsg =
global.selectedCareplan -- Start with the careplan
|> Maybe.andThen .id -- Call .id on it if it's Just; return Nothing if it's Nothing or id is Nothing
|> Maybe.map MilestonesRoute -- Wrap it in a MilestonesRoute if we have a Just
|> Maybe.withDefault DoNothing -- If we have a Nothing, return DoNothing; otherwise, return the value in the Just
@RobertFischer
RobertFischer / Main.elm
Created October 4, 2017 20:00
Nifty Trick for Loading CSS in Pure Elm
module Main exposing (main)
import Navigation exposing (program, Location)
import Platform.Cmd as Cmd exposing (Cmd)
import Platform.Sub as Sub exposing (Sub)
import Html exposing (Html)
import Html.Attributes as Attr
import Html.Events as Event
import Routes exposing (Route(..))
import RemoteData exposing (..)
@RobertFischer
RobertFischer / Lib.hs
Created March 28, 2017 17:27
What's wrong with this?
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Lib
( startApp
, app
) where
import Data.Aeson
import Data.Aeson.TH
@RobertFischer
RobertFischer / gist:df1a7027c1f8bb8e401edb90fcad9089
Created January 18, 2017 15:22
Changesets with state count (for Dave)
robert=# \d+ changeset
Table "public.changeset"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+--------------------------------------------------------+---------+--------------+-------------
id | integer | not null default nextval('changeset_id_seq'::regclass) | plain | |
Indexes:
"changeset_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "state" CONSTRAINT "state_changeset_id_fkey" FOREIGN KEY (changeset_id) REFERENCES changeset(id)
@RobertFischer
RobertFischer / HashFlash.js
Created March 7, 2016 21:00
Flash detection with Modernizr and Check1.js
<html>
<head>
<script src="check1.js"></script>
<script>
var modzrFlash;
Check1(
"hasFlash",
"https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
function() {
return Modernizr.flash;
public enum TimePeriod {
ONE_YEAR_AGO(Calendar.YEAR, -1),
THREE_MONTHS_AGO(Calendar.MONTH, -3),
// and so on...
;
private int calendarField;
private int changeMagnitude;
private TimePeriod(int calendarField, int changeMagnitude) {
@RobertFischer
RobertFischer / MagnusProperty.groovy
Created August 25, 2015 22:34
Example of type-safe properties
@CompileStatic
abstract class MagnusProperty<T> {
final String key;
MagnusProperty(String key) {
assert key : "No key provided!"
this.key = key
}
@RobertFischer
RobertFischer / ExceptionEater.java
Created August 25, 2015 14:57
ExceptionEater with Optional
public class ExceptionEater {
private static final Logger log = //TODO Create Logger
public static <T> Optional<T> swallowNPE(Supplier<T> producer) {
try {
return Optional.ofNullable(supplier.get());
} catch(NullPointerException npe) {
log.info("NullPointerException being swallowed", npe);
return Optional.empty();
@RobertFischer
RobertFischer / ExceptionEater.java
Created August 25, 2015 14:49
Lambda for the pattern of eating exceptions
public class ExceptionEater {
private static final Logger log = //TODO Create Logger
public static <T> T swallowNPE(Supplier<T> producer) {
try {
return supplier.get();
} catch(NullPointerException npe) {
log.info("NullPointerException being swallowed", npe);