Skip to content

Instantly share code, notes, and snippets.

View andrewbranch's full-sized avatar

Andrew Branch andrewbranch

View GitHub Profile
@andrewbranch
andrewbranch / writing-type-definitions.md
Last active November 3, 2023 19:07
Writing type definitions, on a scale of 1–5

Writing type definitions, on a scale of 1–5

By hand With tsc With 3rd party tool
Ease 1 5 4
Avg. correctness 2 5 2
Flexibility 5 1 3
@andrewbranch
andrewbranch / tsc-ts-vs-dts.md
Last active May 31, 2024 20:54
tsc performance consuming .ts vs .d.ts files in npm packages

Original Tweet

tsc performance consuming .ts vs .d.ts files in npm packages

What if TypeScript libraries published just .ts sources to npm instead of .js and .d.ts files? This might already be tempting for Bun-only libraries, but how will that impact users? This is easy to answer by experimenting on existing libraries that ship .js, .d.ts, and .ts files.

RxJS ships .js and .d.ts files, but also .ts files for debugability purposes. By tweaking its package.json "exports", we can compare tsc performance on this file with imports resolving to .d.ts files vs .ts source files:

import {} from "rxjs";
@andrewbranch
andrewbranch / avrdude.conf
Created February 19, 2018 05:03
Modified avrdude.conf for Adafruit Trinket
# $Id: avrdude.conf.in 1371 2016-02-15 20:15:07Z joerg_wunsch $ -*- text -*-
#
# AVRDUDE Configuration File
#
# This file contains configuration data used by AVRDUDE which describes
# the programming hardware pinouts and also provides part definitions.
# AVRDUDE's "-C" command line option specifies the location of the
# configuration file. The "-c" option names the programmer configuration
# which must match one of the entry's "id" parameter. The "-p" option
# identifies which part AVRDUDE is going to be programming and must match
@andrewbranch
andrewbranch / transpose-array-test.js
Created February 5, 2016 20:54
#algorithm challenge: more elegant way to do this
import { describe, it, beforeEach } from 'mocha';
import assert from 'assert';
import transposeArray from './transpose-array';
describe('transpose-array', () => {
let array;
beforeEach(() => array = [0, 1, 2, 3, 4, 5]);
it('works for downward transpositions', () => {
let result = transposeArray(array, 4, 2);
@andrewbranch
andrewbranch / set-seq-splitting-efficiency.js
Last active November 18, 2015 18:53
One of these is around 10x faster than the other two
// filtered is an Immutable.Seq (lazy sequence) with 307 entries
let withinCountry = filtered.filter(p => p.get('locations').some(isSameCountry(yourLocation)));
let outsideCountry1 = filtered.filter(p => !withinCountry.includes(p));
let outsideCountry2 = filtered.filter(p => !p.get('locations').some(isSameCountry(yourLocation)));
let outsideCountry3 = filtered.toSet().subtract(withinCountry);
return withinCountry.sort(someWayOfSorting)
.concat(outsideCountryN.sort(someOtherWayOfSorting))
.take(10);
@andrewbranch
andrewbranch / sort.js
Last active September 1, 2015 01:16
Variadic sort
function getTestPeople() {
return [{
name: "Kylie",
age: 18
}, {
name: "Andrew",
age: 23
}, {
name: "Andrew",
age: 18
@andrewbranch
andrewbranch / promise-bad.js
Created June 30, 2015 20:09
I frequently overcomplicate Promises
someAsyncMethod() {
return new Promise((resolve, reject) => {
somePromiseReturningMethod().then(x => {
resolve(doSomethingTo(x));
});
});
}
@andrewbranch
andrewbranch / keybase.md
Created March 22, 2015 00:15
Verifying my GitHub identity on keybase.io

Keybase proof

I hereby claim:

  • I am andrewbranch on github.
  • I am andrewbranch (https://keybase.io/andrewbranch) on keybase.
  • I have a public key whose fingerprint is 3F80 A965 F914 BC02 8650 E395 22CC A4B1 20C4 27D2

To claim this, I am signing this object:

@andrewbranch
andrewbranch / defer-with-promise.js
Created December 19, 2014 03:20
Explore the effect of Promises on JS speed and order of execution
var trash = [];
function computationallyIntensiveStuff() {
trash.push(Math.pow(Math.pow(Math.cos(Math.sin(Math.random())), Math.random()), Math.random() * 100000));
trash.filter(function (a) { return a > Math.random(); });
}
new Promise(function (resolve, reject) {
for (var i = 0; i < 1000; i++) {
@andrewbranch
andrewbranch / RadioView.swift
Last active August 29, 2015 14:11
Simple, elegant radio button view
class RadioView: UIView {
var selected: Bool = false {
didSet {
UIView.animateWithDuration(self.fadeTime) {
self.inner.alpha = self.selected ? 1 : 0
}
}
}