Skip to content

Instantly share code, notes, and snippets.

@choonkeat
choonkeat / App.elm
Last active March 17, 2024 02:37
various Main.elm templates (app, minimum, bootstrap)
module App exposing (Flags, Model, Msg(..), init, main, subscriptions, update, view)
import Browser
import Browser.Navigation
import Html exposing (Html, text)
import Url
main =
Browser.application
@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
@choonkeat
choonkeat / task.example.go
Last active November 24, 2023 01:06
Task type in Go
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"try-go/task"
def execute_command(command_name, arguments):
try:
if command_name == "google":
# Check if the Google API key is set and use the official search method
# If the API key is not set or has only whitespaces, use the unofficial search method
if cfg.google_api_key and (cfg.google_api_key.strip() if cfg.google_api_key else None):
return google_official_search(arguments["input"])
else:
return google_search(arguments["input"])
type TrafficLight
= Red
| Yellow
| Green
allTrafficLight : List TrafficLight
allTrafficLight =
let
helper list =
#!/bin/bash
set -euo pipefail
#
#
# `m3u8.txt` contains urls returned by `https://www.dandanzan.com/url.php`
# you can get them from your browser's network tab, look for `url.php`,
# copy the response body, and paste into your `m3u8.txt` file
#
#
@choonkeat
choonkeat / diy.cloudmailin.bash
Created August 1, 2012 10:33
receiving (postfix) emails via (rails) http; using file upload (-F) for less verbose Rails log (otherwise use --data-urlencode)
#!/bin/bash
MAILFILE=/tmp/mail.$$
CURLFILE=/tmp/mail.$$.curl
cat > $MAILFILE
curl -i -F message=@$MAILFILE "http://localhost/incoming_messages" > $CURLFILE
if grep 'HTTP/1.1 204 No Content' $CURLFILE
then
rm -f $CURLFILE $MAILFILE
fi
import Url
import Url.Parser exposing ((<?>))
import Url.Parser.Query

"http://example.com/?key=Prefix%3A+Some+text+%2B+Some+words+%3D+Words+%40+%3CLast+word%3E"
|> Url.fromString
|> Maybe.andThen (Url.Parser.parse (Url.Parser.top <?> Url.Parser.Query.string "key"))
--> Just (Just "Prefix: Some text + Some words = Words @ <Last word>")