Skip to content

Instantly share code, notes, and snippets.

View carloscasalar's full-sized avatar
💜
Helping make cities a better place to live at @cabify

Carlos Castillo carloscasalar

💜
Helping make cities a better place to live at @cabify
View GitHub Profile
@morrislaptop
morrislaptop / stateMock.js
Last active November 23, 2015 08:51 — forked from wilsonwc/stateMock.js
angular.module('stateMock',[]);
angular.module('stateMock').service("$state", function($q){
this.expectedTransitions = [];
this.current = {};
this.transitionTo = function(stateName){
if(this.expectedTransitions.length > 0){
var expectedState = this.expectedTransitions.shift();
if(expectedState !== stateName){
throw Error("Expected transition to state: " + expectedState + " but transitioned to " + stateName );
}
//GistID:1c45ca694ad333baeddd
'use strict';
angular.module('stateMock', []);
angular.module('stateMock').service("$state", function($q) {
this.expectedTransitions = [];
this.current = {};
this.transitionTo = function(stateName) {
if (this.expectedTransitions.length > 0) {
var expectedState = this.expectedTransitions.shift();
@nahuelsotelo
nahuelsotelo / error.js
Last active April 20, 2016 09:23
ERROR HANDLER
var beep = require('beepbeep');
var colors = require('colors');
var onError = function(err) {
beep([200, 200]);
var formatOutput = function(context) {
var msg, file, line, description;
if(context == 'gulp-babel') {
@ssaunders
ssaunders / exposePriv.js
Created September 4, 2014 17:57
Expose private variables for unit testing in JavaScript
/* The code below takes a constructor and exposes its private functions
Useful for unit testing (not general use). An example usage is below it.
Access to the private functions available through the _privMems property. */
/* Original credit goes to Rob Gravelle
http://www.htmlgoodies.com/beyond/javascript/accessing-private-functions-in-javascript.html */
var Reflection = {};
Reflection.createExposedInstance = function(objectConstructor, args)
{
@gmilby
gmilby / createUUID.js
Created September 18, 2013 16:46
angular - create unique id
angular
.module('uuidApp', ['lvl.services'])
.controller('uuidCtl', ['$scope', 'uuid', function($scope, uuid){
$scope.generateUuid = function() {
$scope.new = uuid.new();
$scope.nInfo = new Date();
};
$scope.showEmpty = function() {
$scope.empty = uuid.empty();
@sanderhahn
sanderhahn / gulpfile.js
Last active September 11, 2019 14:45
Minify and templateCache your Angular Templates using Gulp
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var templates = require('gulp-angular-templatecache');
var minifyHTML = require('gulp-minify-html');
// Minify and templateCache your Angular Templates
// Add a 'templates' module dependency to your app:
// var app = angular.module('appname', [ ... , 'templates']);
@CrabDude
CrabDude / callback_contract.md
Last active December 20, 2019 18:50
Node.js Callback Contract

Node.js Callback* Contract

(aka "errback" or "error first callback")

  1. Function that takes 2 arguments
    • first argument is an error
    • second argument is the result
    • Never pass both
    • error should be instanceof Error
  2. Must never excecute on the same tick of the event loop
  3. Must be passed as last argument to function
@danwit
danwit / node_acl_example.js
Created April 26, 2014 00:22
Authorization with node_acl + mongo + express
/**
* Simple node_acl example with mongoDB and expressjs
*
* Usage:
* 1. Start this as server
* 2. Play with the resoures
*
* Show all permissions (as JSON)
* http://localhost:3500/info
*
@busypeoples
busypeoples / AngularJS-ES6-Test-Skeleton
Last active June 6, 2020 01:29
AngularJS - Karma, Jasmine, Browserify, Stringify - ES6 Test Setup
We couldn’t find that file to show.
@nackjicholson
nackjicholson / unit-test-angularjs-grunt-karma-travis.md
Created December 22, 2014 05:37
Unit Testing with AngularJs, Grunt, Karma, and TravisCI

If you've done much reading about angularjs you've no doubt come across mention of karma, a test runner recommended especially for use with angularjs applications. The [angular-seed][1] project is a great way to get started with the basics of angular testing using karma, but for projects of any significant size you will soon hit the cieling in terms of organizational complexity. What I want to share in this article is the approach I have taken using [Grunt][2] and the [grunt-karma][3] plugin to sustainably manage my projects' client side unit tests and run them via [TravisCI][4]. I plan to write another entry about how to approach the actual minutia of unit testing angular code in the near future.

Karma, configuration for tests

Karma is really nothing more than a set of centralized configuration that builds a test runner for you. The advantage being that it allows you to easily execute tests in a headless browser, and output to the command line. As someone who has actually set all of that up from scratc