Skip to content

Instantly share code, notes, and snippets.

@michiel
michiel / bezier.coffee
Last active Dec 15, 2015
Bezier functions in CoffeeScript
View bezier.coffee
_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)->
@michiel
michiel / xml-jquery.coffee
Last active Dec 15, 2015
Fetch an XML file and parse it with jQuery
View xml-jquery.coffee
$ ->
$.ajax
url : 'path/file.xml'
dataType : 'xml'
success : (doc)->
$(doc).find('element').each ->
element = $ this
@michiel
michiel / random-hex-color.coffee
Created Mar 25, 2013
Random hex color value in CoffeeScript
View random-hex-color.coffee
# 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 / random-canvas.coffee
Last active Dec 15, 2015
Visualize Math.random() in a canvas element
View random-canvas.coffee
#
# Visualize random data on a canvas element
#
$ ->
canvas = $ "#canvas"
ctxt = canvas[0].getContext "2d"
@michiel
michiel / VimColorTest.vim
Last active Dec 16, 2015
vim color test script for ~/.vim/plugin
View VimColorTest.vim
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
View topleft.coffee
# 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
View encrypted-git-repo.md

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang (geek@cerias.net). It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].

Description

When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes

View projections.json
{
"app/assets/javascripts/models/*.coffee": {
"command": "jmodel",
"alternate": "spec/javascripts/models/%s_spec.coffee",
"template": "App.%S = DS.Model.extend"
},
"app/assets/javascripts/controllers/*_controller.coffee": {
"command": "jcontroller",
"alternate": "spec/javascripts/controllers/%s_spec.coffee",
@michiel
michiel / newton_sqrt.coffee
Created May 31, 2013
Newton's square root method in coffeescript
View newton_sqrt.coffee
sqrt = (x, conv=10)->
y = 1
for i in [0..conv]
y = y - ((y*y - x) / (2*y))
y
@michiel
michiel / interface_ex.go
Last active Dec 17, 2015
Interface example in Go
View interface_ex.go
package main
import (
"fmt"
"math"
)
type Shaper interface {
SurfaceArea() float64
Volume() float64