Skip to content

Instantly share code, notes, and snippets.

View toddmotto's full-sized avatar

Todd Motto toddmotto

View GitHub Profile
@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
@toddmotto
toddmotto / gist:6730919
Created September 27, 2013 16:04
Assumptious click/touch binding events
var device = function () {
return 'ontouchstart' in window ? 'touchstart' : 'click';
};
element.on(device(), myFunction);
@toddmotto
toddmotto / gist:6596373
Created September 17, 2013 15:56
Disable Web Security in Chrome Canary to make cross-domain XHR requests (local servers obvs).
open -a Google\ Chrome\ Canary --args --disable-web-security
window.globalData = {};
globalData.alarms = {
totalApplications : '107',
monitoring: [{
"applicationName": "JIRA",
"applicationId": "174-94784",
"dateOfLastFault": "20130828T1103",
"currentFault": "20130828T1327"
},{
"applicationName": "AWS",
@toddmotto
toddmotto / gist:6345979
Created August 26, 2013 20:03
Mobile detects
(function(a) {
if(/android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(ad|hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|playbook|silk/i.test(a)
||
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt
@toddmotto
toddmotto / gist:6249144
Created August 16, 2013 11:36
XAMPP svg+xml MIME Type
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/trunk/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/trunk/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure