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 / gist:cf647b8559be70903750
Created July 23, 2014 16:47
No separate stream - works
List myList = new List();
StreamController controller = new StreamController();
controller.stream.listen((_)
{
print("data: $_");
});
controller.add("sup");
@JesterXL
JesterXL / Gruntfile.js
Last active August 29, 2015 14:04
Example Grunt jslint task
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: ["Gruntfile.js"]
},
jscs: {
src: "*.js",
@JesterXL
JesterXL / Logger.js
Last active August 29, 2015 14:04
Logger class for Angular so you can turn it off. // TODO: add production mode for warnings and errors only
angular.module('logging', ['ngResource'])
.factory('Logger', function($log)
{
var Logger = {
enabled: true,
_consoleObject: $log,
_console: function(type, first, second)
{
@JesterXL
JesterXL / StacktraceService.js
Created August 4, 2014 19:18
StacktraceService
// Why? For production level stack traces for a variety of devices.
factory("StacktraceService",
function($window)
{
// [jwarden 2014] NOTE: She's a global method based on stacktrace.js, but if we change her,
// we can just change the method.
return({
printStackTrace: printStackTrace
});
}
@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: {