Skip to content

Instantly share code, notes, and snippets.

View jberndsen's full-sized avatar

Jeroen jberndsen

View GitHub Profile
/////////
// LESSION MATERIAL FOR .map, .filter, .reduce, function composition and currying
/////////
const list = [1, 2, 3, 4, 5];
const anotherList = ['h', 'e', 'l', 'l', 'o'];
let result;
// map is used to transform each element in the array
@jberndsen
jberndsen / _body.scss
Created February 10, 2017 15:38
Quick ITCSS startup structure for Angular 2 / Material Design
@import '../settings/_colours.scss';
@import '../settings/_typography.scss';
body {
width: 100%;
height: 100%;
min-height: 100vh;
background-color: md-color($vir-app-ui, 50);
font-family: $font-stack;
@jberndsen
jberndsen / guid.js
Created February 10, 2017 15:27
GUID generator for JS
export function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
@jberndsen
jberndsen / base.service.ts
Created February 10, 2017 15:25
Quickly read current state in an Angular service depending on NGRX.
import {Store} from '@ngrx/store';
export abstract class BaseService {
state: any;
constructor(protected store: Store<any>) {
this.store.subscribe(s => this.state = s);
}
}
@jberndsen
jberndsen / toastr.actions.ts
Created March 14, 2016 09:34
Angular2-Redux-Immutable-Toastr
import {Injectable} from 'angular2/core';
import {guid} from '../../../helpers';
export const ADD_TOAST = 'ADD_TOAST';
export const REMOVE_TOAST = 'REMOVE_TOAST';
export const FADE_TOAST = 'FADE_TOAST';
@Injectable()
export class ToastrActionCreator {
constructor() {
(function(angular) {
'use strict';
angular.module('app').filter('dutchmoney', function () {
return function(input) {
var result = roundToTwo(parseFloat(input) + 'e+2').toFixed(2).replace('.', ',');
return isNaN(result) ? "" : result;
};
function roundToTwo(num) {
@jberndsen
jberndsen / angular-dutch-currency-filter.js
Created November 20, 2015 12:15
Angular filter for displaying a number as dutch currency.
(function (angular) {
'use strict';
angular.module('app').filter('customnumber', function () {
return function (input) {
return roundToTwo(parseFloat(input) + "e+2").toFixed(2).replace('.', ',');
};
function roundToTwo(num) {
return +(Math.round(num) + "e-2");