Skip to content

Instantly share code, notes, and snippets.

View JesterXL's full-sized avatar
🔊
writing

Jesse Warden JesterXL

🔊
writing
View GitHub Profile
@JesterXL
JesterXL / ServiceLocator.js
Last active August 29, 2015 14:04
ServiceLocator - finds all our REST API URL's with additional rules for formulating them
angular.module('com.servicelayer', [])
.constant("ServicesLocator",
{
// *** dev ***
DOMAIN: "https://",
SOME_SERVICE: "someservice",
ANOTHER_SERVICE: "another/service",
// *** dev ***
@JesterXL
JesterXL / HTTPInterceptor.js
Created August 4, 2014 19:30
$http interceptor for ErrorService and redirects
angular.module('interceptor',
["com.servicelayer"],
function($q, ErrorService)
{
return {
response: function (response) {
// do something on success
if(response.headers()['content-type'] === "application/json; charset=utf-8"){
//TODO: check for error codes and delegate to error handler service
@JesterXL
JesterXL / ErrorService.js
Last active August 29, 2015 14:04
ErrorService - logs all errors to Splunk
factory('ErrorService',
function($injector, $window, ServicesLocator, StacktraceService, Debounce, Logger)
{
var $http = null;
var ErrorService = {
log: function(exception, cause)
{
if($http == null)
{
@JesterXL
JesterXL / GlobalExceptionHandler.js
Created August 4, 2014 19:39
GlobalExceptionHandler - handles global errors that are uncaught
angular.module('com.servicelayer.errors',
['ngResource', 'logging'])
.config(['$provide', function($provide)
{
$provide.decorator('$exceptionHandler', function($delegate, ErrorService)
{
return function(exception, cause)
{
$delegate(exception, cause);
ErrorService.log(exception, cause);
@JesterXL
JesterXL / angular-roles.js
Created August 12, 2014 19:16
Roles in Angular Pseudo code example
// assuming user JSON object comes back with role; I don't care if y'all encrypt/hash it
$scope.user = null;
$http.post("some/auth", {credentials})
.success(function(data, status, headers, config)
{
/*
// JSON looks like
{
data: {
user: {
@JesterXL
JesterXL / Gruntfile.js
Created October 14, 2014 13:04
Example Mocha Chai Angular in Karma
karma: {
options: {
configFile: 'karma.configuration.js'
},
unit: {
runnerPort: 9101,
background: true,
port: 9877
},
continuous: {
@JesterXL
JesterXL / index.html
Created December 2, 2014 00:09
Examples of Angular Scopes
<html>
<head><title>Angular Basics</title></head>
<script src="angular.js"></script>
<body ng-app="app">
<script>
function shouldEqual(a, b)
@JesterXL
JesterXL / directive.mocha.spec.js
Created March 30, 2015 00:47
Angular Directive Mocha Unit Test
/* jshint -W117, -W030 */
(function() {
'use strict';
describe('simple directive test:', function() {
describe('factory', function() {
var scope;
beforeEach(function() {
module('wdpr.angular-validators');
});
@JesterXL
JesterXL / lodash.spec.js
Created April 1, 2015 16:36
Strange Lodash _.every unit tests
// uses mocha and chai
it('basic lodash _.every function is strange', function() {
_.every([true]).should.be.true;
_.every([true], true).should.be.false;
_.every([true, true], true).should.be.false;
_.every([true, true, true], true).should.be.false;
_.every([false, false, false], Boolean).should.be.false;
_.every([false, false, false], false).should.be.false;
});
@JesterXL
JesterXL / gist:29a678c50929a6e79805
Created May 22, 2015 13:23
Why Boolean doesn't work as a checked value
function getPlayer()
{
return {
isWorthy: true
}
}
function determineIfWorthy(player)
{
return player.isWorthy();