Skip to content

Instantly share code, notes, and snippets.

View elgervb's full-sized avatar

Elger van Boxtel elgervb

View GitHub Profile
@elgervb
elgervb / multi-property-sort.js
Created March 8, 2018 11:04
Sort on multiple object properties
function compareBy(a, b) {
return (a || b) ? (!a ? -1 : !b ? 1 : a.localeCompare(b)) : 0;
}
array.sort((a, b) => compareBy(a.prop1, b.prop1) || compareBy(a.prop2, b.prop2) || etc...);
@elgervb
elgervb / default.css
Last active June 8, 2020 08:18
Default stylesheet
/* Default stylesheet. Taken from https://gist.github.com/elgervb/00359968425a6eecdd1d1c80d87d3886 */
html {
box-sizing: border-box;
font-size: 16px;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
*, *:before, *:after {
box-sizing: inherit;
@elgervb
elgervb / PromiseRequest.js
Created October 13, 2016 17:51
XmlHttpRequest on Promises!
export default class PromiseRequest {
get(url, data) {
return this.request('GET', url, data);
}
post(url, data) {
return this.request('POST', url, data);
}
@elgervb
elgervb / resize-done.js
Created October 13, 2016 08:07
window.resizeEnd event handler
var resizeTimer;
$(window).on('resize', function(e) {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
// Run code here, resizing has "stopped"
}, 250);
@elgervb
elgervb / webpack.webworkers-loader.js
Created October 11, 2016 15:04
Webpack configuration for webworkers
loaders: [
{
test: /worker\.js$/,
exclude: [/node_modules/],
loaders: ['babel', 'worker?name=js/[name].js'], // same as output.filename
},
]
@elgervb
elgervb / bootstrap-equal-cols.scss
Created September 14, 2016 12:08
Bootstrap equal columns
// hack for equal column height, together with parent display: table;
.row-eq-height {
display: table;
margin-left: 0;
margin-right: 0;
width: 100%;
> [class*="col-"] {
float: none;
display: table-cell;
/**
* Truncate the current element with a ellipsis over a fixed number of lines when it does not fit
*
* @param {strimg} $lineHeight The line height with unit (1em, 1.785rem, 25px)
* @param {number} $lineCount The number of lines to show
* @param {
*
* @see http://hackingui.com/front-end/a-pure-css-solution-for-multiline-text-truncation/
*/
@mixin wrap-ellipsis-multiline($lineHeight: 1.2em, $lineCount: 1, $bgColor: #ffffff){
@elgervb
elgervb / debug.handlebars.js
Last active February 4, 2019 16:55
Handlebars debug helper
/**
* Register a debug helper for Handlebars to be able to log data or inspect data in the browser console
*
* Usage:
* {{debug someObj.data}} => logs someObj.data to the console
* {{debug someObj.data true}} => logs someObj.data to the console and stops at a debugger point
*
* https://gist.github.com/elgervb/5c38c8d70870f92ef6338a291edf88e9
*
* @param {any} the data to log to console
@elgervb
elgervb / screen.js
Created May 30, 2016 13:56
Taking screenshot
var phantomjs = require('phantomjs-prebuilt/bin/phantomjs');
var page = require('webpage').create();
page.open('http://github.com/', function() {
page.render('github.png');
phantom.exit();
});
@elgervb
elgervb / MarkSelectedFilter.ts
Last active April 7, 2016 14:11
TypeScript angular 1.5 filter
/**
* Wraps a match inside a string between <b>...</b> tags
*
* Example:
* $filter('filtername').('match');
*
* Note: make sure you'll render this using ng-bind-html (in a repeater you'll probably must use ng-if as well, or otherwise all nodes will be rendered (empty when no match))
*/
class MarkSelectedFilter {