Skip to content

Instantly share code, notes, and snippets.

@wu-lee
wu-lee / concepts.nim
Created March 24, 2018 10:33 — forked from PhilipWitte/concepts.nim
How to use concept in Nim
type
CanDance = concept x
dance(x) # `x` is anything that has a `dance` procedure
proc doBallet(dancer: CanDance) =
# `dancer` can be anything that `CanDance`
dance(dancer)
# ---
@wu-lee
wu-lee / ns-100.html
Last active January 22, 2018 18:49
Clickable Number Squares
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Number Square</title>
<meta name="viewport" content="width=device-width">
<!DOCTYPE html5>
<html lang="en">
<head>
<style>
@import url('https://fonts.googleapis.com/css?family=Droid+Sans+Mono|Open+Sans');
body {
margin: 20px;
font: 16px 'Open Sans', sans-serif;
}
@wu-lee
wu-lee / im-pair.c
Created July 11, 2017 16:43
Immutable C lists experiment
#include "im-pair.h"
#include <stdio.h>
#include <stdlib.h>
bool imPairHeap_defaultOnEmpty(imPairHeap* heap)
{
fprintf(stderr, "heap 0x%p empty", heap);
exit(1);
}
<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css">@import url('https://themes.googleusercontent.com/fonts/css?kit=wAPX1HepqA24RkYW1AuHYA');.lst-kix_5wknczree46j-4>li:before{content:"\0025cb "}.lst-kix_8kgwfupas1dp-0>li{counter-increment:lst-ctn-kix_8kgwfupas1dp-0}.lst-kix_5wknczree46j-2>li:before{content:"\0025a0 "}.lst-kix_5wknczree46j-6>li:before{content:"\0025cf "}.lst-kix_5wknczree46j-3>li:before{content:"\0025cf "}.lst-kix_5wknczree46j-7>li:before{content:"\0025cb "}ol.lst-kix_ofx39mac5r44-8.start{counter-reset:lst-ctn-kix_ofx39mac5r44-8 0}ol.lst-kix_463rtqr13yoi-5.start{counter-reset:lst-ctn-kix_463rtqr13yoi-5 0}.lst-kix_5wknczree46j-5>li:before{content:"\0025a0 "}.lst-kix_b5d3ihyd12zv-6>li:before{content:"" counter(lst-ctn-kix_b5d3ihyd12zv-6,decimal) ". "}.lst-kix_5wknczree46j-8>li:before{content:"\0025a0 "}ol.lst-kix_pyr2qwdixxa2-4.start{counter-reset:lst-ctn-kix_pyr2qwdixxa2-4 0}.lst-kix_b5d3ihyd12zv-5>li:before{content:"" counter(lst-ctn-kix
@wu-lee
wu-lee / watch.bash
Created August 11, 2015 23:19
An inotifywait driven script to run erica push in a couchdb development directory
#!/bin/bash
root=$(dirname $(readlink -f $0))
app=$(basename $root)
src="$root/render"
couchdb=${couchdb:-http://${couchdb_auth:+$couchdb_auth@}localhost:5984/$app}
while true; do
echo "pushing $src to $couchdb id $app"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
make -f c.makefile clean upload
rm -f blink5.hex blink5.o nimcache/stdlib_system.o nimcache/stdlib_unsigned.o
avr-gcc -I ~/i/installs/Nim/lib -g -mmcu=atmega168 -c -o blink5.o blink5.c
avr-gcc -I ~/i/installs/Nim/lib -g -mmcu=atmega168 -c -o nimcache/stdlib_system.o nimcache/stdlib_system.c
avr-gcc -I ~/i/installs/Nim/lib -g -mmcu=atmega168 -c -o nimcache/stdlib_unsigned.o nimcache/stdlib_unsigned.c
avr-gcc blink5.o nimcache/stdlib_system.o nimcache/stdlib_unsigned.o -o blink5.bin
avr-objcopy -j .text -j .data -O ihex blink5.bin blink5.hex
avrdude -p atmega168 -c arduino -b19200 -e -U flash:w:blink5.hex -P /dev/ttyUSB1
;; FIXME work in progress
;; ----------------------------------------------------------------------
;; Gets a cons cell indicating the bounds of the current region (if set) or word
(defun bounds-of-word-or-region ()
(if (and transient-mark-mode mark-active)
(cons (region-beginning) (region-end))
(bounds-of-thing-at-point 'symbol)))
;; ----------------------------------------------------------------------
@wu-lee
wu-lee / gist:9274194
Created February 28, 2014 16:31
Using Apache as s CORS-handling proxy to a CouchDB server
<IfModule !proxy_module>
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
</IfModule>
<IfModule !proxy_http_module>
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
</IfModule>
<IfModule !headers_module>
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so