Skip to content

Instantly share code, notes, and snippets.

View toddmotto's full-sized avatar

Todd Motto toddmotto

View GitHub Profile
<div class="module">
<div class="module__thing">
<h1 class="module__thing-title">Hi</h1>
</div>
<div class="module__content">
<p class="module__content-text">Oh, hello.</p>
</div>
</div>
@toddmotto
toddmotto / gist:10960869
Created April 17, 2014 07:28
ECMAScript 5 .bind() Polyfill
Function.prototype.bind = Function.prototype.bind || function (target) {
var self = this;
return function (args) {
if (!(args instanceof Array)) {
args = [args];
}
self.apply(target, args);
};
};
@toddmotto
toddmotto / gist:9890835
Created March 31, 2014 12:04
AngularJS ng-options RegExp
/^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/
@toddmotto
toddmotto / consoleLoge.js
Last active August 29, 2015 13:57
console.loge(), many log, much console
window.console.loge = function (msg) {
var gifs = ['wink','shake-space','peepers','prizza','hat','gradient','fat','rainbow','sunglasses','derp','shake'],
wow = ['', 'wow! ', 'amaze! ', 'dazzle! '],
adjs = ['so', 'such', 'many', 'much', 'very'],
randomizr = function (a) { return a[Math.floor(Math.random() * a.length)];},
message = '%c ' + randomizr(wow) + randomizr(adjs) + ' ' + typeof msg + ': ',
css = 'background: url(http://d1e3ezyatlol8u.cloudfront.net/img/212/doge-' + randomizr(gifs) + '-212.gif) no-repeat 0 0; background-size: 80px 80px; font-family: \'Comic Sans MS\', cursive; text-shadow: 0 1px 1px rgba(0,0,0,1); font-size: 14px; padding: 25px; line-height: 70px; color: #fff; font-weight: 100;';
console.log.apply(console, typeof msg === 'object' ? [message, css, msg] : [message += msg, css]);
};
var isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
@toddmotto
toddmotto / gist:9370782
Created March 5, 2014 16:34
Recursive Object traversal (loops through Object keys and Arrays)
var updateKeys = function (form) {
var objString = Object.prototype.toString;
var traverse = function (obj) {
if (objString.call(obj) === '[object Array]') {
for (var i = 0; i < obj.length; i++) {
console.log(obj[i].type, obj[i].title);
traverse(obj[i]);
}
@toddmotto
toddmotto / gist:9346064
Created March 4, 2014 13:00
Fixed heights/content JavaScript applications
(function (root, document, undefined) {
var $$ = function () {
return document.querySelectorAll(arguments[0]);
};
var header = $$('.header')[0];
var headerHeight = header.offsetHeight;
var content = $$('.main')[0];
var sidebar = $$('.sidebar')[0];
@toddmotto
toddmotto / gist:8433866
Created January 15, 2014 10:15
Safe $scope.$apply();
myApp.service('Apply', ['$scope', function ($scope) {
return function ($scope) {
if (!$scope.$$phase) {
$scope.$apply();
}
};
}]);
@toddmotto
toddmotto / gist:8350837
Created January 10, 2014 12:04
Conditionizr test for localhost, add optional port number: /(?:127.0.0.1|localhost):9000/
conditionizr.add('localhost', [], function () {
return /(?:127.0.0.1|localhost)/.test(location.host);
});
@toddmotto
toddmotto / gist:8299402
Created January 7, 2014 13:41
Stop npm sudo-ing
sudo chown -R `whoami` ~/.npm
sudo chown -R $USER /usr/local