Skip to content

Instantly share code, notes, and snippets.

@spion
spion / a-warning.md
Last active Sep 18, 2020
C++ versus V8 versus luajit versus C benchmark - (hash) tables
View a-warning.md

Warning

This benchmark has been misleading for a while. It was originally made to demonstrate how JIT compilers can do all sorts of crazy stuff to your code - especially LuaJIT - and was meant to be a starting point of discussion about what exactly LuaJIT does and how.

As a result, its not indicative of what its performance may be on more realistic data. Differences can be expected because

  1. the text will not consist of hard-coded constants
View translate-error.js
function translateError(msg) {
var newErr = new Error(msg); // placed here to get correct stack
return e => {
newErr.originalError = e;
throw newErr;
}
}
async function asyncTask() {
const user = await UserModel.findById(1).catch(translateError('No user found'))
View estimate.md

Software estimation Q&A

Q: What do the points mean?

A: Lets say we have two engineers, E1 and E2, estimating a story S. E1 believes the story can be done in time T1. E2 believes it can be done in time T2.

We assign the velocity numbers V1 and V2 to these two engineers, such that

View sync-async-adapter.js
let Read = {};
let End = {};
function* lexer() {
let accumulatedChars = [];
while (true) {
let inp = yield Read;
if (inp === End) {
if (accumulatedChars.length > 0) yield accumulatedChars.join('');
return;
View simplified.ts
function inRange(a: number, min: number, max: number) {
return min <= a && a <= max;
}
class UTF8Encoder {
bytes = new Uint8Array(4).fill(0)
len = 0;
toBytes(codePoint: number):void {
@spion
spion / features.md
Last active Apr 12, 2020
Adding features to a software product
View features.md

New features and changes workflow guide

This guide describes what steps usually work best when adding new features to a product. The guidelines are not mandatory; simpler features may not need any of these steps. They exist to help battle the hardest new features to add :)

The steps are not necessarily in the correct order - this is the usual order. Going back to an older step to add/change things is okay.

Brainstorming sessions

Goal: collect all that we can come up with for the new feature or change. Everything goes into an unorganized document (wiki page). Possible ways to organize this document is into proposal items (and proposal detail item for each proposal item).

View techempower.diff
diff --git a/frameworks/JavaScript/express/express-postgres.dockerfile b/frameworks/JavaScript/express/express-postgres.dockerfile
index f2907bd02..9b2196082 100644
--- a/frameworks/JavaScript/express/express-postgres.dockerfile
+++ b/frameworks/JavaScript/express/express-postgres.dockerfile
@@ -1,9 +1,9 @@
FROM node:12.3.1-slim
-COPY ./ ./
-
+COPY package.json ./
@spion
spion / 01-fractal-weird-design.md
Last active Nov 2, 2019
Node streams - a fractal of weird design
View 01-fractal-weird-design.md

Node streams - a fractal of weird design

and a potential refactor that could fix that

This is a list of issues and confusions I've encountered with node streams, and things I wish were designed and implemented differently. If promise-streams is ever going to change to a design that doesn't build on top of node streams, this would be a list of mistakes to avoid

  1. enc parameter - Why is encoding always passed together with the data? It should be a separate concern. It doesn't even make sense in objectMode
  2. eventemitter base - This encourages a lot of random events to be "attached" by other authors which doesn't work. Best to have an uniform (typed) interface so that everyone knows what to expect.
  3. relying on nextTick etc for execution order - This is very unreliable and causes all sorts of unpredictable rules for implementers which are not documented anywhere. When you attach listeners determines what will happen.
  4. no error propagation - we need the
View mobx.js
@observer class Chart(props) {
@computed get data() { return getDataWithinRange(this.props.dateRange) }
@computed get dimensions() { return getDimensions() }
@computed get xScale() { return getXScale() }
@computed get yScale() { return getYScale() }
render() {
// use this.xScale, this.yScale etc. component will re-render automatically if any of those update.
return <svg className="Chart" />
}
View gist:96b6232b151d1007a2aa396c2e2c478a

Be careful when feature flags affect any shared mutable state. This for example will cause data loss if the flag value changes during the work:

this.fancyModel = FancyModel.createInitial()
this.rustyModel = RustyModel.createInitial()

async loadData() { 
  let flag = await this.ff.isEnabled('flag');
  let data = await this.fetchData();
You can’t perform that action at this time.