Skip to content

Instantly share code, notes, and snippets.

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 Mar 9, 2014
Angular-UI Router states auth/anon
View states.js
$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 Aug 29, 2015
Sort the papers for Utah JS by vote
View conf.utahjs.sort.js
// 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 Aug 29, 2015
Will print out the full error message when it's been omitted
View long-errors.js
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 Aug 29, 2015
Folder Structure styles
View README.md

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.

View kcd-base-64.js
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 Jun 21, 2014
A method for hijacking the $new of scopes.
View hijack-new.js
// 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 Jul 12, 2014
Loading Scripts for AngularJS
View Gruntfile.js
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 Jul 12, 2014
Part of medium blog
View index.jade
// 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};
View getIndexData.js
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'
];
View kcd-recompile-usage.html
<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>