Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
RobertFischer / Description.md
Last active October 14, 2023 16:47
Benchmarking is Hard, Yo.

So, I was reading Why You shouldn’t use lodash anymore and use pure JavaScript instead, because once upon a time, I shifted from Underscore to Lodash, and I'm always on the lookout for the bestest JavaScript stdlib. At the same time, there was recently an interesting conversation on Twitter about how some of React's functionality can be easily implemented in modern vanilla JS. The code that came out of that was elegant and impressive, and so I have taken that as a message to ask if we really need the framework.

Unfortunately, it didn't start out well. After copy-pasting the ~100 lines of code that Lodash executes to perform a find, there was then this shocking claim: Lodash takes 140ms, and native find takes 0ms.

@RobertFischer
RobertFischer / deidentify-help.txt
Created December 22, 2022 19:25
deidentify help
usage: deidentify [Options] <infile> <outfile>
or deidentify [Options] <infile>... <outdir>
or deidentify [Options] <indir>... <outdir>
De-identify one or several DICOM files according the Basic Application
Level Confidentiality Profile specified in DICOM Part 15.
-
Options:
--expl-item-len encode sequence items with explicit length; at
default, non-empty sequence items are encoded with
@RobertFischer
RobertFischer / pre-commit
Created July 30, 2018 21:12
ESLint executing on changed files as a git precommit hook
#!/bin/bash -u
#
# Run eslint on js and jsx files that are being committed, including doing a round of fixing up
# those files.
#
# Based on @dahjelle/pre-commit.sh and @jancimajek's one liner in that Gist.
#
NAMES=`git diff --diff-filter=d --cached --name-only -- '*.js' '*.jsx' | wc -l`
@RobertFischer
RobertFischer / sample.jsonpp
Created November 4, 2021 18:29
JSON++ Sample
{
alphanumeric_field_needs_quotes: false,
_leading_undderscores_ok: true,
trailing_underscores_ok_: true,
carriage_return_acts_like_comma: true
"vanilla JSON keys also supported": true
"a list with null element in at index 1": [0,,2,3,4,5]
"a list with null element in at index 0": [,1,2,3,4,5]
"a list with null final element": [0,1,2,3,4,]
"empty list is interpreted as the empty list, not [null]": []
@RobertFischer
RobertFischer / release-rules.config.js
Created November 9, 2020 16:04
Release Rules for a Package in a Monorepo
"use strict";
const _ = require("lodash");
const defaultRules = require("@semantic-release/commit-analyzer/lib/default-release-rules");
const scope = require(`${__dirname}/package.json`).name; // You may want to remove whatever's before a "/" in the name.
module.exports = _.map(
(defaultRules),
(defaultRule) => {
return {
@RobertFischer
RobertFischer / Retry.java
Last active July 25, 2020 22:12
A utility method for retrying on exception, using Java 8 lambdas
public class Retry {
private static final Logger log = Logger.getLogger(Retry.class);
public static interface CallToRetry<T> {
<T> T doIt() throws Exception;
}
public static T withRetry(int maxTimes, long initialWait, int waitMultiplier, CallToRetry<T> call) {
if(maxTimes <= 0) {
@RobertFischer
RobertFischer / node_concurrency.es6
Last active March 5, 2020 20:16
Node concurrency
/*
Node itself is single-threaded. There is some concurrency stuff that comes from calling out to
C libraries and I/O, but it can be ignored unless you’re performance-tuning: in general, think of
your entire application as executing on one single thread.
Asynchronous actions in Node are all callback-based (“continuation passing style”, or CPS): at
any point when Node needs to perform something asynchronously (eg: I/O), the Node API will take
a callback and invokes that callback with the results. The convention for those callbacks is that
the first argument is the error (if any), and the rest of the arguments are the results.
@RobertFischer
RobertFischer / InterfacesVsEnums.md
Last active August 20, 2019 10:57
GraphQL: Interfaces are better than Enums

Consider the following types in a schema:

type Foo {
	id:ID!
	weight:Number!
	foo:Number!
}

type Bar {
@RobertFischer
RobertFischer / FakedVariantTypes.java
Last active February 27, 2019 18:31
Faking variant types within Java
enum Variant<T> {
Foo(1),
Bar(true);
private final T data;
private Variant(T data) {
this.data = data;
}
/**
* Merges together Colors and BrandingImages into a single
* coherent branding structure.
*
* Using the function `brandingFromRedux` in `mapStateToProps` will give you
* a single object containing all the branding colors and images. If you return the
* object that we generate here (possibly with some other additions) as the `props` for
* your component, then you can use whatever you want from the branding colors and images
* without having to think about defaulting or wiring up additional fields or whatever.
*