Skip to content

Instantly share code, notes, and snippets.

"use strict":
@jonnybojangles
jonnybojangles / Self-Invoking Functions.js
Created December 10, 2013 17:09
What are the key differences between these two self-invoking functions?
!function(a){console.log(a)}('Hello'); // Returns function statement Hello and true
// VS
(function(a){console.log(a)})('World'); // Returns function statement: World and undefined
@jonnybojangles
jonnybojangles / How can a provider reference itself?
Created November 19, 2013 01:08
A question for later. This in ability makes testing difficult.
provider('widget', [function(){
var that = this;
this.hi = function(){
return 'Hi';
};
this.$get = [function(){
return {
hello : function(){
/*
* How can a provider reference it self?
@jonnybojangles
jonnybojangles / angularjs provider with private method test example
Last active December 28, 2015 15:29
Testing a provider with a private method. See the use of provide injector "withPrivateProvider."
angular.module('widget', []).
provider('withPrivate', [function(){
var query = 'First';
this.demo = 'Third';
this.setQuery = function(newQuery){
query = newQuery;
};
this.$get = [function(){
return {
getQuery: function(){
angular.module('youtubeWidget.directives', []).
directive('youtubeWidgetApp', function(){
return {
restrict: 'C',
templateUrl: 'youtubeWidgetApp.html'
}
}).
run(function($templateCache){
$templateCache.put('youtubeWidgetApp.html', '' +
'<div class="mod-youtubeWidget">' +
@jonnybojangles
jonnybojangles / angular-extend-module-and-factory-test-example.js
Created November 16, 2013 00:44
Similar to https://gist.github.com/jonnybojangles/7492609 but this snippet extends the module widget. Good for use across multiple files.
angular.module('widget', []).
factory('widgetVersion', function(){
return {
version: '0.123'
}
});
/*
* Extend widget, sans []s
* */
angular.module('widget').
@jonnybojangles
jonnybojangles / angular-controller-test-example.js
Created November 15, 2013 23:19
Testing controllers that are not declared globally: angular.module().controller();
angular.module('widget.controllers', []).
controller('mainCtrl', ['$scope', function($scope){
$scope.test = 'this is a test';
}]);
/*
* Testing a controller created with angular.module().controller();
* */
describe('Testing controllers created via module\'s controller', function(){
"use strict";
@jonnybojangles
jonnybojangles / angular-provider-test-example.js
Last active December 28, 2015 11:19
Test private provider methods in AngularJS with Jasmine. How would you test setDay? Thanks: http://www.yearofmoo.com/2013/09/advanced-testing-and-debugging-in-angularjs.html
angular.module('widget.providers', []).
provider('day', function(){
var day = '';
return {
setDay: function(current){
day = current;
},
$get: function(){
return {
day: day + 'day'
@jonnybojangles
jonnybojangles / gist:5920859
Last active December 19, 2015 07:48 — forked from courtsimas/gist:1167053
I place this function atop my main/primary SASS file for all modules with in a site or project. When multiple modules are combined in a layout the main/primary styles are not duplicated each time. Thanks to user courtsimas and !default http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#variable_defaults_
$imported-once-files: () !default;
@function import-once($name) {
@if index($imported-once-files, $name) {
@return false;
}
$imported-once-files: append($imported-once-files, $name);
@return true;
}