Skip to content

Instantly share code, notes, and snippets.

View kfl's full-sized avatar
🤓
Happy

Ken Friis Larsen kfl

🤓
Happy
View GitHub Profile
@chrisdone
chrisdone / Intro.md
Last active May 20, 2024 12:44
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type

@kfl
kfl / simpleallocate.wat
Last active March 5, 2020 08:32
Simple WASM allocator
(module $simpleallocate
(global $ALIGN_MASK i32 (i32.const 7))
(global $MAX_SIZE_32 i32 (i32.const 1073741824))
(global $PAGE_SIZE i32 (i32.const 65536))
(global $next_free (mut i32) (i32.const 0))
(func $bytes_to_pages (param $n i32) (result i32)
(i32.add (i32.div_u (local.get $n)
(global.get $PAGE_SIZE))
(i32.const 1)))
@rxwei
rxwei / ad-manifesto.md
Last active November 9, 2023 09:58
First-Class Automatic Differentiation in Swift: A Manifesto
@chrisdone
chrisdone / review.md
Last active August 14, 2023 23:40
Email message parsing in Haskell in 2018

Email message parsing in Haskell in 2018

Background: I am moving away from GMail to my own Haskell-based server (SMTP receiver/sender, web-based email client, spam filtering, etc.). All email to @chrisdone.com goes through this server (mx.chrisdone.com) as of today, and chrisdone@gmail.com forwards a copy of everything to it.

This is a summary/tracking document of my efforts to simply parse email messages in Haskell for the SMTP receiver.

#include "mach_gettime.h"
#include <mach/mach_time.h>
#define MT_NANO (+1.0E-9)
#define MT_GIGA UINT64_C(1000000000)
// TODO create a list of timers,
static double mt_timebase = 0.0;
static uint64_t mt_timestart = 0;
@kfl
kfl / Sideeffects.sml
Last active March 14, 2019 12:41
Fun with side-effects in SML
(* Moscow ML handle the first three tests correct. *)
fun csnd x y = y
local val r = ref "WRONG" in
val test1 = csnd (r := "OK"; ()) (!r);
end
local
val r = ref "WRONG"
@nolanlawson
nolanlawson / fix_android_apk.py
Last active December 14, 2015 12:58
Fixes an Android APK built by PhoneGap Build to correct the problem of xhdpi images not being properly added (https://github.com/phonegap/build/issues/9). Requires apktool and jarsigner to already be installed.
#!/usr/bin/env python
# fix an Android APK built by PhoneGap Build to correct the problem of
# xhdpi images not being correctly added (https://github.com/phonegap/build/issues/9)
#
# REQUIRES apktool and jarsigner to already be installed and on the PATH.
#
# usage: fix_android_apk.py www/config.xml InputFile.apk OutputFile.apk
#
import os,sys,shutil,tempfile,xml.dom.minidom
@mcliment
mcliment / mapiconmaker.js
Created September 24, 2012 07:28
MapIconMaker for Google Maps API v3
/**
* @name MapIconMaker
* @version 2.0b
* @author Pamela Fox, Marc Climent
* @copyright (c) 2008 Pamela Fox, 2010 Marc Climent
* @fileoverview This gives you static functions for creating dynamically
* sized and colored marker icons using the Charts API marker output.
*/
/*
@davegurnell
davegurnell / ios-scroll.js
Created January 23, 2011 11:16
iOS HTML5 Scrollpane
/* iOS scrollpane jQuery plugin, v1.0
* ==================================
*
* (c) 2011 Dave Gurnell
* http://boxandarrow.com
*
* Distributed under the Creative Commons Attribution 3.0 Unported licence:
* http://creativecommons.org/licenses/by/3.0/
*/