Skip to content

Instantly share code, notes, and snippets.

View calebdwilliams's full-sized avatar

Caleb Williams calebdwilliams

View GitHub Profile
describe('GridController', function() {
beforeEach(module('GridApp'));
var GridApp, controller, scope, ctrl;
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller;
ctrl = controller('GridController', {
@calebdwilliams
calebdwilliams / evalMethod.filter.js
Created September 18, 2015 19:30
Defines a filter on the $filter provider that will call a method to filter objects inside of ngRepeat.
angular.module('myApp.filters', [])
/**
* Defines a filter on the $filter provider that will call a method
* to filter objects inside of ngRepeat.
*
* @return {Function}
* @param {Array} - the array to loop through
* @param {String} - the Object method name
* @param {Any} - the value to match against
* @return {Array} - the resultant array
(function() {
angular.module('myApp.directives')
.directive('validateClass', [function() {
return {
restrict: 'A',
link: function validateClassLink(scope, element, attributes, ngForm) {
var fieldObj = ngForm[attributes.validateClass],
className = attributes.errorClass || 'has-error';
scope.$watch(function() {
@calebdwilliams
calebdwilliams / binarySearch.js
Last active March 22, 2016 20:55
Basic binary search demonstration.
function generateArray() {
'use strict';
let length = Math.floor(Math.random() * 100000),
remove = Math.floor(Math.random() * length),
array = [];
for (let counter = 0; counter <= length; counter += 1) {
array.push(counter);
}
const traceProperty = (object, property) => {
let value = object[property];
Object.defineProperty(object, property, {
get () {
console.trace(`${property} requested`);
return value;
},
set (newValue) {
console.trace(`setting ${property} to `, newValue);
value = newValue;
function fetchResource(url, interval = 500, i = 1) {
let attempts = 0;
return new Promise((resolve, reject) => {
const repeat = setInterval(() => {
fetch(url)
.then(response => {
if (response.ok) {
resolve(response);
clearInterval(repeat);
export const updatePath = (obj, path, value) => {
const paths = path.split('.');
const location = paths.pop();
let pointer = obj;
for (let point in paths) {
const path = paths[point];
if (path in pointer) {
pointer = pointer[path];
} else {
/**
* This code was adapted from the excellent Braid Design System
* by SEEK OSS, you can find their original code code here
* https://github.com/seek-oss/braid-design-system/blob/master/lib/hooks/typography/basekick.ts
*
* They're doing some really amazing stuff and I got to copy them here,
* you should definitely check them out.
*/
@calebdwilliams
calebdwilliams / rollup-plugin-lit-scss.js
Created June 25, 2020 15:44
Rollup Plugin LitElement SCSS
import sass from 'node-sass';
import { resolve, extname } from 'path';
import { processString } from 'uglifycss';
import stringToTemplateLiteral from 'string-to-template-literal';
import nodeSassImporter from 'node-sass-package-importer';
const importer = nodeSassImporter();
function transform(css) {
return `import { css } from 'lit-element';
@calebdwilliams
calebdwilliams / mixin-annotated.js
Created July 15, 2020 14:17
Mixin annotation with JSDoc and TypeScript
import { LitElement } from 'https://cdn.pika.dev/lit-element@^2.3.1';
/** @typedef {new (...args: any[]) => any} Constructor */
/**
* @template {!Constructor} T
* @param {T} superclass - The class to extend
*/
const FormControlMixin = (superclass) =>
class FormControl extends superclass {