Skip to content

Instantly share code, notes, and snippets.

View brianmriley's full-sized avatar

Brian Riley brianmriley

View GitHub Profile
@brianmriley
brianmriley / AngularJS-Service-Factory-Provider-Example.js
Last active August 29, 2015 13:57 — forked from Mithrandir0x/gist:3639232
AngularJS Service vs Factory vs Provider Implementations
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@brianmriley
brianmriley / javascript-parse-query-string
Last active December 18, 2015 15:39
Simple method for parsing query params from a URL into a hash object.
/**
* Creates a hash object of all the URL query string params.
*
* @returns {{}}
*/
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
vars[key] = value;
});
@brianmriley
brianmriley / reclaim-npm-as-local-user
Created September 18, 2013 18:15
Terminal command to reclaim ownership of the .npm directory execute (b/c it started out as sudo) during install. Run the following command from anywhere in terminal.
sudo chown -R `whoami` ~/.npm
@brianmriley
brianmriley / jira-javascript-code-block
Created September 18, 2013 20:29
Code block macros in JIRA comments can be created by specifying {code:<language>}my code...{code}
{code:JavaScript}
grunt.loadNpmTasks('grunt-contrib-connect');
...
connect: {
webServer: {
options: {
port: '<%= ports.webServer %>',
base: '<%= buildDir %>',
keepalive: false
}
@brianmriley
brianmriley / inner-iife-breakpoints-webstorm-fail
Last active December 23, 2015 19:59
WebStorm will not hit break points inside of an IIFE with parameters. The following example shows an example that won't work followed by an example that will work.
////////////////////////////////////////////////////////////////////////////////
// NOTE: This specific use case had leverages AngularJS and RequireJS so it's
// possible these had something to do with it as well, but it seems that there's
// an issue with breakpoints and V8:
//
// * http://mariuszprzydatek.com/2013/07/21/angularjs-karma-and-debugging-unit-tests-in-webstorm-or-intellij-idea/
// * http://www.andrejkoelewijn.com/blog/2013/05/07/debugging-with-webstorm-and-karma/
// * http://tommytcchan.com/blog/2013/03/18/example-how-to-set-up-debugging-with-karma-formerly-testacular-and-webstorm/
////////////////////////////////////////////////////////////////////////////////
@brianmriley
brianmriley / merge-javacript-objects
Last active December 23, 2015 22:09
Native JavaScript function that performs deep-copy/merge capabilities on n number of arguments. Returns merged object. Adapted from: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
var obj1 = {
"foo": {
"dog": "000"
},
"bar": {
"bear": "111"
},
"tee": {
"elephant": "555"
}
Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3
@brianmriley
brianmriley / javascript-simple-guid-generator
Created October 3, 2013 19:07
JavaScript Simple GUID Generator
// internal function to generate a random number guid generation
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// generates a guid for adding items to array
var createGUID = function () {
return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0,3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
};
@brianmriley
brianmriley / Grepping log files and outputting new files
Last active April 27, 2016 11:38
Grepping logs and outputting to a new file.
// grep {searchString} {targetFile} > {outputFile}
grep "loadChunk(" mysxm.log > mysxm-load-chunk.log
@brianmriley
brianmriley / javascript-console-logging-wrapper
Last active April 27, 2016 12:02
Attempt to wrap the `console.log()` method of the browser and successfully bind to the client object calling `logger.debug()` and not the logger itself.
// I've created a simple logger (wraps console.* methods) that provides output similar to say Log4J or other robust
// loggers out there for the enterprise, but a huge missing piece (for me) is that you can no longer see the file
// reference and line number from the client object using the logger. When you use console.log() OOTB it'll spit out
// a clickable link to the file and line number that executed the console.log making it easy to debug; when you wrap
// console.log it simply spits out the logger file reference and the line number the console.log was executed, so
// all logging shows up as from the logger wrapper (which is technically correct)...bottom line, you lose the context
// from which you actually made the logging call and I'd like to get that back.
// Aside from blackboxing, is there another way to wrap console.log() such that it binds to the client callee
// and ultimately shows the correct file reference and line number of the callee (and not the log wrapper)?