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-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();
};
Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3
@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"
}
@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 / git-remove-all-DS_Store
Last active April 9, 2021 08:34
How Can I Remove .DS_Store Files From A Git Repository? Open terminal and run the following command from your git project root. http://stackoverflow.com/questions/107701/how-can-i-remove-ds-store-files-from-a-git-repository
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
@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 / 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 / git-pre-commit-jshint-karma-unit
Created September 18, 2013 15:40
Git Pre-Commit shell script hook that executes Grunt tasks for JSHint && Karma Unit Tests before committing. Currently setup to change the directory as first step to the dir with your Gruntfile.js. Also adds PATH to grunt executable to current shell's PATH.
#!/bin/sh
#
# Pre-commit hooks
######################################################################
# Environment Setup
# 1) Change directory to build dir so we can run grunt tasks.
# 2) Make sure path is extended to include grunt task executable
# dir, as this commit shell is executed in the git
# client's own shell; ie Tower and WebStorm have own shell path.
@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;
});