Skip to content

Instantly share code, notes, and snippets.

View kontur's full-sized avatar

Johannes Neumeier kontur

View GitHub Profile
@kontur
kontur / gist:9344293
Created March 4, 2014 10:56
jQuery make nested element (img / video) cover the container area with debounced resize listener
$(function () {
var resizeTimer;
$(window).resize(function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(onResize, 50);
});
onResize();
function onResize() {
var $container = $("#container"),
@kontur
kontur / gist:5f328a0c065b2536ef16
Created June 19, 2014 08:46
Javascript object size (length) function
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
@kontur
kontur / gist:1a0ab32d3ccef97d4d06
Created June 19, 2014 08:48
Javascript Array polyfills
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
if (!Array.prototype.indexOf){
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
@kontur
kontur / gist:777f0409a04e041440c0
Last active August 29, 2015 14:03
Javascript window width detection that matches mediaquery pixel width
if ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth)> someMediaQueryBreakpointPointToMatch) {
...
}
@kontur
kontur / gist:5a7ed7b76041597fb820
Created July 14, 2014 13:50
Detect windows phone browser with no font face support
/(Windows Phone)|(XBLWP)|(ZuneWP)/.test(navigator.userAgent)&&$("body").addClass("no-fontface");
@kontur
kontur / gist:9fcbaef1b7396927d569
Created July 28, 2014 11:17
Javascript regexp to extract matrix values from a String into an Array
// via http://stackoverflow.com/a/14397066/999162
var matrixToArray = function(str){
return str.match(/(-?[0-9\.]+)/g);
};
matrixToArray('rgba(0, 0, 0, 0.5)'); // => ['0', '0', '0', '0.5']
matrixToArray('matrix(1, 0, 0, 1, -770, 0)'); // => ['1', '0', '0', '1', '-770', '0']
#!/bin/sh
echo "[post-rewrite hook: $1]"
# noah grant
# quick script to call bower install and npm install automatically if
# bower.json or package.json are changed, respectively
# this assumes one top-level file for each
changedfiles=( `git diff-tree --no-commit-id --name-only HEAD@{1} HEAD` )
@kontur
kontur / gist:65243806495e437a510d
Created August 12, 2014 13:48
Enable gzip/deflate to apache .htaccess / vhost config
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
</IfModule>
@kontur
kontur / Fullscreen
Created October 2, 2014 06:30
Make a processing sketch run in fullscreen
boolean sketchFullScreen() {
return true;
}
void setup() {
size(displayWidth, displayHeight);
}
@kontur
kontur / test.less
Last active August 29, 2015 14:18
Odd less @import error when *not* using colons after @ımport statement
body {
// surprisingly this will not throw an error, but it won't import the file neither
.mx({ @import: "test2.less"; });
}
body {
// this will throw an error:
// SyntaxError: Cannot read property 'rules' of undefined in /Users/johannes/test/less-bug/test.less on line 7, column 3:
// 6 body {
// 7 .mx({ @import "test2.less"; });