Skip to content

Instantly share code, notes, and snippets.

View kontur's full-sized avatar

Johannes Neumeier kontur

View GitHub Profile
@kontur
kontur / gist:3789544
Created September 26, 2012 18:02
empty a php array of values, but leave the keys
array_map(create_function('', ''), $array);
@kontur
kontur / gist:3839798
Created October 5, 2012 13:25
javascript getter for a flash object on page, for calls to external interface
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf('Microsoft') !== -1;
return (isIE) ? window[movieName] : document[movieName];
}
// with a swfobject embedding like:
var flashvars = {};
var params = {};
var attributes = {};
attributes.id = "myFlash"; // required for flash to javascript communication
@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';
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: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
};
@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: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) {
...
}