Skip to content

Instantly share code, notes, and snippets.

const defaultMenu = ['hamburger', 'french fries', 'soda'];
const guestNames = ['John', 'Jane', 'Bill'];
const guest = (name) => ({
name,
foods : defaultMenu,
eat(food) {
this.foods.push(food);
return this;
}
const _addToGroup = (keyFn) => (result, item) =>
(result[keyFn(item)] = result[keyFn(item)] || []).push(item) && result;
const groupBy = (array, keyFn) => array.reduce(_addToGroup(keyFn), {});
let objects = [
{ id: 0, name: 'root', parent: null },
{ id: 1, name: 'foo', parent: 0 },
{ id: 2, name: 'bar', parent: 1 },
{ id: 3, name: 'baz', parent: 1 },
@cdanyl
cdanyl / wsResource.service.js
Created October 27, 2016 12:27
mapRecursively es6
/* @ngInject */
export default function wsResource(wsEndpoints, resource) {
/* eslint-disable no-confusing-arrow */
const mapRecursively = obj =>
Object.assign(...Object.keys(obj)
.map(key => (obj[key] && typeof obj[key] === 'object') ?
{ [key]: mapRecursively(obj[key]) } :
{ [key]: resource.create(obj[key]) }
)
);
@cdanyl
cdanyl / service.js
Created October 17, 2016 12:38 — forked from aaronfrost/service.js
caching service in Angular
angular.module('app').factory('myService', function($q, $http){
var data;
var dataPromise;
return {
getData: getData
}
function getData(){
//If the data is already here, return it in a resolved promise
@cdanyl
cdanyl / onlyForAdmin.ng-directive.js
Created October 15, 2016 09:47 — forked from vvscode/onlyForAdmin.ng-directive.js
onlyForAdmin directive
angular
.module('smartjs').directive('onlyForAdmin', function(ngIfDirective) {
ngIfDirective = ngIfDirective[0];
return {
transclude: ngIfDirective.transclude,
priority: ngIfDirective.priority,
terminal: ngIfDirective.terminal,
restrict: ngIfDirective.restrict,
link: function($scope, $element, $attr) {
$attr.ngIf = 'user.isAdmin';
@cdanyl
cdanyl / api.js
Created October 8, 2016 13:21 — forked from eliberov/api.js
API Abstraction Layer used to simplify resource loading and pagination
/** API Abstraction Layer used to simplify resource loading and pagination
*
*
*/
angular.module( 'laundureeApp' )
.provider( 'api', [ function(){
var api = {};
@cdanyl
cdanyl / _ng-animate-helper.sass
Created October 1, 2016 14:18 — forked from afknapping/_ng-animate-helper.sass
ngAnimate transition Sass mixins which work for both ng-if and ng-show
// ngAnimate helper mixins
// first it helps to have a single transition for everything. you can always fine-tune later:
$base-transition: 0.5s ease all
// this set of mixins which works for both ng-if and and ng-show:
@mixin revealTo($transition: $base-transition)
@content
@cdanyl
cdanyl / deferMaps.js
Created September 28, 2016 14:42 — forked from wholypantalones/deferMaps.js
Lazyload Google Maps Angular Service
/*
usage:
Initializer.mapsInitialized.then(function(){
initMap(); // do stuff with maps
});
*/
angular.module('ngApp', []).
factory('Initializer', function($window,$q){
var asyncUrl = '//maps.googleapis.com/maps/api/js?callback=',
mapsDefer = $q.defer();
@cdanyl
cdanyl / auth.interceptor.config.js
Created September 9, 2016 16:34
flatten object with nested object to array
function _getApiToAuthorize(apiUrl) {
return _.reduce(apiUrl, function fn(result, url, key) {
if (typeof url === 'object') {
_.reduce(url, fn, result);
} else {
if (key === 'tokens') {
return result;
}
result.push(url);
}
@cdanyl
cdanyl / mockedService.test.js
Created September 7, 2016 19:57 — forked from accraze/mockedService.test.js
Testing with mocked Angular Services using Jasmine - http://accraze.info/testing-angular-services-using-jasmine/
describe('OrderApp', function() {
describe('Service: MenuResult', function() {
beforeEach(module('OrderApp'));
beforeEach(inject(function($httpBackend) {
mock_response = {
results: [{
_id: "1234567890",
url: "/food/pizza",
title: 'Pizza'