Skip to content

Instantly share code, notes, and snippets.

Lee Byron leebyron

View GitHub Profile
@leebyron
leebyron / input-union-meeting-2020-5-28.md
Created May 28, 2020
Input Union Meeting 2020/5/28
View input-union-meeting-2020-5-28.md
View for-in-react-example.jsx
var children = []
for (var key in terms) {
if (terms.hasOwnProperty(key)) {
children.push(
<React.Fragment key={key}>
<dl>{key}</dl>
<dd>{terms[key]}</dd>
</React.Fragment>
)
}
@leebyron
leebyron / .flowconfig
Last active Jul 9, 2018
flow-implements-bug
We couldn’t find that file to show.
View Super-Rough-Record-Class-Types.js
declare function Record(): any
const RecordInstance = Record({
})
class _Foo extends RecordInstance {}
exports.Foo = _Foo
View Flow-Predicate-Checks.js
type HasFoo = { kind: "Foo" }
type HasBar = { kind: "Bar", baz: string }
class Other {
baz = "cool"
}
function hasBar(obj: HasFoo | HasBar | Other): boolean %checks {
return obj instanceof Other
@leebyron
leebyron / PriorityQueue.js
Last active Jan 28, 2019
PriorityQueue.js uses a binary heap to ensure the highest priority item is always available to dequeue, and sorts on enqueue. A dynamically resizing Array can be used to model the binary heap, for a simpler and more efficient implementation.
View PriorityQueue.js
/**
* For compare function return:
* - Less than zero: item1 has higher priority than item2.
* - Zero: same.
* - Greater than zero: item1 has lower priority than item2.
*/
export type CompareFunction<T> = (item1: T, item2: T) => number;
export class PriorityQueue<T> {
_items: Array<T>;
@leebyron
leebyron / index.js
Last active Aug 8, 2017
requirebin sketch
View index.js
const Observable = require("zen-observable");
let sink;
const list = [];
const error = new Error();
new Observable(_sink => {
sink = _sink;
return () => list.push('cleanup');
}).subscribe({
View keybase.md

Keybase proof

I hereby claim:

  • I am leebyron on github.
  • I am leeb (https://keybase.io/leeb) on keybase.
  • I have a public key ASBnVuESLbEjmR4Ac79vgbgOLVoPtA6GAZSV-MxsHpJ1_Ao

To claim this, I am signing this object:

@leebyron
leebyron / sort-keys.js
Created Jan 30, 2017
Sort values by key order performance
View sort-keys.js
var keys = [];
var results = [];
var keyCount = 100;
var iterations = 10000;
//generate keys 0 to <keycount>
for (var i=0; i < keyCount; i++) {
keys.push(i);
results.push({ id: i })
}
@leebyron
leebyron / maybeFilter.js
Last active Jun 29, 2016
An array filter function which does not create a new array if no items are removed.
View maybeFilter.js
function maybeFilter(array, predicate) {
var newArray;
array.forEach((item, i) => {
if (predicate(item)) {
if (newArray) {
newArray.push(item)
}
} else if (!newArray) {
newArray = array.slice(0, i)
}
You can’t perform that action at this time.