Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim: * I am nfeldman on github. * I am nfeldman (https://keybase.io/nfeldman) on keybase. * I have a public key ASCmL7tE2W7jN4gXhtoFUTduRozJbn3qI0_NcNZezyu43wo To claim this, I am signing this object:

{   "body": {     "key": {       "eldest_kid": "012017a0cec1358416502289e93d6554e27a1b0673393019fd87cc5823a264a2718d0a",       "host": "keybase.io",       "kid": "0120a62fbb44d96ee337881786da0551376e468cc96e7dea234fcd70d65ecf2bb8df0a",       "uid": "df44552e375176116764d9d3c2671e19",       "username": "nfeldman"     },     "merkle_root": {       "ctime": 1570906265,       "hash": "73506821e290f784ab76b707d4dc81cf57fdae13c32b6aab792dd98ac57a0459162527863950692ef8681b435eafbc0a1bdbef04208b0736ed50cae36cdf732a",       "hash_meta": "1c81bbdbbd54f3327f38fe38f6ac007e30989d7d088eb7d3ec54577e9486fb87",       "seqno": 8062689     },     "service": {       "entropy": "PQCRv9BmA+/WJqWU/d/h+ADZ",       "name": "github",       "username": "nfeldman"     },     "type": "web_servi
@nfeldman
nfeldman / custom-elements.md
Last active April 27, 2016 04:58
notes on custom elements

There are two types of custom elements.

  1. custom tag
  2. type extension

Tag names must have a hyphen and must start with [a-z]. Plus some other rules.

Tag names must not be any one of:

  • annotation-xml
@nfeldman
nfeldman / find.js
Last active August 29, 2015 14:01
starting point for regexp based page search
// this is just the starting point. you can run it in the console.
// there are numerous problems to solve, like working out whether
// the text it finds is visible or not -- i.e. if a node has display: none,
// or is absolutely positioned offscreen or behind another element, or
// has visiblity: hidden, or has height: 0 and overflow: hidden, and so on.
function find (str, caseSensitive) {
var head = (document.head || document.getElementsByTagName('head')[0]),
body = (document.body || document.getElementsByTagName('body')[0]),
re = RegExp(str, 'g' + (caseSensitive ? '' : 'i')),
@nfeldman
nfeldman / firebug-xpath.js
Last active May 11, 2017 16:51
Standalone version of XPath Module from Firebug, assumes strings have a trim method
// AMD, Node flavored CommonJS, and old fashion global
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
@nfeldman
nfeldman / gist:10614719
Created April 14, 2014 03:55
an updated html5 template with no old IE support
<!doctype html>
<html lang="en">
<head>
<!-- warning: template assumes modern browser features -->
<title>UNTITLED</title>
<meta charset="utf-8">
<meta name="author" content="AUTHOR NAME">
@nfeldman
nfeldman / dictionary.js
Created July 7, 2012 23:27
one way to do a dictionary in ES5
// as a nodejs module
module.exports = makeDictionary();
function makeDictionary (dict) {
return function Dictionary () {
!dict && (dict = Object.create(null));
var Dictionary = {
__proto__: null,
get: function (name) {
@nfeldman
nfeldman / gist:2949291
Created June 18, 2012 16:35
constructor for building xml like strings
// extracted from an earlier gist that had a more comprehensive DOM-like implementation
// in this case, I didn't care about namespaces and I didn't require any operation but
// append. This is too basic to be useful for most things, but good enough for what I've
// used it for. Note that the use of ES5 accessors makes this incompatible with IE < 9.
function Tag (name) {
this.name = name;
this.attrs = Object.create(null);
this.children = [];
return this;
@nfeldman
nfeldman / gist:2934140
Created June 15, 2012 01:39
recursive readdir for node (via stackoverflow)
// http://stackoverflow.com/q/5827612/
function walk(dir, done) {
var results = [];
fs.readdir(dir, function (err, list) {
if (err) {
return done(err);
}
var i = 0;
(function next() {
var file = list[i++];
@nfeldman
nfeldman / gist:2904580
Created June 10, 2012 08:59
break text into lines of length n
// a bit messy and not optimized, but handy for basic formatting of short blocks of text
function splitToLines (string, leftMarginWidth, maxLineWidth) {
var lines = [],
line = [],
padding = Array(leftMarginWidth).join(' '),
i = 0, // cursor
p = 0, // left anchor
m = 0, // counter for searching 5 char wrap zone
s, // tmpvar
@nfeldman
nfeldman / gist:1868037
Created February 20, 2012 05:53
mimetypes list
// from node-paperboy
{
"aiff": "audio/x-aiff",
"arj": "application/x-arj-compressed",
"asf": "video/x-ms-asf",
"asx": "video/x-ms-asx",
"au": "audio/ulaw",
"avi": "video/x-msvideo",
"bcpio": "application/x-bcpio",
"ccad": "application/clariscad",