I hereby claim:
- I am IceCreamYou on github.
- I am icecreamyou (https://keybase.io/icecreamyou) on keybase.
- I have a public key whose fingerprint is 003D 9415 45F6 8791 898B 82BE 2F57 FE00 41D6 AF70
To claim this, I am signing this object:
/** | |
* Extract a multiline string from a multiline comment inside a function. | |
* | |
* @param {Function} fn The function containing the string. | |
* @param {vars} A map of tokens to values to replace in the string. | |
*/ | |
function textFromComment(fn, vars) { | |
var s = (fn + '').match(/^[\s\S]*?\/\*!?\s*([\s\S]+?)\s*\*\/$/m)[1]; | |
if (typeof vars !== 'undefined') { | |
var keys = Object.keys(vars).sort(function(a, b) { return b.length - a.length; }); |
I hereby claim:
To claim this, I am signing this object:
/** | |
* Returns a normally distributed random variable. | |
* | |
* Adapted from http://blog.yjl.im/2010/09/simulating-normal-random-variable-using.html | |
* To the extent I have the ability to do so, this code is released into the public domain. | |
*/ | |
function random_normal(mean, variance) { | |
if (typeof mean === 'undefined') { | |
mean = 0.0; | |
} |
/** | |
* Create or update the value of a URL query parameter. | |
* | |
* Given an input URL, a query parameter, and a value, if the query parameter | |
* already exists in the URL, this function replaces that paramter's value with | |
* the given value; otherwise, this function adds the parameter to the URL and | |
* sets it to the given value. Returns the modified URL. | |
*/ | |
function updateQueryParam(url, param, value) { | |
var search = new RegExp('([?&])(' + param + ')=[^&]*|$', 'i'); |
var container = document.getElementById('container'), // Pick the element(s) you care about | |
halfBoxSize = 0, // Facilitates placing boxes (click in the middle, get the upper-left coords) | |
roundPxToNearest = 5, // Snap to grid | |
roundPctToNearest = 0.0000001; // Precision for percentage values | |
container.addEventListener('click', reportLocation, false); // mousemove is another useful event | |
function reportLocation(event) { | |
var floorCoords = this.getBoundingClientRect(), | |
leftPx = roundPxToNearest * Math.round((event.clientX - floorCoords.left - halfBoxSize) / roundPxToNearest), | |
topPx = roundPxToNearest * Math.round((event.clientY - floorCoords.top - halfBoxSize) / roundPxToNearest), |
/** | |
* Returns the r^2 value for a three-dimensional data set. | |
* | |
* `r` is the Pearson product-moment correlation coefficient, a measure of | |
* linear correlation. | |
* | |
* @param {Object[]} data | |
* An array of vectors with `x`, `y`, and `z` properties representing points | |
* in the data set. | |
* |
// Basically copied directly from http://www.catswhocode.com/blog/using-keyboard-shortcuts-in-javascript | |
var isCtrl = false; | |
$(document).keyup(function (e) { | |
if (e.which == 17) | |
isCtrl = false; | |
}).keydown(function (e) { | |
if (e.which == 17) | |
isCtrl = true; | |
if (e.which == 83 && isCtrl == true) { | |
$('#searchbox').focus().select(); |
<!--break--> | |
<!-- script from https://github.com/dglittle/smiley-slider --> | |
<script type="text/javascript" src="https://raw.github.com/dglittle/smiley-slider/master/smiley-slider.js"></script> | |
<script> | |
jQuery(document).ready(function() { | |
var s = new SmileySlider(document.getElementById("slider"), 'https://github.com/dglittle/smiley-slider/raw/master/smiley-slider.png'); | |
s.position(0.5); | |
s.position(function (p) { | |
jQuery('.smiley-slider').val(Math.round(p*10)); | |
}); |
/** | |
* Periodically log a message to the JavaScript console. | |
* | |
* This is useful for logging things in loops; it avoids being overwhelmed by | |
* an unstoppable barrage of similar log messages. Example calls: | |
* | |
* # Log "message" to the console no more than every 500ms. | |
* logPeriodically('message', 500); | |
* # Log "message" as an error no more than every 500ms. | |
* logPeriodically('message', 500, console.error); |
/** | |
* Quickly returns a random UUID that is compliant with RFC-4122 Version 4. | |
* | |
* An example result is "2c3fa383-0d9d-4104-8fa2-58fdf614f021" | |
* | |
* Works in modern browsers and IE11+, and not Android Browser. A fallback if | |
* you care about those is to drop the Uint32Array and crypto lines, and | |
* replace the dX = buf[X] lines with dX = Math.random() * 0x100000000 >>> 0. | |
* In node.js do the same but use dX = crypto.randomBytes(4).readUInt32BE(0). | |
* |