Skip to content

Instantly share code, notes, and snippets.

View bluesmoon's full-sized avatar

Philip Tellis bluesmoon

View GitHub Profile
@bluesmoon
bluesmoon / gist:69587
Created February 24, 2009 14:33
TMPL_VAR usage
<TMPL_VAR name="foo" default="bar" escape="html|url|js|none">
// Constructor
HTML.Template({
tmpl_str: tmpl,
OR
file_url: foo,
file_type: tmpl|js,
});
// Setting
HTML.Template.param({
@bluesmoon
bluesmoon / gist:774939
Created January 11, 2011 19:08
Measure page generation time using boomerang
<?php
$t_serverstart = microtime(true);
// rest of page generation goes in here
$t_serverend = microtime(true);
?>
<script type="text/javascript">
BOOMR.plugins.RT.setTimer("t_pagegen", <?php echo $t_serverend - $t_serverstart; ?>);
</script>
@bluesmoon
bluesmoon / LICENSE.txt
Created October 18, 2011 16:58 — forked from aemkei/LICENSE.txt
JS ASCII Logo - 140byt.es
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
@bluesmoon
bluesmoon / stddev-fast
Created April 25, 2012 15:57
Fast calculation of stddev
Datum: x
Size: n
Mean: m
variance = sum((x-m)^2)/n
= (x0-m)^2 + (x1-m)^2 + (x2-m)^2 ...
----------------------------------
n
@bluesmoon
bluesmoon / test-cipher.js
Created July 26, 2012 19:47
Test Node.js Cipher implementation.
crypto=require("crypto");
assert=require("assert");
data = [
// 0. Short key, short data, ascii data, hex output
{ k: "abcde", d: "foobar", enc_in: "ascii", enc_out: "hex" },
// 1. Long key, short data, ascii data, hex output
{ k: "abcdefabcdefabcdeabcdefabcdefabcdeabcdefabcdefabcdeabcdefabcdefabcdef", d: "foobar", enc_in: "ascii", enc_out: "hex" },
// 2. Long key, long data, ascii data, hex output
@bluesmoon
bluesmoon / FSWatcher-test.js
Created September 5, 2012 20:34
only first of multiple fs.FSWatchers will fire on a directory
var fs = require('fs')
fs.watch("./", function(event, filename) { console.log(1, event, filename); });
fs.watch("./", function(event, filename) { console.log(2, event, filename); });
fs.watch("./", function(event, filename) { console.log(3, event, filename); });
@bluesmoon
bluesmoon / README.md
Last active February 15, 2022 12:43
Pseudo-Random number generator that follows a Normal or Log-Normal distribution.

Marsaglia-polar.js

This script generates random numbers along a Normal or Log-normal distribution using the Marsaglia polar method.

There are four functions you can use:

  • normalRandom: Generate random numbers that follow a Normal distribution.
  • normalRandomInRange: Generate random numbers that follow a Normal distribution but are clipped to fit within a range
  • normalRandomScaled: Generate random numbers that follow a Normal distribution with a given mean and standard deviation
  • lnRandomScaled: Generate random numbers that follow a Log-normal distribution with a given geometric mean and geometric standard deviation
// Support routines for automatically reporting user timing for common analytics platforms
// Currently supports Google Analytics, Boomerang and SOASTA mPulse
// In the case of boomerang, you will need to map the event names you want reported
// to timer names (for mPulse these need to be custom0, custom1, etc) using a global variable:
// rumMapping = {'aft': 'custom0'};
(function() {
var wtt = function(n, t, b) {
t = Math.round(t);
if (t >= 0 && t < 3600000) {
// Google Analytics
@bluesmoon
bluesmoon / boomerang-1-loaded-event.js
Last active June 13, 2017 17:01
Code to identify when boomerang has loaded
// You can give this function any name, just use the same name on lines 18 & 22 below
function boomerang_loaded_handler(e) {
// Older IE stored the event in window.event global
if(!e) { e = window.event; }
// If there is no event or this is a "propertychange" event and the propertyName is not onBoomerangLoaded,
// then abort
if(!e || (e.hasOwnProperty("propertyName") && e.propertyName !== "onBoomerangLoaded")) {
return;
}