Skip to content

Instantly share code, notes, and snippets.

View hendriklammers's full-sized avatar

Hendrik Lammers hendriklammers

View GitHub Profile
@hendriklammers
hendriklammers / gist:3760498
Created September 21, 2012 09:07
Javascript: Calculate Radians/Degrees
// Returns radians from the given value in degrees
function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}
// Returns degrees from the given value in radians
function radiansToDegrees(radians) {
return radians * (180 / Math.PI);
}
@hendriklammers
hendriklammers / canvas.html
Created September 20, 2012 14:46
html: Canvas starter page
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Canvas</title>
<style>
* {
margin: 0;
padding: 0;
}
@hendriklammers
hendriklammers / rAF.js
Created September 20, 2012 07:53 — forked from paulirish/rAF.js
Javascript: 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 Möller
// fixes from Paul Irish and Tino Zijdel
(function () {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
@hendriklammers
hendriklammers / jquery.ba-tinypubsub.js
Created September 19, 2012 14:05 — forked from cowboy/HEY-YOU.md
jQuery: Tiny Pub/Sub
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@hendriklammers
hendriklammers / gist:3714478
Created September 13, 2012 13:55
Javascript: Object.create
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
@hendriklammers
hendriklammers / gist:3709109
Created September 12, 2012 18:58
Javascript: Sort array by property value
function dynamicSort(property) {
return function (a, b) {
return (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
};
}