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 / 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 / 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 / Gruntfile.js
Created July 12, 2014 21:26
Loading Scripts for AngularJS
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
jade: {
local: {
options: {
data: function() {
return require('./jade/getIndexData')('local');
}
@kentcdodds
kentcdodds / index.jade
Created July 12, 2014 21:47
Part of medium blog
// This file is generated from index.jade
doctype html
html(lang="en", ng-app="dv.web", ng-controller="MainCtrl", ng-class="{'auth': authenticated, 'anon': !authenticated, 'small-screen': smallScreen}")
head
// create global DV object
script.
window.DV = {};
window.DV.BASE_URL = '#{BASE_URL}';
window.DV.FBAPI = '#{FBAPI}';
window.DV.onDev = #{onDev};
@kentcdodds
kentcdodds / getIndexData.js
Created July 12, 2014 21:49
For a medium post
var fs = require('fs');
var _ = require('lodash-node');
var glob = require('glob');
var address = require('address');
module.exports = function(env) {
'use strict';
var topScripts = [
'bower_components/angular/angular.js'
];
@kentcdodds
kentcdodds / kcd-recompile-usage.html
Created July 16, 2014 04:55
kcd-recompile usage
<div kcd-recompile="recompileAllTheThings" use-boolean>
<div ng-repeat="thing in ::things" kcd-recompile="thing.recompileCount">
<img ng-src="{{::thing.getImage()}}">
<span>{{::thing.name}}</span>
<button ng-click="thing.recompileCount=thing.recompileCount+1">Recompile This Thing</button>
</div>
</div>
<button ng-click="recompileAllTheThings=true">Recompile All Things!</button>