Skip to content

Instantly share code, notes, and snippets.

View branneman's full-sized avatar

Bran van der Meer branneman

View GitHub Profile
@branneman
branneman / event.js
Last active December 27, 2018 11:58
JavaScript window resize event with a 100ms delay
$(function() {
var resizeEnd;
$(window).on('resize', function() {
clearTimeout(resizeEnd);
resizeEnd = setTimeout(function() {
$(window).trigger('resize-end');
}, 100);
});
});
@branneman
branneman / dump.php
Created July 30, 2013 08:16
PHP: A better formatted var_dump()
function dump($var) {
ob_start();
var_dump($var);
$output = ob_get_clean();
echo preg_replace("/=>(\s+)/m", ' => ', $output);
}
@branneman
branneman / es5-features.js
Last active October 20, 2016 15:48
ECMAScript 5 In code examples
/**
* Strict mode
* Opt in to a restricted variant of JavaScript.
*/
'use strict';
(function() { 'use strict'; });
/**
* Array.prototype.forEach()
* Executes a provided function once per array element.
@branneman
branneman / breakpoints.scss
Last active February 19, 2019 08:57
JavaScript - CSS breakpoint Sync
/**
* Set the breakpoints as a font-family and pseudo element.
* This way JavaScript can read the current active breakpoint.
*/
head {
font-family: 'no-breakpoint';
}
body:after {
display: none;
content: 'no-breakpoint';
@branneman
branneman / _rem.scss
Last active December 24, 2015 07:19
Sass (scss) rem function and mixin. Based on and improved upon: https://github.com/bitmanic/rem
//
// Sass rem function and mixin
// https://gist.github.com/branneman/6762906
// Based on and improved upon https://github.com/bitmanic/rem
//
// Baseline, measured in pixels
// The value should be the same as the font-size value for the html element
// If the html element's font-size is set to 62.5% (of the browser's default font-size of 16px),
// then the variable below would be 10px.
@branneman
branneman / articles.js
Last active December 30, 2015 21:50
Example code style I use of a Node.js module. Uses @felixge's Node Style Guide and some more conventions on naming and formatting.
//
// Articles controller
// Optional module description line.
//
'use strict';
var fs = require('fs');
var path = require('path');
@branneman
branneman / better-nodejs-require-paths.md
Last active April 8, 2024 00:22
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@branneman
branneman / svg-classes.js
Created January 15, 2014 14:12
SVG — hasClass, addClass, removeClass, toggleClass
//
// SVG — hasClass, addClass, removeClass, toggleClass
// Source:
// https://gist.github.com/branneman/8436956
// Taken and adapted from:
// http://toddmotto.com/hacking-svg-traversing-with-ease-addclass-removeclass-toggleclass-functions/
//
if (SVGElement && SVGElement.prototype) {
@branneman
branneman / howto.md
Last active January 3, 2016 21:39
Howto install Ruby & DevKit on Windows

Howto install Ruby & DevKit on Windows

  1. Install Ruby 2, x64
    inside a directory without spaces

  2. Install a matching Ruby DevKit, instructions here
    inside a directory without spaces

  3. Install extra dependencies:

@branneman
branneman / app.js
Last active February 5, 2021 21:58
Node.js application entry-point files
#!/usr/bin/env node
'use strict';
var spawn = require('child_process').spawn;
var args = [
'--harmony',
'app/bootstrap.js'
];