Skip to content

Instantly share code, notes, and snippets.

View leebyron's full-sized avatar
🌎

Lee Byron leebyron

🌎
View GitHub Profile
@leebyron
leebyron / sort-keys.js
Created January 30, 2017 21:42
Sort values by key order performance
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 June 29, 2016 08:34
An array filter function which does not create a new array if no items are removed.
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)
}

Languages have various allowances for white-space. This is a short exploration of parsers I found and what they claim to accept

Key

Oct  Dec Char  Hex  Key Esc
\000   0  NUL  \x00  ^@ \0 (Null byte)
\010   8   BS  \x08  ^H \b (Backspace)
\011   9   HT  \x09  ^I \t (Horizontal tab)
\012  10   LF  \x0A  ^J \n (Line feed)  (Default UNIX NL)
TN:
SF:/Users/leebyron/src/dataloader/src/__tests__/abuse-test.js
FN:15,_interopRequireDefault
FN:25,(anonymous_2)
FN:27,(anonymous_3)
FN:28,(anonymous_4)
FN:32,(anonymous_5)
FN:37,(anonymous_6)
FN:38,(anonymous_7)
FN:42,(anonymous_8)
@leebyron
leebyron / index.js
Created April 16, 2015 19:44
requirebin sketch
'use strict';
var React = require('react');
var Immutable = require('immutable');
var Map = Immutable.Map;
var List = Immutable.List;
var Component = React.createClass({
displayName: 'Component',
@leebyron
leebyron / privatemethods.js
Last active August 29, 2015 14:17
How might "private methods" be transpiled to define a semantic behavior?
// Private methods (instance and static) are different from private properties
// because they are not assigned per instance. Instead, they can be thought of
// as a nested function, scoped to the class body.
// Resolution of a private `@x()` method can be done with brand checks, but
// inlined when the resolution can be determined statically.
class C {
m(somethingElse) {
somethingElse.@x();

Additonal export-from statements in ES7

The export ___ from "module" statements are a very useful mechanism for building up "package" modules in a declarative way. In the ES6 spec, we can export through a single export with export {x} from "mod", optionally renaming it with export {x as v} from "mod". We can also spread all exports with export * from "mod".

These three export-from statements are easy to understand if you understand the semantics of the similar looking import statements.

var tree = Immutable.fromJS(
{id: 0, children: [{id: 1, children: [{id: 2}, {id: 3}]}, {id: 4, children: [{id: 5}, {id: 6}]}]}
);
function reduceFn(list, item) {
var children = item.get('children');
list = children ? children.reduce(reduceFn, list) : list;
list = list.push(Immutable.Map({id: item.get('id')}));
return list;
}
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# first load in the master bash
if [ -f /etc/master_bash ]; then
. /etc/master_bash
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-with-addons-0.12.0.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">