Skip to content

Instantly share code, notes, and snippets.

/**
* Traversing tree-like data structures, returning items on provided depth level
* Works on flat or deep-nested structures
* @param root Root node
* @param {number} depth Desired depth level
* @param {Function} getter fn to provide node's children
*/
function findByDepth(root, depth, getter) {
if (root == null) throw new Error('No root node was provided!');
@arkhemlol
arkhemlol / rxjs-diagrams.md
Created October 5, 2018 18:20 — forked from PCreations/rxjs-diagrams.md
Super Intuitive Interactive Diagrams to learn combining RxJS sequences by Max NgWizard K
@arkhemlol
arkhemlol / angular-mock-backend.js
Created May 6, 2016 22:22 — forked from kennethlynne/angular-mock-backend.js
High fidelity prototyping using a mock back-end. Include angular-mocks in your script includes after angular. Demo: http://codepen.io/kennethlynne/pen/lJbce
'use strict';
angular.module('yourApp')
.constant('Config', {
viewDir: 'views/',
API: {
useMocks: true,
fakeDelay: 2000,
protocol: window.location.protocol.split(':')[0],
host: window.location.hostname,
@arkhemlol
arkhemlol / LESS mixin for CSS arrow
Created April 24, 2016 19:33 — forked from julienchazal/LESS mixin for CSS arrow
LESS mixin for CSS arrow
/* ------------------------ */
/* LESS mixin for CSS arrow */
/* ------------------------ */
/* https://github.com/HugoGiraudel/LESS-Mixin-for-CSS-arrows
//Usage
.arrow(size, color, direction, offset, border-size, border-color);
Where
@arkhemlol
arkhemlol / box-shadow.html
Last active October 14, 2015 19:05 — forked from ocean90/box-shadow.html
CSS3 Box Shadow, only top/right/bottom/left and all
<!DOCTYPE html>
<html>
<head>
<title>Box Shadow</title>
<style>
.box {
height: 150px;
width: 300px;
margin: 20px;
@arkhemlol
arkhemlol / poller.js
Last active October 5, 2015 14:00
Long poll with timeout for angularjs
(function () {
'use strict';
angular
.module('mymodule')
.factory('poller', poller);
/** @ngInject */
function poller($timeout, config) {
@arkhemlol
arkhemlol / gist:3038fee489480e458419
Created June 26, 2015 08:35
throttle function for AngularJS
app.factory('socket', function ($rootScope) {
// Underscore.js 1.4.3
// http://underscorejs.org
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license.
// _.throttle
// https://github.com/documentcloud/underscore/blob/master/underscore.js#L626
// Returns a function, that, when invoked, will only be triggered at most once
@arkhemlol
arkhemlol / _toFixed
Last active August 29, 2015 14:19
toFixed function
Number.prototype._toFixed = function( precision ) {
var power = Math.pow(10, precision + 1);
var wholeNumber = Math.round( this * power );
return +(Math.round( wholeNumber / 10 ) * 10 / power).toFixed(2);
}