Skip to content

Instantly share code, notes, and snippets.

View alexspurling's full-sized avatar

Alex Spurling alexspurling

View GitHub Profile
@alexspurling
alexspurling / MJTimes.java
Created March 17, 2023 15:52
When did Michael Jackson's hair catch on fire?
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
/*
output:
Earliest midpoint in LA: 1984-01-26T17:13-08:00[America/Los_Angeles]
Latest midpoint in LA: 1984-01-27T05:13-08:00[America/Los_Angeles]
@alexspurling
alexspurling / git_svn_bash_prompt.sh
Last active August 8, 2018 05:51 — forked from woods/git_svn_bash_prompt.sh
Update of prompt colours and terminal title
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
@alexspurling
alexspurling / XMLLexer.g4
Last active June 18, 2018 19:07
Adaptation to XML ANTLR Grammar
/*
[The "BSD licence"]
Copyright (c) 2013 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@alexspurling
alexspurling / Canvas.elm
Created August 21, 2016 13:56
Possible Elm model update syntax
update : Msg -> Model -> Model
update msg model =
case msg of
CanvasResized canvasSize ->
model
|> :canvas
|> updateCanvasSize canvasSize
|> updateVisibleTiles
get = -> {
secret_callback = -> {
secret_squirrly_function = -> {secret_callback(err, res, body)}
# Do something asynchronous
setTimeout secret_squirrly_function, 5000
# and return a function
(callback) -> {secret_callback = callback}
}
}
@alexspurling
alexspurling / Decoder.elm
Created November 10, 2015 18:09
Not sure how to complete these Json Decoder example.
type alias Answer =
{ name : String,
imgUrl : String
}
decodeAnswers : Json.Decoder (List Answer)
decodeAnswers =
let
imageUrlDecoder = ("url" := Json.string)
@alexspurling
alexspurling / InitialValues.elm
Last active September 15, 2015 13:13
Port initial value example
module InitialValues where
import Graphics.Element exposing (..)
port timestamp : Int
main =
show ("Hello" ++ (toString (timestamp + 2)))
@alexspurling
alexspurling / randomexample.elm
Last active September 15, 2015 11:56
Elm example for producing random values in a model
import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp
import Random exposing (Seed)
type alias Model = { seed : Seed, values : List Int }
initialModel : Model
initialModel =
{ seed = (Random.initialSeed 0),
{ "_id" : "7183414623122970455", "name" : "Bob", "items" : [ { "id" : 29 }, {"id" : 37 } ], "itemCount" : 2 }
{ "_id" : "-1843045741878739623", "name" : "Jim", "items" : [ { "id" : 93 }, { "id" : 51 }, { "id" : 42 }, { "id" : 11 } ], "itemCount" : 4 }
...
@alexspurling
alexspurling / Comment.java
Created June 28, 2010 18:22
Simple example of MongoDB driver for Java
public class Comment {
private final String author;
private final String body;
public Comment(String author, String body) {
this.author = author;
this.body = body;
}