Skip to content

Instantly share code, notes, and snippets.

@timohausmann
timohausmann / gist:5883813
Created June 28, 2013 10:28
Bitwise operations
//Math.floor( a * 2 )
a = a << 1
// Math.floor( a / 2 )
a = a >> 1
/* The Grid ---------------------- */
.row { width: 1080px; max-width: 100%; min-width: 768px; margin: 0 auto; }
.row .row { width: auto; max-width: none; min-width: 0; margin: 0 -15px; }
.row.large-collapse .column,
.row.large-collapse .columns { padding: 0; }
.row .row { width: auto; max-width: none; min-width: 0; margin: 0 -15px; }
.row .row.large-collapse { margin: 0; }
.column, .columns { float: left; min-height: 1px; padding: 0 15px; position: relative; }
.column.large-centered, .columns.large-centered { float: none; margin: 0 auto; }
@timohausmann
timohausmann / first frame
Created April 23, 2013 10:33
Flash AS2: Wait
var interval;
var displayTime = 4000;
function wait( delay ) {
stop();
interval = setInterval(waitContinue, delay);
}
function waitContinue() {
play();
@timohausmann
timohausmann / gist:5364550
Created April 11, 2013 15:51
jQuery: reverse
$.fn.reverse = [].reverse;
@timohausmann
timohausmann / gist:5203276
Created March 20, 2013 09:01
Javascript: restrain maximum dimensions
var aspectRatio = width / height;
if( height > APP.height ) {
height = APP.height;
width = height * aspectRatio;
} else if( width > APP.width ) {
width = APP.width;
height = width / aspectRatio;
}
@timohausmann
timohausmann / gist:5097741
Created March 6, 2013 08:54
Javascript: Render To Canvas Buffer
var renderToCanvas = function (width, height, renderFunction) {
var buffer = document.createElement('canvas');
buffer.width = width;
buffer.height = height;
renderFunction(buffer.getContext('2d'));
return buffer;
};
// 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) {
@timohausmann
timohausmann / gist:5056007
Created February 28, 2013 11:11
CSS: Sexy Image Replacement
.ir {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@timohausmann
timohausmann / gist:5055811
Last active December 14, 2015 08:09
HTML: HTML5 Template
<!doctype html>
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<title>Seitentitel</title>
<meta charset="utf-8" />
<meta name="description" content="Kurzbeschreibung der Seite, idealerweise unter 160 Zeichen" />
@timohausmann
timohausmann / gist:5003280
Created February 21, 2013 08:43
Javascript Math: get the distance between two points.
/**
* return the distance between two points.
*
* @param {number} x1 x position of first point
* @param {number} y1 y position of first point
* @param {number} x2 x position of second point
* @param {number} y2 y position of second point
* @return {number} distance between given points
*/
Math.getDistance = function( x1, y1, x2, y2 ) {