Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert Fischer RobertFischer

View GitHub Profile
@RobertFischer
RobertFischer / release-rules.config.js
Created Nov 9, 2020
Release Rules for a Package in a Monorepo
View release-rules.config.js
"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 {
View node_concurrency.es6
/*
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 Aug 20, 2019
GraphQL: Interfaces are better than Enums
View InterfacesVsEnums.md

Consider the following types in a schema:

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

type Bar {
@RobertFischer
RobertFischer / FakedVariantTypes.java
Last active Feb 27, 2019
Faking variant types within Java
View FakedVariantTypes.java
enum Variant<T> {
Foo(1),
Bar(true);
private final T data;
private Variant(T data) {
this.data = data;
}
@RobertFischer
RobertFischer / pre-commit
Created Jul 30, 2018
ESLint executing on changed files as a git precommit hook
View pre-commit
#!/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`
View BrandingBinding.jsx
/**
* 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.
*
@RobertFischer
RobertFischer / Router.js
Created Jul 2, 2018
Move styling within the Router.js
View Router.js
import React from 'react';
import { View } from 'react-native';
import { Scene, Router } from 'react-native-router-flux';
import { connect } from 'react-redux';
import _ from "lodash";
import WelcomeBeeWell from './components/WelcomeBeeWell';
import Login from './components/Login';
import ForgotPassword from './components/ForgotPassword';
import EmailSent from './components/EmailSent';
import BrandWelcome from './components/BrandWelcome';
@RobertFischer
RobertFischer / Description.md
Last active Jan 6, 2021
Benchmarking is Hard, Yo.
View Description.md

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 / JS.this.gotcha.js
Last active Apr 27, 2018
The Mystery of the Vanishing Self: A deep dive into a JavaScript functional programming gotcha and the meaning of "this".
View JS.this.gotcha.js
"use strict";
import Promise from 'bluebird';
import _ from 'lodash';
Promise.resolve({a:'a',b:2,c:True}).then(_.values); // This will work, returning ['a',2,True] (or some permutation thereof)
// Now let's create our own object implementing _.values(obj).
class Valuator {
values(obj) {
@RobertFischer
RobertFischer / task.js
Last active Apr 3, 2018
Task Completion Calculation
View task.js
const {taskArray,completeTasks} = this.props; // These are both arrays of task ids (and nothing else)
const totalTaskSize = _.size(taskArray);
const completeTaskSize = _.size(_.intersection(taskArray, completeTasks)) // https://lodash.com/docs/4.17.5#intersection
const pctComplete = (completeTaskSize*1.0)/(totalTaskSize*1.0);