Skip to content

Instantly share code, notes, and snippets.

View choonkeat's full-sized avatar

Chew Choon Keat choonkeat

View GitHub Profile
View commands.py
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"])
View slamdunk.1993.sh
#!/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
#
#
View ElmUrlQuirk.md
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>")
@choonkeat
choonkeat / ICal.elm
Created September 12, 2022 10:29
very rudimentary iCalendar format support in elm
View ICal.elm
module ICal exposing
( VAlarmAction(..)
, VAlarmTrigger(..)
, VCalendar(..)
, VEvent(..)
, VEventProp(..)
, VEventStatusValue(..)
, eventPropString
, eventString
, string
@choonkeat
choonkeat / destructuring.md
Created May 20, 2022 01:12 — forked from yang-wei/destructuring.md
Elm Destructuring (or Pattern Matching) cheatsheet
View destructuring.md

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@choonkeat
choonkeat / P.elm
Last active April 26, 2022 02:11
elm overhead
View P.elm
module P exposing (..)
main : Program () number msg
main =
Platform.worker
{ init = always ( 0, Cmd.none )
, update = \_ _ -> ( 0, Cmd.none )
, subscriptions = always Sub.none
}
View allVariants.elm
type TrafficLight
= Red
| Yellow
| Green
allTrafficLight : List TrafficLight
allTrafficLight =
let
helper list =
@choonkeat
choonkeat / Custom Type Naming Convention.md
Last active October 6, 2021 10:35
Custom Type Naming Convention (hope I can gist search this time; wrote it before)
View Custom Type Naming Convention.md

In a type specific module, we can name succinctly

module Channel

type Channel
    = Alpha
    | Beta