Skip to content

Instantly share code, notes, and snippets.

View auxcoder's full-sized avatar
🗼
Working from home

AuxCoder auxcoder

🗼
Working from home
View GitHub Profile
@auxcoder
auxcoder / supplant.js
Created August 8, 2016 16:01 — forked from pbroschwitz/supplant.js
supplant - Crockford
/**
* supplant() does variable substitution on the string. It scans through the string looking for
* expressions enclosed in { } braces. If an expression is found, use it as a key on the object,
* and if the key has a string value or number value, it is substituted for the bracket expression
* and it repeats.
*
* Written by Douglas Crockford
* http://www.crockford.com/
*/
String.prototype.supplant = function (o) {
@auxcoder
auxcoder / createPromiseSpy.js
Created August 6, 2016 16:12 — forked from bbraithwaite/createPromiseSpy.js
Utility function for working with promises in angular tests.
var createPromiseSpy = function(obj, name, method, $q) {
var createdSpy = jasmine.createSpy(name, obj);
var returnObj = {};
var promise = {};
if (typeof(method) === 'string') {
var deferred = $q.defer();
spyOn(createdSpy, method).and.returnValue(deferred.promise);
promise[method] = deferred;
}
@auxcoder
auxcoder / interact-angular-from-console.md
Last active August 21, 2017 17:23
Access to Angular from console to debug

Access to Angular from console to debug

We can get whatever service we like and then call an specific method.

var serviceName = angular.element(document.body).injector().get('serviceName');
serviceName.someMethod();
@auxcoder
auxcoder / whatever.spec.js
Last active July 26, 2016 19:26
Test sample mocking $window service function
// http://stackoverflow.com/questions/20252382/how-to-mock-window-location-replace-in-angularjs-unit-test
describe('whatever', function() {
var $window, whatever;
beforeEach(module('services'));
beforeEach(function() {
$window = {location: { replace: jasmine.createSpy()} };
module(function($provide) {
@auxcoder
auxcoder / angularjs-providers-explained.md
Created March 30, 2016 15:34 — forked from demisx/angularjs-providers-explained.md
AngularJS Providers: Constant/Value/Service/Factory/Decorator/Provider
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

@auxcoder
auxcoder / README.md
Created March 20, 2016 23:38 — forked from chrisroos/README.md
Apache 2.4 on OS X Yosemite listening on ::1 and not 127.0.0.1

Apache appears to be listening on ::1 but not 127.0.0.1.

$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.

$ telnet 127.0.0.1 80
Trying 127.0.0.1...
@auxcoder
auxcoder / MyController.spec.js
Created January 20, 2016 14:17
$state mock for testing ui-router state
(function() {
'use strict';
describe('controllers', function(){
var scope, vm, state, $rootScope;
// Initialize the controller and scope
beforeEach(function () {
// Load the controller's module
module('AngularApp');
@auxcoder
auxcoder / index.filters.js
Created January 15, 2016 19:36
Search by two atributes in an object (collections of customers)
(function() {
'use strict';
angular.module('engageAngularApp')
.filter('searchByNameAndPhone', function(){
return function(items, searchString){
if(!searchString){
return items;
}
@auxcoder
auxcoder / index.route.js
Last active January 15, 2016 15:23
ui-router-with-resolve-example
(function() {
'use strict';
angular
.module('myApp')
.config(routeConfig);
/** @ngInject */
function routeConfig($stateProvider, $urlRouterProvider) {
$stateProvider
@auxcoder
auxcoder / index.config.js
Last active January 11, 2016 00:08
httpInterceptorFactory to manage authentication token in header and redirection
(function() {
'use strict';
angular.module('engageAngularApp')
.config(httpInterceptor);
/** @ngInject */
function httpInterceptor($httpProvider) {
$httpProvider.interceptors.push('httpInterceptorFactory');
}