Skip to content

Instantly share code, notes, and snippets.

View wellcaffeinated's full-sized avatar

Jasper wellcaffeinated

View GitHub Profile
@wellcaffeinated
wellcaffeinated / update.json
Created October 20, 2012 23:13
YTSE-update test
[
{
"version": "1.1.0rc1",
"package": "https://www.dropbox.com/s/6ql6cqsbuael31w/YTSE-update-1.1.0rc1.zip?dl=1"
},
{
"version": "1.0.1",
"package": "https://www.dropbox.com/s/7uvyn80xdq33v5d/YTSE-update-1.0.1.zip?dl=1"
},
{
@wellcaffeinated
wellcaffeinated / ga-outbound-track.js
Created October 25, 2012 21:06
One-step outbound link tracking with google analytics
(function($, window, document){
$(document).on('click', 'a[href^=http]', function(e){
var $this = $(this)
,url = $this.attr('href')
,newtab = ($this.attr('target') === '_blank' || e.metaKey || e.ctrlKey)
;
window._gaq = window._gaq || [];
/*
* Photon
* http://photon.attasi.com
*
* Licensed under the MIT license.
* Copyright 2012 Tom Giannattasio
*/
//Country/Territory ISO code Source % of homicides by firearm Number of homicides by firearm Homicide by firearm rate per 100,000 pop Rank by rate of ownership Average firearms per 100 people Average total all civilian firearms
[
["Albania","AL","CTS",65.9,56,1.76,70,8.6,270000],
["Algeria","DZ","CTS",4.8,20,0.06,78,7.6,1900000],
["Angola","AO","",0,0,0,34,17.3,2800000],
["Anguilla","AI","WHO-MDB",24,1,7.14,0,0,0],
["Argentina","AR","Ministry of Justice",52,1198,3.02,62,10.2,3950000],
["Armenia","AM","CTS",13,9,0.29,52,12.5,380000],
["Australia","AU","NSO",11.5,30,0.14,42,15,3050000],
["Austria","AT","CTS",29.5,18,0.22,14,30.4,2500000],
/**
* Very simple find/replace template.
*
* Optional filter function that is used on tags with three curlies. Ex: `{{{this_param_will_be_filtered}}}`
*
* @function {mixin} Application.template
* @param {string} t templateable string
* @param {object} d data object
* @... {string} yourKey containing value to replace
* @param {function(value)} filter a filter function that is passed members of `d` that are templated by triple curlys
// Fake the :nth-child(#) selector shim for ie8
// @author Jasper Palfree <http://wellcaffeinated.net>
// finders props to Graham Losee
// ---------------------------------------------------
// limited functionality, only works for
// strictly numeric $n values and child
// elements must be of the same type.
// $sel is the type of selector.
// $extend is the class (or selector)
// to @extend from.
@wellcaffeinated
wellcaffeinated / asm-helpers.js
Last active December 22, 2016 22:45
Helper module for creating collections of objects that store their properties inside typed arrays. Useful for managing objects that will be used by asm.js modules. Code by Jasper Palfree (http://wellcaffeinated.net) License: MIT See comments for usage examples. See this blog post for explanation: http://wellcaffeinated.net/articles/2013/04/16/pl…
/**
* asm-helpers.js
* A simple helper module for managing memory allocation of
* collections of objects, particularly for use in asm.js code
*
* Copyright (c) 2013 Jasper Palfree <jasper@wellcaffeinated.net>
* Licensed MIT
*/
(function (root, factory) {
if (typeof exports === 'object') {
@wellcaffeinated
wellcaffeinated / raf.js
Created November 15, 2013 06:08
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Moller
// fixes from Paul Irish and Tino Zijdel
(function(window) {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@wellcaffeinated
wellcaffeinated / complex-expression.js
Created November 15, 2013 15:55
Complex expression parser (uses scratchpad.js)
!function(){
var orderOfOps = ['+', '-', '*', '/'];
var rules = {
'+' : 'add',
'-' : 'subtract',
'*' : 'multiply',
'/' : 'divide'
};
@wellcaffeinated
wellcaffeinated / math-utils.js
Created November 19, 2013 04:40
Very crude approximation to gaussian random number. It's fast, but it's NOT accurate.
// VERY crude approximation to a gaussian random number.. but fast
var gauss = function gauss( mean, stddev ){
var r = 2 * (Math.random() + Math.random() + Math.random()) - 3;
return r * stddev + mean;
};