Skip to content

Instantly share code, notes, and snippets.

View jdthorpe's full-sized avatar
💭
Can we all just agree it's pronounced "kubernetes"

Jason Thorpe jdthorpe

💭
Can we all just agree it's pronounced "kubernetes"
View GitHub Profile
@jdthorpe
jdthorpe / Dealing with JSDOM Memory Usage.md
Last active March 8, 2019 04:47
Dealing with JSDOM Memory Usage

The Problem

You're using the awesome JSDOM package to process a few hundred html files and your process crashes with an error like this:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

If you're sure your code it not accidentally holding on to a reference to (nodes from) prior window objects, then the most likely cause of the apparent memory leak is that

@jdthorpe
jdthorpe / README.md
Last active August 8, 2018 05:02
Better Typings for react-dnd

The standard typings for react-dnd suck. In particular

  • They ignore the fact that thre props recieved by the wrapped component are a union of the props passed in to the react-dnd HOC and props collected by react-dnd collectors
  • Items are assigned type Object
  • DropResults are assigned the type Object

These types are a work and progress, which means they suck too. They just suck a little less than the standard typings

@jdthorpe
jdthorpe / kld.d.ts
Created August 12, 2018 17:16
A stub with some typescript typings for kld-intersections and kld-path-parser
declare module "kld-intersections" {
class Shape {}
export class Point2D {
constructor(x:number,y:number)
}
class Bezier2 extends Shape {
@jdthorpe
jdthorpe / package-lock.json
Created August 23, 2018 21:17
Resources for re-capitulating data-lake download errors
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"@types/bluebird": {
"version": "3.5.23",
"resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.23.tgz",
"integrity": "sha512-xlehmc6RT+wMEhy9ZqeqmozVmuFzTfsaV2NlfFFWhigy7n6sjMbUUB+SZBWK78lZgWHA4DBAdQvQxUvcB8N1tw=="
},
"@types/fs-extra": {
@jdthorpe
jdthorpe / Example-file.ts
Last active February 11, 2024 23:06
Webpack vs. Rollup vs. parcel.js vs. typescript bundles
// this requires `namedExports` to work with rollup:
import {join } from "lodash";
// this works with both webpack and rollup and yields a smaller package:
// import join from "lodash/join";
// this works everythere, of course:
// import _ from "lodash"
// this works everwhere because it's an external module and isn't bundled by webpack or rollup:
@jdthorpe
jdthorpe / Extending python-docx.md
Last active November 4, 2023 15:41
Extending python-docx

Extending python-docx

Background

I was recently tasked with scraping data from a few thousand of word documents each of which contained nested docx documents which were referenced by w:altChunk elements in the body of the main ./word/document.xml file, like so:

@jdthorpe
jdthorpe / Gradient Descent Constrained to the Unit Simplex
Last active April 10, 2019 04:40
Take a step in the direction of the gradient restricted to the positive simplex
<svg height="210" width="400">
<path d="M150 0 L75 200 L225 200 Z" />
Sorry, your browser does not support inline SVG.
</svg>
@jdthorpe
jdthorpe / bundle.js
Last active April 18, 2019 14:49
code emitted by webpack when packing `importScripts('./require.js');requirejs.config()`
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@jdthorpe
jdthorpe / kd.js
Created May 28, 2019 00:57
Kernel densties
function kernelDensityEstimator(kernel:{(x:number):number}, X:number[]) {
return function(V:number[]) {
return X.map(function(x) {
return [x, d3.d3.mean(V, function(v:number) { return kernel(x - v); })];
});
};
}
function kernelEpanechnikov(k:number): {(x:number):number}{
@jdthorpe
jdthorpe / README.md
Created July 3, 2019 05:52
Rational for adding collection wide typings

Having to add typings to each require is almost as useless as not having typings at all. For example,

import DB from "nedb"
const myCollection = new nedb(DB)
// insert one kind of document
myCollection.insert<{name:string}>({name:"nedb"})
// expect to find a different kind of document
myCollection.findOne<{name:number}>({},(err,doc) => console.log(typeof doc.name))