Skip to content

Instantly share code, notes, and snippets.

@choonkeat
choonkeat / track_events.js
Created August 19, 2010 05:37
Paste at the bottom of a webpage
// See: http://gist.github.com/537133
// standard script to track clicks on document elements, and send google analytic events
// identifying which element was clicked (classname, id, href, src, csspath)
// if "cssprefix_optional" is null, identify element as either using classname, id, href, src, csspath (order of preference)
// if "pagename_optional" is null, identify "event category" as page filename
(function(jQuery, pageTracker, cssselector, cssprefix_optional, pagename_optional) {
if (! jQuery) return;
try {
var baseurl = window.location.href.split(/[?#;]/)[0];
var pathsegments = baseurl.split('/');
@choonkeat
choonkeat / gist:2297910
Created April 4, 2012 05:10
street names of singapore
Abingdon Road
Adam Drive
Adam Park
Adam Road
Adis Road
Admiralty Drive
Admiralty Lane
Admiralty Link
Admiralty Road
Admiralty Road East
@choonkeat
choonkeat / ICal.elm
Created September 12, 2022 10:29
very rudimentary iCalendar format support in elm
module ICal exposing
( VAlarmAction(..)
, VAlarmTrigger(..)
, VCalendar(..)
, VEvent(..)
, VEventProp(..)
, VEventStatusValue(..)
, eventPropString
, eventString
, string
var http = require('http');
var querystring = require('querystring');
var MailParser = require("mailparser").MailParser; // https://github.com/andris9/mailparser
var server = http.createServer();
server.addListener('request', function(req, res) {
var chunks = [];
req.on('data', chunks.push.bind(chunks));
req.on('end', function() {
var mailparser = new MailParser();
@choonkeat
choonkeat / destructuring.md
Created May 20, 2022 01:12 — forked from yang-wei/destructuring.md
Elm Destructuring (or Pattern Matching) cheatsheet

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
module P exposing (..)
main : Program () number msg
main =
Platform.worker
{ init = always ( 0, Cmd.none )
, update = \_ _ -> ( 0, Cmd.none )
, subscriptions = always Sub.none
}
@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)

In a type specific module, we can name succinctly

module Channel

type Channel
    = Alpha
    | Beta
@choonkeat
choonkeat / external-aws-account.tf
Last active August 1, 2021 07:54
terraform declaration to "Another AWS account" with "external ID" for infrastructure scanning purpose, e.g. Cloudcraft
resource "aws_iam_role" "foobar-role" {
name = "foobar"
path = "/"
assume_role_policy = data.aws_iam_policy_document.foobar-assume-role-policy-document.json
managed_policy_arns = [aws_iam_policy.foobar-policy.arn]
}
data "aws_iam_policy_document" "foobar-assume-role-policy-document" {
statement {
actions = ["sts:AssumeRole"]
<div class="max-w-screen bg-gray-100 text-center">
<span class="text-red-400 sm:hidden">xs</span>
<span class="text-yellow-400 hidden sm:inline md:hidden">sm</span>
<span class="text-green-400 hidden md:inline lg:hidden">md</span>
<span class="text-blue-400 hidden lg:inline xl:hidden">lg</span>
<span class="text-purple-400 hidden xl:inline 2xl:hidden">xl</span>
<span class="text-pink-400 hidden 2xl:inline 3xl:hidden">2xl</span>
</div>
@choonkeat
choonkeat / Http.Extra.elm
Last active July 7, 2021 13:16
Http.task { resolver = Http.stringResolver decoder, ... }
module Http.Extra exposing (..)
import Http
import Json.Decode
{-| to obtain a String from `Http.task`
Http.task
{ resolver = Http.stringResolver httpStringBodyResolver