Skip to content

Instantly share code, notes, and snippets.

View kontur's full-sized avatar

Johannes Neumeier kontur

View GitHub Profile
@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']
@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: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: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: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: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:8435422
Created January 15, 2014 12:35
javascript strict boolean type casting
var something = something === true; // something will always be 'false' except for explicit 'true'
var something = something !== false; // something will always be 'true' except for explicit 'false'
@kontur
kontur / gist:6901510
Created October 9, 2013 13:43
Simple touch detection snipped
function is_touch_device() {
return 'ontouchstart' in window // works on most browsers
|| 'onmsgesturechange' in window; // works on ie10
};
if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
var msViewportStyle = document.createElement("style");
msViewportStyle.appendChild(document.createTextNode("@-ms-viewport{width:auto!important}"));
document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
}
@kontur
kontur / gist:5332271
Created April 7, 2013 20:08
MySQL CLI command to create csv view from select
SELECT *
FROM test
INTO OUTFILE '/tmp/test.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';