Skip to content

Instantly share code, notes, and snippets.

View elgervb's full-sized avatar

Elger van Boxtel elgervb

View GitHub Profile
@elgervb
elgervb / guid.js
Last active April 6, 2016 14:09
Create GUID
/**
* Creates a random guid.
*
* @example 064ca254-ab32-4a0b-bb38-4a35c730f323
*/
function guid(){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
@elgervb
elgervb / scriptDirective.js
Last active April 6, 2016 14:10
ng-script
/**
* add a script dynamically to the head of your document
* use <script ng-src="/path/to/script.js"></script>
*/
.directive('script', ($parse, $rootScope) => {
return {
restrict: 'E',
terminal: true,
link: (scope, element, attr) => {
if (attr.ngSrc) {
@elgervb
elgervb / CollapseDirective.ts
Last active April 6, 2016 14:10
TypeScript angular 1.5 directive
/**
* Angular Directive to collapse a panel
*
* Params:
* name {string} the name of the directive (bound by angular.module.directive(name, fn))
*
* Use:
* <div class="sidebar">
* <div class="toggle" collapse=".sidebar"> </div>
* </div>
@elgervb
elgervb / CommonComponent.ts
Last active April 6, 2016 14:10
TypeScript angular 1.5 Component
class MyComponentController {
static $inject = ['AnyService'];
constructor( private service: AnyService) {}
}
class MyComponent implements ng.IComponentOptions {
public bindings: { [binding: string]: string };
@elgervb
elgervb / SearchDirective.ts
Last active July 29, 2016 06:56
TypeScript angular 1.5 directive without scope
/**
* Angular directive to search inside a list of objects
*
* @event search-select on selection. Emits the selected obj upstream to parents
*/
class SearchDirective implements ng.IDirective {
public restrict: string = "EA";
public scope: Object = {}; // always use an isolated scope
public bindToController: Object = { // bind properties to controller (not the scope)
@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 {
@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 / 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
/**
* 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 / 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;