Skip to content

Instantly share code, notes, and snippets.

@thetallweeks
thetallweeks / escape-html.ts
Created November 5, 2014 17:14
Little function for escaping html characters (in TypeScript)
// From Tom Gruner @ http://stackoverflow.com/a/12034334/1660815
var entityMap = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};
import find from "lodash/find";
import get from "lodash/get";
import isEmpty from "lodash/isEmpty";
import api from "utils/api";
import { createSelector } from "reselect";
import {
actionTypesFor,
actionCreatorsFor,
selectorsFor,
{
"data_schema": {
"group": "",
"name": "String",
"title": "String",
"description": "String datatype inherited from Generic datatypes",
"type": "datatype.string",
"base_type": "datatype",
"inherits": "generic.datatype",
"version": "1.0.0",
function findTableIds(properties) {
const ids = map(properties, (property, key) => {
if (get(property, 'lhv_table')) {
return key;
}
else if (key === 'input') {
return findTableIds(get(property, 'properties'));
}
});
var response = {
title: 'Genesis 1:2-3', // what is x-gen?
verses: [
{ // first verse (we'll loop through if there are many)
osisID: 'Gen.1.2',
words: [
{ // words not within <w> are converted to this
$: 'The' // $ is always a string value
},
{
@thetallweeks
thetallweeks / github-pygments.css
Created November 14, 2013 16:33
Pygments syntax highlighting from github
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #000000; font-weight: bold } /* Keyword */
.highlight .o { color: #000000; font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold; font-style: italic } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
@thetallweeks
thetallweeks / memoize.js
Created August 22, 2014 17:59
Memoize functions
http://jsperf.com/another-memoization-comparison
// underscore.js memoize
function memoize1(func) {
"use strict";
var memo = {};
var slice = Array.prototype.slice;
return function() {
var key = "" + slice.call(arguments);
return (key in memo) ? memo[key] : (memo[key] = func.apply(this, arguments));
@thetallweeks
thetallweeks / colors.js
Created November 20, 2014 21:11
Array of colors
['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'orange', 'purple', 'red', 'silver', 'teal', 'white', 'yellow'];
@thetallweeks
thetallweeks / unit-test-private-functions.js
Last active February 16, 2016 00:47
A modified version of Phillip Walton's concept for unit testing private methods
// modified version of: http://philipwalton.com/articles/how-to-unit-test-private-functions-in-javascript/
// uses grunt-strip-code npm package during build
var myModule = (function() {
var api = {
bar: bar
};
var _bar = 'bar';
function getPrevious(n, className) {
var y = n.previousSibling;
// Check if previous node is an element node with a specific class
while (y.nodeType != 1 || !y.classList.contains(className)) {
// If not, move on to previous node
y = y.previousSibling;
}
return y;
}