Skip to content

Instantly share code, notes, and snippets.

View kentcdodds's full-sized avatar
馃
working hard to make the world better with software

Kent C. Dodds kentcdodds

馃
working hard to make the world better with software
View GitHub Profile
@kentcdodds
kentcdodds / Firebase.js
Created January 28, 2014 06:37
Introduction to AngularJS code snippets
{
"people": {
"Joe": {
"birthday": "October 18th, 1988",
"favoriteIceCream": "Mint Chocolate Chip"
},
"Mary": {
"birthday": "December 23rd, 1986",
"favoriteIceCream": "Vanilla"
}
@kentcdodds
kentcdodds / states.js
Created March 9, 2014 06:11
Angular-UI Router states auth/anon
$stateProvider.
state('main', {
abstract: true,
url: '/',
templateUrl: '/main/index.html',
controller: 'SuperCtrl',
resolve: {
isAuthenticated: function($q, $http) {
var deferred = $q.defer();
$http.get('/api/v1/auth/isAuthenticated').then(function(response) {
@kentcdodds
kentcdodds / AuthInterceptor.js
Created April 1, 2014 20:57
Example interceptor for jpotts
angular.module('bs.common.models').factory('AuthInterceptor', function ($rootScope, $q, $window) {
return {
request: function (config) {
config.headers = config.headers || {};
var token = $window.localStorage.getItem('user-token');
if (token) {
config.headers.Authorization = 'Bearer ' + token;
}
return config;
},
@kentcdodds
kentcdodds / chooser.js
Last active July 12, 2021 14:17
JSHint Options Chooser
// Just paste this into the console on http://www.jshint.com/docs/options/
(function() {
var i, row, link, span, extraCol, checkbox, value;
var rows = document.querySelectorAll('table.options tr');
var links = document.querySelectorAll('table.options a');
// add checkboxes
for (var i = 0; i < rows.length; i++) {
row = rows[i];
@kentcdodds
kentcdodds / conf.utahjs.sort.js
Last active August 29, 2015 14:01
Sort the papers for Utah JS by vote
// Paste this into the console on http://conf.utahjs.com/vote
(function() {
var tableBody = $('tbody');
$('.score').map(function(index, score) {
return {
el: $(score).parents('tr'),
score: ~~score.innerText
};
}).sort(function(a, b) {
return a.score < b.score ? 1 : a.score > b.score ? -1 : 0;
@kentcdodds
kentcdodds / long-errors.js
Last active August 29, 2015 14:01
Will print out the full error message when it's been omitted
window.onerror = function (errorMsg, url, lineNumber, columnNumber, errorObject) {
if (/<omitted>/.test(errorMsg)) {
console.error('Error: ' + errorObject ? errorObject.message : errorMsg);
}
};
@kentcdodds
kentcdodds / README.md
Last active August 29, 2015 14:01
Folder Structure styles

Project Folder Structure

I'd love some feedback on a project folder structure I've been considering/trying out. I just don't know why people aren't doing this already and I think I may just be missing something. Is there a problem with the different.md that I'm just missing. Leave comments below. Thanks for the feedback.

angular.module('app').directive('kcdBase64', function () {
'use strict';
return {
restrict: 'A',
template: [
'<span class="button file-upload-button">',
'<span>Select Image</span>',
'<input type="file" class="input-file" accept="image/*">',
'</span>'
].join(''),
@kentcdodds
kentcdodds / hijack-new.js
Created June 21, 2014 03:51
A method for hijacking the $new of scopes.
// How bad is this? Do you see any problems with doing this?
var scopePrototype = Object.getPrototypeOf($rootScope);
var oldNew = scopePrototype.$new;
// hijack the prototype's $new
scopePrototype.$new = function $new() {
var scope = oldNew.apply(this, arguments);
addFunctionality(scope);
return scope;
};
@kentcdodds
kentcdodds / angular-static-server.js
Last active November 24, 2015 00:36 — forked from ryanflorence/static_server.js
Angular Static Server - Serves up static files. If the request doesn't match one, it'll send the hash version and lets Angular leverage html5Mode. Haven't tested it with Ember or others, but I imagine they'd work just as well. Thanks to rpflorence for the original version.
var http = require('http');
var url = require('url');
var path = require('path');
var fs = require('fs');
var base = path.join(process.cwd(), process.argv[2] || '');
var port = process.argv[3] || 8888;
var extensionRegex = /\.([0-9a-z]+)(?:[\?#]|$)/i;
var contentTypeMap = {
html: 'text/html',