Skip to content

Instantly share code, notes, and snippets.

  • Elm is not a frontend framework.
  • Elm is neither V in MVC, nor MV in MVC, nor even MVC itself.
  • You don't assemble libraries and configure options to make Elm do what you want.

Elm is a language. You write programs with it.

But instead of providing a regular main function to run, Elm wants you to write at least 2 parts to run your program: init and update. This is my pseudo code for your init and update plugs into Elm runtime:

let [globalState, cmd] = init(optionFlags)
@choonkeat
choonkeat / gosumtype_1_declaration.go
Last active November 28, 2023 14:15
Discriminated union for Go
package gosumtype
import (
"time"
)
// To define this sum type:
//
// type User
// = Anonymous
FROM golang:1.12.5-alpine3.9 as builder
RUN apk --no-cache add tzdata
COPY . /src
RUN go build -o /bin/timenow /src/timenow.go
FROM scratch
COPY --from=builder /bin/timenow /bin/timenow
# without these, TZ env is useless
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
@posener
posener / go-table-driven-tests-parallel.md
Last active October 29, 2024 13:01
Be Careful with Table Driven Tests and t.Parallel()

Be Careful with Table Driven Tests and t.Parallel()

We Gophers, love table-driven-tests, it makes our unittesting structured, and makes it easy to add different test cases with ease.

Let’s create our table driven test, for convenience, I chose to use t.Log as the test function. Notice that we don't have any assertion in this test, it is not needed to for the demonstration.

func TestTLog(t *testing.T) {
	t.Parallel()
@posener
posener / go-shebang-story.md
Last active October 18, 2024 01:42
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active November 15, 2024 16:21
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux
@bennuttall
bennuttall / remotegpio.md
Last active July 8, 2021 18:22
Set up a Pi and host PC for remote GPIO access using gpiozero

Remote GPIO

GPIO Zero allows you to create objects representing GPIO devices. As well as running it on a Raspberry Pi, you can also install GPIO Zero on a PC and create objects referencing GPIO pins on a Pi over the network.

To do this, you'll need to do a few things to get set up:

  1. Enable Remote GPIO on the Pi in the Raspberry Pi Configuration Tool.

  2. Run the pigpio daemon on the Pi:

@roylee0704
roylee0704 / dockergrep.sh
Created December 9, 2016 08:24
how to grep docker log
docker logs nginx 2>&1 | grep "127."
# ref: http://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container
@yous
yous / server.py
Created December 5, 2016 10:49
Multithreaded SimpleHTTPServer with basic auth
import os
import base64
import SocketServer
import BaseHTTPServer
import SimpleHTTPServer
class AuthHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
''' Main class to present webpages and authentication. '''
def do_AUTHHEAD(self):
self.send_response(401)
package main
//implements the SFTP Service. Needs to be installed and managed using NSSM.
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"