Skip to content

Instantly share code, notes, and snippets.

@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)->
@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 / 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 / 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 / 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
# 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

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

{
"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 01:28
Newton's square root method in coffeescript
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 December 17, 2015 22:38
Interface example in Go
package main
import (
"fmt"
"math"
)
type Shaper interface {
SurfaceArea() float64
Volume() float64