Skip to content

Instantly share code, notes, and snippets.

View voznik's full-sized avatar
🤔
Open for opportunities

Vadym Parakonnyi voznik

🤔
Open for opportunities
View GitHub Profile
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
@voznik
voznik / SumByKey.js
Last active September 10, 2015 14:18 — forked from Cacodaimon/SumByKey.js
A simple AngularJS filter for summarizing the values of an array containing objects by a key.
angular.module('caco.feed.filter', [])
.filter('sumByKey', function() {
return function(data, key) {
if (typeof(data) === 'undefined' || typeof(key) === 'undefined') {
return 0;
}
var sum = 0;
for (var i = data.length - 1; i >= 0; i--) {
sum += parseInt(data[i][key]);
# @ngdoc overview
# @name ui-commons.hook
# @description
# a directive to hook enter/leave events to select children without watchers or broadcasting
@directive = angular.module('ui-commons.hook', [])
@directive.controller 'UiHookController', ['$scope', ($scope) ->
hooks = []
@addHook = (fn) ->
@directive = angular.module('ui-commons.autosave', [])
@directive.directive 'autosave', ['formHandler', 'promiseTrackers', '$timeout', (formHandler, promiseTrackers, $timeout) ->
restrict: 'A'
require: ['form', 'autosave']
controller: ($scope) ->
submitExpr = null
tracker = null
currentPromise = null
formDelay = null
@voznik
voznik / Angular.Ionic.HardwareBackButtonManager.js
Created October 29, 2015 09:55 — forked from mircobabini/Angular.Ionic.HardwareBackButtonManager.js
HardwareBackButtonManager Service for Ionic (Angular.js) provides an interface to easily enable or disable the hardware back button on Android
.service( 'HardwareBackButtonManager', function($ionicPlatform){
this.deregister = undefined;
this.disable = function(){
this.deregister = $ionicPlatform.registerBackButtonAction(function(e){
e.preventDefault();
return false;
}, 101);
}
# via http://wiki.apache.org/couchdb/Installing_on_Ubuntu

sudo apt-get install --yes build-essential curl git
sudo apt-get install --yes python-software-properties python g++ make

sudo apt-get install -y erlang-dev erlang-manpages erlang-base-hipe erlang-eunit erlang-nox erlang-xmerl erlang-inets
sudo apt-get install -y libmozjs185-dev libicu-dev libcurl4-gnutls-dev libtool

# via http://ftp.fau.de/apache/couchdb/source/1.6.1/

cd /tmp

@voznik
voznik / angular-loading-bar_overlay.css
Created March 23, 2016 14:55
angular-loading-bar overlay
#loading-bar {
pointer-events: all;
z-index: 99999;
border: none;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
@voznik
voznik / config.cson
Created September 4, 2016 10:24
Solirized Dark for terminal-fusion Atom Terminal (fork of platformio-atom-ide-terminal)
"platformio-ide-terminal":
ansiColors:
normal:
black:
red: 88
green: 110
blue: 117
alpha: 1
blue:
red: 38
@voznik
voznik / README.md
Created September 21, 2016 09:07 — forked from felippenardi/README.md

Testing an Angular $resource factory

This is an example of how to test an Angular Resource created with $resource.

Live Demo

Important take aways:

  • Do not mock $resource. Instead, you can use the resource's methods and assert that it is making the right API call. By doing that you can later change the implementation (for example for replace $resource for Angular Cached Resource) without needing toi go change all previous tests.
  • When intercepting the response of a custom method, do not transform the response string into json yourself. When you use the transformResponse action property of a $resource, you replace the default angular parser that is transforming backend response from string to JSON. It has some logic to ensure that the response is a JSON and can be parsed securely. You can use it by injecting $http into your factory and using `$http.defaults.transformRespon