Skip to content

Instantly share code, notes, and snippets.

# Find element's top-left position, cross-browser
# via http://www.kirupa.com/html5/get_element_position_using_javascript.htm
topLeft = (e)->
x = y = 0
@michiel
michiel / VimColorTest.vim
Last active December 16, 2015 15:39
vim color test script for ~/.vim/plugin
function! VimColorTest(outfile, fgend, bgend)
let result = []
for fg in range(a:fgend)
for bg in range(a:bgend)
let kw = printf('%-7s', printf('c_%d_%d', fg, bg))
let h = printf('hi %s ctermfg=%d ctermbg=%d', kw, fg, bg)
let s = printf('syn keyword %s %s', kw, kw)
call add(result, printf('%-32s | %s', h, s))
endfor
endfor
@michiel
michiel / random-canvas.coffee
Last active December 15, 2015 22:09
Visualize Math.random() in a canvas element
#
# Visualize random data on a canvas element
#
$ ->
canvas = $ "#canvas"
ctxt = canvas[0].getContext "2d"
@michiel
michiel / random-hex-color.coffee
Created March 25, 2013 20:27
Random hex color value in CoffeeScript
# Random hex color value in CoffeeScript
randomHexColor = (len=3)->
pattern = '0123456789ABCDEF'.split ''
str = '#'
for i in [1..len]
str += pattern[Math.round(Math.random() * pattern.length)]
@michiel
michiel / xml-jquery.coffee
Last active December 15, 2015 09:39
Fetch an XML file and parse it with jQuery
$ ->
$.ajax
url : 'path/file.xml'
dataType : 'xml'
success : (doc)->
$(doc).find('element').each ->
element = $ this
@michiel
michiel / bezier.coffee
Last active December 15, 2015 08:19
Bezier functions in CoffeeScript
_bez1 = (pct)->
Math.pow pct, 3
_bez2 = (pct)->
3 * Math.pow(pct, 2) * (1-pct)
_bez3 = (pct)->
3 * pct * Math.pow (1-pct), 2
_bez4 = (pct)->
package main
import (
"log"
"io"
"os"
"crypto/tls"
"strings"
"net"
"flag"
@michiel
michiel / sortingx.coffee
Last active October 2, 2015 17:48
some sorting in coffeescript
sort = (objs, attrs) ->
dojo.map(
(dojo.map objs, (obj) ->
arr = [obj]
dojo.forEach attrs, (attr) ->
arr.push obj.get(attr)
arr
).sort(
(attrsA, attrsB) ->
i = 1
@michiel
michiel / multisort.js
Created April 2, 2012 21:56
Some sorting
//
// Ex. sort on attrs = [
// ["Name", "asc"],
// ["Description, "desc"]
// ]
//
// This is how we do just one column,
//
// function sortOn(objs, attr, order) {
// return objs.sort(
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#