Skip to content

Instantly share code, notes, and snippets.

@rev22
rev22 / LICENSE.txt
Last active August 29, 2015 14:13 — forked from 140bytes/LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@rev22
rev22 / simple-inheritance.coffee
Last active August 29, 2015 14:09
simple javascript/coffeescript inheritance
Person = ->
return
Person::hello = -> alert "hello"
John = ->
Person.call @
return
John::__proto__ = Person:: # This is shorter, but changing __proto__ is deprecated
# John:: = __proto__: Person::, constructor: John # this would be equivalent to the former line, but is longer!
John::hello = -> alert "ciao"
@rev22
rev22 / gist:5e2058959cf96582d715
Created November 10, 2014 01:37
transducer.coffee
Transducer =
employ: (x)-> x.call @
# Privitive transducers
map: (f)-> (conj)-> (a,b)-> conj(f(a), b)
mapcat: (f)-> (conj)-> (a,b)-> f(conj)(a, b)
filter: (f)-> (conj)-> (a,b)-> if f(a) then conj(a,b) else b
# Operator for binary composition of transducers
comp2: (a,b)-> (conj)-> a(b(conj))
@rev22
rev22 / gist:2d26deb56f944527da0f
Created October 25, 2014 17:02
multiple selection without CTRL
ignoreEvent = (event)->
event.preventDefault()
event.stopPropagation()
true
$('select[multiple]').each ->
select = $ @
values = {}
$('option',select)
.each (i, option)->
values[option.value] = !!option.selected
@rev22
rev22 / hsv2rgb.coffee
Created October 13, 2014 20:27
hsv2rgb rgb2hsv conversion (the hue value may have a different scale)
hsv2rgb = ([h,s,v])->
return [v,v,v] if s is 0
h = if h >= 1 then h - 1 else h
hh = h * 6
hhh = Math.floor hh
f = hh - hhh
a = v * (1.0 - s)
b = v * (1.0 - s * f)
c = v * (1.0 - s * (1 - f))
return switch hhh
@rev22
rev22 / soft-code-gitignore.patch
Created April 3, 2014 13:38
Allow a different file name rather than .gitignore, as a per-directory include file in git
--- git-2.0~next.20140207.orig/dir.c
+++ git-2.0~next.20140207/dir.c
@@ -1589,7 +1589,7 @@ void setup_standard_excludes(struct dir_
const char *path;
char *xdg_path;
- dir->exclude_per_dir = ".gitignore";
+ dir->exclude_per_dir = ignore_per_dir;
path = git_path("info/exclude");
if (!excludes_file) {
@rev22
rev22 / internet-time.js
Last active January 1, 2016 03:19
Javascript code to get Swatch Internet time ("Unlicense"'d)
"@"+("00"+Math.floor((((x.getUTCHours()+1)%24*60+x.getUTCMinutes())*60+x.getUTCSeconds()+(x.getUTCMilliseconds()*0.001))/86.4)).slice(-3)
@rev22
rev22 / gist:7669930
Last active December 29, 2015 12:19
Testing curve255js...
// Converts key from plain hexadecimal to inverted-byte hexadecimal
function hex2ibh(x) {
x = new Array(64 + 1 - x.length).join("0") + x; // Pad with '0' at the front
// Invert bytes
return x.split(/(..)/).reverse().join("");
}
function ibh2hex(x) {
//assert(length(x) == 64);
// Invert bytes
@rev22
rev22 / CamelCap.coffee
Last active December 20, 2015 14:29
Visual aid for CamelCase code in the ACE Editor; this can be compiled into a Bookmarklet
# Copyright (c) 2013 Michele Bini; MIT license
ace = window.ace ? window.__ace_shadowed__
if require = ace?.require
require ["ace/layer/text"], ({Text}) ->
orig = Text.prototype.$renderToken
patched = do (
rgx = new RegExp "[a-z][0-9]*[A-Z]", "g"
) -> (builder, col, token, value) ->
if match = rgx.exec value