Skip to content

Instantly share code, notes, and snippets.

@jonbretman
jonbretman / connectedComponents.tsx
Created August 19, 2018 13:38
Typescript connected components example
import React from 'react';
import { connect } from 'react-redux';
// Some example state data
interface Person {
name: string;
}
interface State {
people: {
[key: string]: Person;
const graphql = require('graphql');
function getRequestedFields(query, info) {
const parsed = graphql.parse(query);
if (parsed.definitions.length > 1) {
throw new Error('Too many definitions');
}
const requested = info.operation;
module.exports = function (grunt) {
grunt.initConfig({
jshint: {
options: {
debug: grunt.option('js-debug') === true,
undef: true,
unused: 'var',
browser: true,
@jonbretman
jonbretman / gist:6281b65f14be6bb72f68
Created May 27, 2015 13:55
FontFaceObserver without Promise polyfill
!function(){"use strict";function t(t){function e(){document.body?t():setTimeout(e,0)}e()}function e(t){this.a=document.createElement("div"),this.a.setAttribute("aria-hidden","true"),this.a.appendChild(document.createTextNode(t)),this.b=document.createElement("span"),this.c=document.createElement("span"),this.h=document.createElement("span"),this.g=document.createElement("span"),this.f=-1,this.b.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;",this.c.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;",this.g.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;",this.h.style.cssText="display:inline-block;width:200%;height:200%;",this.b.appendChild(this.h),this.c.appendChild(this.g),this.a.appendChild(this.b),this.a.appendChild(this.c)}function i(t,e,i){t.a.style.cssText="min-width:20px;min-height:20px;display:inline-block;position:absolute;width:auto;margin:0;padding:0;top:-999px;le
@jonbretman
jonbretman / gist:66771bee474bfa28874a
Last active August 29, 2015 14:16
Example karma conf
grunt.initConfig({
karma: {
unitTests: {
singleRun: true,
browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon', 'expect'],
options: {
files: [
'path/to/codemirror',
'path/to/your/source/code',
var tpl = function (_swig,_ctx,_filters,_utils,_fn) {
var _ext = _swig.extensions,
_output = "";
(function () {
var __l = (((typeof _ctx.things !== "undefined" && _ctx.things !== null) ? ((typeof _ctx.things !== "undefined" && _ctx.things !== null) ? _ctx.things : "") : ((typeof things !== "undefined" && things !== null) ? things : "")) !== null ? ((typeof _ctx.things !== "undefined" && _ctx.things !== null) ? ((typeof _ctx.things !== "undefined" && _ctx.things !== null) ? _ctx.things : "") : ((typeof things !== "undefined" && things !== null) ? things : "")) : "" ), __len = (_utils.isArray(__l) || typeof __l === "string") ? __l.length : _utils.keys(__l).length;
if (!__l) { return; }
var _ctx__loopcache07607445325702429 = { loop: _ctx.loop, thing: _ctx.thing, __k: _ctx.__k };
_ctx.loop = { first: false, index: 1, index0: 0, revindex: __len, revindex0: __len - 1, length: __len, last: false };
_utils.each(__l, function (thing, __k) {
_ctx.thing = thing;
@jonbretman
jonbretman / Gruntfile.js
Last active August 29, 2015 13:56
Simple grunt task for instrumenting javascript files and then generating reports from coverage data
module.exports = function (grunt) {
grunt.initConfig({
coverage: {
// set this to the coverage object created from running the instrumented code
coverage: null,
// task for generating instrumented code
@jonbretman
jonbretman / css-linter.js
Last active August 29, 2015 13:56
Look for bad CSS
/**
* CSSLinter Class
* @param {Object} options
* @constructor
*/
var CSSLinter = function (options) {
var css = require('css');
var fs = require('fs');
@jonbretman
jonbretman / underscore_templating.js
Last active August 29, 2015 13:55
Underscore templates with Mustache style tags and include functionality
var templates = {
register: function (key, template) {
this[key] = _.template(
'<% ' +
'var include=_.bind(function(k,d){print(this[k](d))},this);' +
'var includeEach=_.bind(function(k,d){_.each(d,function(v){print(this[k](v))},this)},this);' +
'var includeIf=_.bind(function(k,d){if(d)print(this[k](d))},this);' +
' %>' +
template,
null,
@jonbretman
jonbretman / type.js
Last active January 16, 2024 01:16
Simple type checking in JavaScript.
(function (root) {
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements