Skip to content

Instantly share code, notes, and snippets.

@awerlang
awerlang / gist:ef16cb32ff9605ab8c0d
Created February 1, 2015 21:06
99 bottles of beer, ES6 version
function* bottlesOfBeer(howMany=99){
let pluralizeBottles = count => count !== 1 ? "bottles" : "bottle";
let takeNext = next => next >= 1 ? next.toString() : "No more";
for (let i = howMany; i >= 0; i--) {
let bottle = pluralizeBottles(i);
let bottleNext = pluralizeBottles(i-1);
let left = takeNext(i);
let toTake = i > 1 ? "one" : (i == 1 ? "it" : "no more");
let toTakeNext = takeNext(i-1);
let line1 = `${left} ${bottle} of beer on the wall, ${left.toLowerCase()} ${bottle} of beer.`;
@awerlang
awerlang / lexiSort.js
Created January 5, 2015 16:42
natural compare function
// benchmark: http://jsperf.com/natural-compare
"use strict";
function lexiSort(config) {
return function (a, b) {
if (typeof a === "number" && typeof b === "number")
return a - b;
if (a === null || b === null)
return NaN;
if (a === undefined || b === undefined)
return NaN;
@awerlang
awerlang / gist:007e11fd415a95c6bb44
Last active August 29, 2015 14:11
Apply some delay on Http Requests
// enabled when $rootScope.configHttpDelay == true
(function () {
"use strict";
angular.module("app")
.config(function ($provide) {
function decorator($delegate) {
var proxy = function (method, url, data, callback, headers) {
var interceptor = function () {
@awerlang
awerlang / angular-directives
Last active March 6, 2017 14:27
Angular.js directives sorted by priority
/*
I've compiled a list of angular directives according to their priorities (from most priority to lesser priority).
Also, terminal property is included for each directive that asserts it
*/
ng-switch 1200
ng-repeat 1000 terminal
ng-if 600 terminal
ng-controller 500
ng-init 450