Skip to content

Instantly share code, notes, and snippets.

View jbt's full-sized avatar

James Taylor jbt

View GitHub Profile
@jbt
jbt / formatDate.js
Created September 27, 2011 19:20
JavaScript implementation of PHP's date formatting
/*
* JavaScript implementation of PHP date formatting.
* Author: JT <jt@gosquared.com>
*
* Usage: formatDate('Y M d H:i:s', dateObject)
* or formatDate('Y M d H:i:s') to use current time
*
* This function is free for you to use however you please. Use it or
* modify it however you like. All I ask is that you don't just pass
* it off as your own. I hope it's useful!
@jbt
jbt / gist:1805044
Created February 11, 2012 23:28
Here's something cool
var a=function(){function m(a){this.v=a;this.K=new n(a,100*e.d,100*e.c);this.la=[u[0]*v,u[1]*v];this.ja=new o(q,e);this.m=new w(0.6,0.01);this.n=new x;document.addEventListener("mousedown",this.pa.bind(this));document.addEventListener("mousemove",this.qa.bind(this));document.addEventListener("mouseup",this.ra.bind(this))}function l(a,b){this.a=a;this.p=b;this.axis=[[1,0],[0,1]];this.margin=1.0E-7}function w(a,b){this.N=a;this.P=b;this.i=[]}function r(a){a=a||{};this.a=a.a||[1,1];this.dir=
a.dir||[0.15,0];this.z=a.z||128;this.g=a.g||1}function x(){this.h=[];this.w=[];this.H=1500}function s(a,b,c){a instanceof Array?(this.a=a,this.l=[a[0],a[1]],this.g=b||1,this.o=c||[0,0],this.b=[0,0]):(this.a=a.a||[0,0],this.l=a.l||[0,0],this.g=a.g||1,this.o=a.o||[0,0],this.b=a.b||[0,0]);this.ua=new y(0.01);this.r=new z(this.a,0.25*q);this.u()}function z(a,b){this.a=a;this.margin=b}function n(a,b,c){this.v=a;a.style.width=b+"px";a.style.height=c+"px";this.d=b;this.c=c;a=this.canvas=document.createElement("canvas");
a.width=b;a
@jbt
jbt / gist:2273631
Created April 1, 2012 08:43
I made a cool thing
(function(g){g("f_\";:\x1f\\[.|nAyH|v\x26gs+}h#9SITu4RHpu6;a@F<Ghn+Z5^@\x1feG$'j)h'gW$ht!'7DTz'\\AwgO-4RHp$@\x26e}=mnlEZ}hHbf~3PIEk?d2I`^u bYJFl@RNWHC:;)AKl\\3Ifr[$9RSHiKB{`JK@a\x1f>`!CPluSOuI5N^*H_yx5d?/0%F?P5SO])?x\x26@4u[yu\"Tgyzo/57ZM~;1YXh|.J`\"n<[}|(DM?h \x1fb+;CPU3Kl(MTyvf3^1i\x7fJc\x266XU!*>?4UcS89.Oh 0r+>F^z+,!B'(~>Tx ^5T?/(akgpa1h_(<-,_n*H>fVf?'0E)WSdseac+CGln_}K\x26k40,R\x26U_*A_#j\x1fXg uU<,%^~[2Nd\x26pcz-F 6Dz7-U5Mer!#'(?r[.>Re 6YR#1R^l')?XA*HwRM[w0H`cdYzz^<Tu|2IQ(Giv1:Gy\x26ear Yg\"$^rN@%<FZ%L}HR7^POF\x7f?^prdRplzb4X.dYp u {0oiL*c;Q.xmv(:wZ",22,97,31,492,"",g)})(function(a,b,c,d,e,f,g){for(;e--;)f+=String.fromCharCode(((a.charCodeAt(e)+e-d)*b)%c+d);eval(f)})
@jbt
jbt / gist:2419469
Created April 19, 2012 07:48
jQuery jsonp auto-generated callbacks memory leak.
<?php
// Only run this locally, unless you want to bombard your server with hundreds of requests a second.
if($_GET['a']) die( $_GET['callback'] . '(false);');
?>
<!DOCTYPE html>
<html>
<head>
@jbt
jbt / gist:3112153
Created July 14, 2012 17:08
Comparator function
/*
Ridiculously useful function
Sorts elements of an array by properties
Usage:
Sort elements by property prop1, then by prop2 if prop1 values are equal
someArrayOfObjects.sort(comparator('prop1', 'prop2'));
*/
function comparator(){
@jbt
jbt / gist:3150819
Created July 20, 2012 13:47
If you can tell me what these two functions are for, you win a prize
t.prototype.REDACTED = function(a, b, j, c, g) {
for(var r = this.REDACTED2(0), t = Math.tan(r), C = g % 86400 / 86400 * Math.PI * 2, g = [], n = 0;n <= c + 1;n = n + 1) {
g[n] = Math.atan(Math.cos(2 * Math.PI * (j + n / c) / a + C) / t) / Math.PI * c * a / 2 - (b - a / 4) * c;
}
b = Math.max.apply(Math, g);
j = Math.min.apply(Math, g);
a = "";
if(g[0] > 0 && g[0] < c) {
a = "M0," + g[0];
if(b >= c) {
@jbt
jbt / hello.js
Created September 7, 2012 20:54
Just found this, called blah.js, in my ~/Development
alert("
@jbt
jbt / gist:3847944
Created October 7, 2012 11:26
Think I broke node.
"res[860] = /(?:[\\040\\t]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff])*\\))*\\))*(?:(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\"(?:[^\\\\\\x80-\\xff\\n\\015\"]|\\\\[^\\x80-\\xff])*\")(?:(?:[\\040\\t]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff])*\\))*\\))*\\.(?:[\\040\\t]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff])*\\))*\\))*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\"(?:[^\\\\\\x80-\\xff\\n\\015\"]|\\\\[^\\x80-\\xff])*\"))*(?:[\\040\\t]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff])*\\))*\\))*@(?:[\\040\\t]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff]|\\((?:[^\\\\\\x80-\\xff\\n\\015()]|\\\\[^\\x80-\\xff])*\\))*\\)
@jbt
jbt / gist:5055782
Last active December 14, 2015 08:08
Super-tiny recursive directory list in nodejs, if you don't care that you're using sync functions.
var fs = require('fs');
function ls(dirname){
return [].concat.apply([], fs.readdirSync(dirname).sort().map(function(f){
f = dirname + '/' + f
return fs.statSync(f).isDirectory() ? ls(f) : f
}));
}
@jbt
jbt / index.html
Last active December 14, 2015 15:29
Example use of GoSquared polymaps fork.
<!DOCTYPE html>
<html>
<head>
<title>Polymaps Example</title>
<script src="polymaps.min.js"></script><!-- polymaps from gosquared/polymaps -->
</head>
<body>
<svg id="map" width="1000" height="800"></svg>