Skip to content

Instantly share code, notes, and snippets.

View toddmotto's full-sized avatar

Todd Motto toddmotto

View GitHub Profile
@toddmotto
toddmotto / *.js
Created September 19, 2016 19:41
Angular function arguments
(function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=r;A[l]=A[l]||function(){
(A[l].q=A[l].q||[]).push(arguments)},A[l].l=1*new Date();a=n.createElement(g),
r=n.getElementsByTagName(g)[0];a.async=1;a.src=u;r.parentNode.insertBefore(a,r)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-XX', 'auto');
ga('send', 'pageview');
@toddmotto
toddmotto / *.md
Last active April 25, 2023 09:06
Component versus Directive in AngularJS

Component versus Directive in AngularJS

.component()

Components are not "helper" methods, they are the best change in Angular 1.x since I've been using it.

What is the role of .component()?

  • Declares new HTML via a template or templateUrl
  • Should be used to create Components as part of a Component architecture
@toddmotto
toddmotto / mock-data.txt
Created April 20, 2016 11:28
Excel Online / Kendo Spreadsheet data
OrderDate
Region
Rep
Item
Units
@toddmotto
toddmotto / *.md
Created September 14, 2015 13:46
How I lost 20kg/3stone/44lbs

Everytime I tweet about losing weight and posting images, a lot of people ask questions - so thought I'd write something decent down about what I've done so far and am currently working on.

12 months change:

Necessary changes

Step 1: Fixing your diet

My diet used to be so so bad, energy drinks, constant sugar intake. Kill that! I also used to order takeaways at least 2-3 times a week, because it was easy and the bigger you get the lazier you get from my experience.

@toddmotto
toddmotto / gist:657ba746e89025a0200b
Created October 23, 2014 21:45
Google Inbox invite code
Z21haWxpbnZpdGU#AAjWDC2eHXTaEvbWN19YkGu-csrdu0xEv0RAqZIRtXDlouoVrL9F7Hgs1ITcurRw4omVdrjPjhYFm7V2pUYPhe57u_s5KqDn7A#ZXRpdm5pbGlhbWc
@toddmotto
toddmotto / annotate.js
Created July 16, 2014 21:26
Angular's annotation mapping process and performance
/**
* Read the post for full details, hope these comments are helpful!
* http://toddmotto.com/angular-js-dependency-injection-annotation-process
*/
function annotate(fn, strictDi, name) {
var $inject,
fnText,
argDecl,
last;
@toddmotto
toddmotto / angular.annotate.js
Created July 16, 2014 21:05
Angular's annotation function
function annotate(fn, strictDi, name) {
var $inject,
fnText,
argDecl,
last;
if (typeof fn === 'function') {
if (!($inject = fn.$inject)) {
$inject = [];
if (fn.length) {
@toddmotto
toddmotto / extend.js
Created June 30, 2014 12:42
Even smaller Object extend() method, with no reference cloning: http://jsfiddle.net/LR639
function extend (target, source) {
var a = Object.create(target);
Object.keys(source).map(function (prop) {
prop in a && (a[prop] = source[prop]);
});
return a;
};
@toddmotto
toddmotto / extend.js
Last active August 29, 2015 14:03
ECMAScript 5 extend(), preserves original Object values
function extend (target, source) {
target = JSON.parse(JSON.stringify(target));
Object.keys(source).map(function (prop) {
Object.prototype.hasOwnProperty.call(target, prop) && (target[prop] = source[prop]);
});
return target;
};
@toddmotto
toddmotto / listeners.js
Last active September 14, 2016 04:59
Automatic unbinding on $scope.$destroy for $rootScope listeners
/*!
* $rootScope listeners, remember to unbind on $destroy
*/
var $rootListeners = {
'transmitProgress': $rootScope.$on('transmit:progress', transmitProgress),
'transmitSuccess': $rootScope.$on('transmit:success', transmitSuccess),
'transmitError': $rootScope.$on('transmit:error', transmitError)
};
// iterate the Object and pass the methods to be called on $destroy