Skip to content

Instantly share code, notes, and snippets.

Work-around is:

name-to-upper = (person) -> person=^^person; person.name .= to-upper-case!
# or, in this case:
name-to-upper = (person) -> ^^person.name .= to-upper-case!

How would it handle default arguments? (person=^^defaultV) works: clone defaultV when person is not defined.

@josher19
josher19 / type-of.coffee
Created October 9, 2012 22:46
Testing type-of across frames in LiveScript
type-of = (typeof!)
y = type-of([1,2]) #=> 'Array'
x = type-of [1,2] #=> ['Number', 'Number']
iframe = document.createElement('iframe');
iframe.width = 50;
iframe.height= 50;
@josher19
josher19 / rotate-fonts.js
Created October 10, 2012 09:37
Get & Test Google Web Fonts and rotate through them by clicking on text. Chrome bookmarklet, requires jQuery.
(function() {
sel=document.getSelection()
// if (sel.focusNode) sel.focusNode.parentElement.style.fontFamily="'Poller One',sans-serif"
// function styling(ev) { sel.focusNode.parentElement.style.fontFamily="'Poller One',sans-serif"; }
// jQuery(document.body).bind('mouseup', styling, false);
@josher19
josher19 / surrealDecimals.js
Created October 26, 2012 06:21
Random Numbers, including Surreal Decimals
// random number between -1 and 1 with 0 most common result, linearly decreasing
function triangle() { return Math.random() + Math.random() - 1.0 }
// random number between -1.5 and 1.5 with 0 most common, roughly following the bell curve
function bell() { return Math.random() + Math.random() + Math.random() - 1.5 }
// random number between -1.5e-300 and 1.5e+300 with 50% of the numbers between -0.75 and 0.75
function wild() { return (Math.random() + Math.random() + Math.random() - 1.5) / (Math.random()+1e-300) }
// show distribution counts after 10,000 runs.
@josher19
josher19 / randomFrom.js
Created October 26, 2012 10:33
Semi-random number
function randomFrom(s0) {
return (1103515245 * s0 + 12345) % Math.pow(2,32);
}
@josher19
josher19 / surreal.js
Created November 5, 2012 10:36
Surreal Numbers (Conway)
// Surreal Number generation. Not exactly like Conway's version.
// 4 is [4]|[4] rather than [3]|[]
// so average of leftmost(left) and rightmost(right) is the value of the number
//
// Optimized for usage in Javascript and Node.
// TODO: Create Surreal class and github project.
function surreal_init(e) {
var left = [Math.floor(e)];
var right = [Math.ceil(e)];
@josher19
josher19 / raytracer.js
Created November 9, 2012 10:26
Raytrace in Canvas. Next up: animating it (takes over 1 second to render, though).
var Vector = (function () {
function Vector(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
Vector.times = function times(k, v) {
return new Vector(k * v.x, k * v.y, k * v.z);
@josher19
josher19 / tangled.html
Created November 9, 2012 10:27
Using Tangle for changing values
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href="http://worrydream.com/Tangle/" target="_top" />
<title>Tangle: Getting Started</title>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="Fonts/Insolent/stylesheet.css" type="text/css">
<link rel="stylesheet" href="Fonts/BorisBlackBloxx/stylesheet.css" type="text/css">
@josher19
josher19 / minidoc.js
Created November 29, 2012 08:30
document code using title attributes
/** Give documentation (via mouseover) in title attributes for functions in code highlighted with rainbowco.de */
function minidoc(docs,funcs) {
funcs = funcs || document.querySelectorAll('code span.function') // Could also do 'code span.method'
for(var i=0, len=funcs.length; i<len; ++i) {
var t = docs[funcs[i].textContent];
if (t) funcs[i].title = t;
}
}
@josher19
josher19 / i18n-jqueryui-dialogtitle.js
Created November 30, 2012 10:11 — forked from jlgrall/i18n-jqueryui-dialogtitle.js
i18next: Adds support for data-i18n and data-i18n-options to jQuery UI Dialog's title
// Adds support for data-i18n and data-i18n-options to jQuery UI Dialog's title:
if( $.fn.dialog ) { // Checks the presence of the dialog component of jQuery UI
var rTitleKey = /\[title\]([^;]*);?/,
// Keep a reference to the original _create function:
dialog_create_orig = $.ui.dialog.prototype._create;
$.ui.dialog.prototype._create = function( ) {
var data_i18n,
i18n_options;
if(!this.options.title) { // Because as defined in Dialog, the options.title should override the title attribute
var old_data_i18n = this.element.attr( "data-i18n" );