Skip to content

Instantly share code, notes, and snippets.

View rudiedirkx's full-sized avatar

Rudie Dirkx rudiedirkx

View GitHub Profile
@rudiedirkx
rudiedirkx / is_numeric_array.php
Created October 8, 2011 12:12
is_numeric_array
<?php
$a1 = array('x', 'a' => 'b', 'c', 'd', 'e');
print_r($a1);
var_dump(is_numeric_array($a1)); // false
$a2 = array('a', 'b', 'c', 'd', 'e');
print_r($a2);
@rudiedirkx
rudiedirkx / gist:1290931
Created October 16, 2011 14:33
setTimeout arguments polyfill
window.setTimeout(function() {
if ( !arguments.length ) {
// polyfill
var sto = window.setTimeout;
window.setTimeout = function(cb, speed) {
var args = [];
for ( var i=2; i<arguments.length; i++ ) {
args.push(arguments[i]);
}
sto(function() {
@rudiedirkx
rudiedirkx / time_ago.php
Created December 28, 2011 17:06
Time ago function
<?php
// Example: http://hotblocks.nl/tests/time_ago.php
function time_ago( $f_seconds, $f_size = 2, $f_factor = 1.6 ) {
$units = array(
86400*365.25 => array(' year', ' years'),
86400*30 => array(' month', ' months'),
86400*7 => array(' week', ' weeks'),
86400 => array(' day', ' days'),
@rudiedirkx
rudiedirkx / dabblet.css
Created January 5, 2012 18:04 — forked from anonymous/dabblet.css
Double Opacity
/**
* Double Opacity
*/
body{background:green;}
#baz{
opacity: 0.6;
}
#foo{
height:150px;
@rudiedirkx
rudiedirkx / placeholder.js
Last active October 8, 2015 15:18
Placeholder polyfill (Drupal behavior)
// As seen in bozo/custom.js
(function($) {
Drupal.behaviors.placeholderPolyfill = {
attach: function(context, settings) {
if ( !('placeholder' in document.createElement('input')) ) {
var onFocus = function(e) {
this.$this || (this.$this = $(this));
@rudiedirkx
rudiedirkx / matchesSelector.js
Created August 15, 2012 11:06
JS polyfill for Element.matchesSelector
Element.prototype.matchesSelector || (Element.prototype.matchesSelector = Element.prototype.webkitMatchesSelector || Element.prototype.mozMatchesSelector || function(selecta) {
var els = document.querySelectorAll(selecta);
for ( var i=0, L=els.length; i<L; i++ ) {
if ( els[i] == this ) {
return true;
}
}
return false;
});
@rudiedirkx
rudiedirkx / dbsecrets.js.php
Created August 26, 2012 12:17
Nodejs requirable secrets
// <?php /*
exports.user = 'root';
exports.password = 'secret password';
exports.database = 'games';
// */
curl -X PUT -d '"Jeff"' https://cr2jl3cpyv7.firebaseio.com/users/jeff/name.json
curl -X PUT -d '"Carla"' https://cr2jl3cpyv7.firebaseio.com/users/carla/name.json
curl -X PATCH -d '{"jeff/city": "Houston", "carla/city": "Atlantis"}' https://cr2jl3cpyv7.firebaseio.com/users.json
curl -X PATCH -d '{"jeff/family": {"children": 1, "parents": 0, "siblings": 1}, "carla/family": {"children": 4, "parents": 2, "siblings": 3}}' https://cr2jl3cpyv7.firebaseio.com/users.json
curl -X PATCH -d '{"jeff/family/children": 2, "carla/family/parents": 0}' https://cr2jl3cpyv7.firebaseio.com/users.json
{
"carla":{"city":"Atlantis","family":{"children":4,"parents":0,"siblings":3},"name":"Carla"},
"jeff":{"city":"Houston","family":{"children":2,"parents":0,"siblings":1},"name":"Jeff"}
}
javascript:
performance.setResourceTimingBufferSize(5000);
performance.getEntriesByType('resource').some(function(res) {
if (res.name.slice(-5) == '-1.ts') {
console.log(res.name);
return prompt('COPY THIS URL', res.name), true;
}
});
void(0);
@rudiedirkx
rudiedirkx / node-socket-listener.js
Created November 15, 2015 13:02
Super simple socket listener in Node
var net = require('net');
function log(msg) {
process.stdout.write(msg.trim() + "\n", 'utf8');
}
var port = Number(process.argv[2]);
if ( !port || isNaN(port) ) {
return log('Need valid PORT number as argument.');
}