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 / 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 / Gruntfile.js
Created July 12, 2014 21:46
Medium blog post gist
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 / get-watchers.js
Last active December 4, 2023 22:34
Get Watchers of element and its children
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
@kentcdodds
kentcdodds / kcd-recomplie.js
Last active September 28, 2016 19:53
kcd-recompile
angular.module('kcd.directives').directive('kcdRecompile', ['$parse', function($parse) {
'use strict';
return {
transclude: true,
link: function link(scope, $el, attrs, ctrls, transclude) {
var previousElements;
compile();
function compile() {
@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>
@kentcdodds
kentcdodds / get-all-listeners.js
Created July 23, 2014 21:42
Get all listeners of an element and it's children. Requires a command line api.
(function() {
window.getAllEventListeners = getAllEventListeners;
function getAllEventListeners(root) {
root = root || document.documentElement;
var listeners = mapListeners(getEventListeners(root), root);
eachArray(root.children, function(child) {
listeners = listeners.concat(getAllEventListeners(child));
});
@kentcdodds
kentcdodds / StateUtilsProvider.js
Created July 27, 2014 03:57
StateUtilsProvider
angular.module('pk.web.services').provider('StateUtils', function(_, FILE_ROOT, API_V1_URL) {
'use strict';
var rootUrl = '/';
var templateRoot = FILE_ROOT + 'components/pk.web/app/';
var divView = '<div ui-view></div>';
var absoluteDivView = '<div class="position-relative"><div ui-view class="animated-view"></div></div>';
var injector;
_.extend(this, {
rootUrl: rootUrl,
templates: {
@kentcdodds
kentcdodds / package.json
Created July 31, 2014 19:12
react-components-library package.json
{
"name": "react-components-library",
"version": "0.0.0",
"description": "A library of react components.",
"private": true,
"scripts": {
"test": "./script/test",
"start": "node server.js",
"dev": "./script/dev",
"run": "./script/run"