Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
digitalicarus / wee.js
Created May 4, 2012 21:00
JavaScript Game Loop
//http://www.gamedev.net/topic/579738-web-javascript-game-loop/
//http://dev.opera.com/articles/view/framerate-control-system-for-javascript/
//http://jsfiddle.net/digitalicarus/4kshN/3/
var WEE = {
FPS: 60,
rate: 60,
dt: 1/60,
accrued: 0.0,
last: Date.now()/1000,
@digitalicarus
digitalicarus / canvas_round_rect.js
Created June 29, 2012 03:01
canvas rounded rectangle
var roundRect = function(ctx,o) {
if(!ctx || !o.x || !o.y || !o.w || !o.h || !o.r) {
return;
}
var x = o.x,
y = o.y,
w = o.w,
h = o.h,
r = o.r,
@digitalicarus
digitalicarus / midpointDisplacement
Created July 5, 2012 02:37
2d midpoint displacement
/* http://www.gameprogrammer.com/fractal.html */
// Also, as expected, shifting is waaay faster than division, even in JS :) http://jsperf.com/division-vs-shift unfortunately it also truncates to the mantissa of floating points
// http://jsfiddle.net/digitalicarus/YUDgH/24/
// TODO: abs option, obj args, exception reason
var calcTerrain = function(conf) {
var height = conf.height,
swing = conf.swing,
h = conf.decay || conf.smooth || conf.smoothness,
i = conf.degree,
lb = (height-swing < 0) ? conf.lowerBound : null,
@digitalicarus
digitalicarus / smartReveal
Created September 17, 2012 18:52
fadey height
(function($){
$.fn.voila = function(content,cb) {
return this.each(function() {
var $this = $(this);
if($this.is(":visible")) {
//-- http://stackoverflow.com/questions/4085800/jquery-animate-changes-in-div-height-on-ajax-l
console.log("voila: origHeight="+$this.height());
$this
.animate({height: $this.height(), opacity: 'hide'}, 'fast', function(){
@digitalicarus
digitalicarus / callAsyncAndJoin
Created September 24, 2012 20:58
calls array of async functions and invokes callback when all done - shindig
/**
* Calls an array of asynchronous functions and calls the continuation
* function when all are done.
* @param {Array} functions Array of asynchronous functions, each taking
* one argument that is the continuation function that handles the result
* That is, each function is something like the following:
* function(continuation) {
* // compute result asynchronously
* continuation(result);
@digitalicarus
digitalicarus / regexen
Last active October 11, 2015 12:08
regexen
//-- JS number
[-+]?(?:(?:\d+)|(?:\d+\.\d+)|(?:\.\d+))(?:e[-+]?\d+)?
//-- vim non-greedy multiline http://www.fumbling-in-the-dark.com/2011/08/non-greedy-multi-line-search-and.html
%s/text1\_.\{-}text2/text3/
@digitalicarus
digitalicarus / loader.js
Created December 1, 2012 05:02
load js and css
function asyncLoader (s, cb) {
var d = document
, h = document.getElementsByTagName('head')[0]
, b = (Math.random()*1e8>>0)
, i = 'loader_'+b
, t = (/\.js$/.test(s)) ? "js" : "css"
, j = (t === 'js') ? d.createElement('script') : d.createElement('link');
j.id = i;
@digitalicarus
digitalicarus / .jshintrc
Created December 5, 2012 15:59 — forked from haschek/.jshintrc
JSHint Configuration, Strict Edition
{
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true
function parseQueryString(altStr) {
var s = altStr || window.location.search.substring(1)
, p = s.split("&")
, t = []
, q = {}
, i = 0
;
for(i = 0; i < p.length; i++) {
t = p[i].split("=");
@digitalicarus
digitalicarus / gist:4652503
Created January 28, 2013 02:35
lander "sprite"
this.parts = [
{
//head
points: [-1,2,-3,3,-3,6,-1,7,1,7,3,6,3,3,1,2,-1,2],
color: "#F00"
},
{
//body
points: [-3,2,3,2,3,-1,-3,-1,-3,2]
},