Skip to content

Instantly share code, notes, and snippets.

View JulianLeviston's full-sized avatar

Julian Leviston JulianLeviston

View GitHub Profile
@JulianLeviston
JulianLeviston / simple_todo.ex
Created December 1, 2016 02:22
TodoList implementation
defmodule TodoServer do
def start do
spawn(fn -> loop(TodoList.new) end)
end
def add_entry(todo_server, new_entry) do
send(todo_server, {:add_entry, new_entry})
end
def entries(todo_server, date) do
@JulianLeviston
JulianLeviston / Test.hs
Created June 4, 2017 11:51
Showing output from arbitrary grammar with some expressions
module Test where
data EExp a
= ELit a
| EAdd (EExp a) (EExp a)
eg1 :: EExp Int
eg1 = EAdd (ELit 1) (EAdd (ELit 2) (ELit 0))
eg2 :: EExp Int
@JulianLeviston
JulianLeviston / sigils.txt
Created June 8, 2017 23:07
Sigil Cheatsheet for Elixir 1.4
sigil_C/2 sigil_D/2 sigil_N/2 sigil_R/2 sigil_S/2 sigil_T/2
sigil_W/2 sigil_c/2 sigil_r/2 sigil_s/2 sigil_w/2
~C is a list of characters, no escaping or interpolation
~c is a list of characters, escaped and interpolated just like a single quoted string
~R is a regular expression with no escaping or interpolation
~r is a regular expression, escaped and interpolated
~S is a string with no escaping or interpolation
~s is a string, escaped and interpolated same as a double quoted string
~W is whitespace-delimited words as a list. No escaping or interpolation
{
"student_progress": [
{
"show_placement_test": false,
"id": "learning",
"complete_rows": [
2,
3,
4,
5,
@JulianLeviston
JulianLeviston / Doors.elm
Created November 24, 2018 11:19
Some code that illustrates a nice pattern of dependant update functions to allow flexible reuse and separation of concerns
module Doors exposing (main)
import Browser
import Html exposing (Html, button, div, h2, text)
import Html.Events exposing (onClick)
{-| This is an attempt at building up a dependency between pieces of state
that can be separate and then allowing us to compose them naturally.
module Alarm exposing (main)
import Browser
import Html exposing (Html, button, div, h2, text)
import Html.Events exposing (onClick)
{-| This is an attempt at building up a dependency between pieces of state
that can be separate and then allowing us to compose them naturally.
@JulianLeviston
JulianLeviston / Dijkstra.hs
Last active December 9, 2018 13:24
Dijkstra
module Dijkstra where
import qualified Data.Graph.Inductive.Graph as G
import Data.Graph.Inductive.Graph (mkGraph, labNodes, LEdge)
import Data.Graph.Inductive.PatriciaTree (Gr)
import qualified Data.Array as Ar
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Control.Monad.State as St
import Control.Monad.State (State, runState)
@JulianLeviston
JulianLeviston / README.md
Created September 17, 2019 23:30
Ember Twiddle Demo: Simple nested routes

Ember Twiddle Demo: Simple nested routes

Demo

Basic example of nested routes with some CSS to highlight the active route in the navigation links.

import Controller from '@ember/controller';
import { computed } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
firstName = 'Abe';
lastName = 'Simpson';
@computed('firstName', 'lastName')
get fullName() {