Skip to content

Instantly share code, notes, and snippets.

Workin on my app

James Long jlongster

Workin on my app
Block or report user

Report or block jlongster

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View promise-local-storage.js
const async_hooks = require('async_hooks');
let store = new Map();
let promiseStorageHook = async_hooks.createHook({
init(id, type, triggerId, resource) {
if (store.get(triggerId)) {
if (type === 'PROMISE') {
store.set(id, store.get(triggerId));
View context-no-update.js
import React from 'react';
import { View, Text, ScrollView, TouchableOpacity } from 'react-native';
let NamespaceContext = React.createContext(undefined);
export default class ExamplePage extends React.Component {
constructor() {
this.state = { currentMonth: 1 };
View merkle.js
import Timestamp from './timestamp';
function getKeys(trie) {
return Object.keys(trie).filter(x => x !== 'hash');
function keyToTimestamp(key) {
// 16 is the length of the base 3 value of the current time in
// minutes. Ensure it's padded to create the full value
let fullkey = key + '0'.repeat(16 - key.length);
View hashlist.js
// UPDATE: don't use this. when it re-partitions the list when time moves forward, it does not correctly keep hashes
// Use a real merkle tree instead:
import Timestamp from './timestamp';
// This is a compact data structure that keeps track of a list of
// hashes (representing messages) over a range of time in order to
// figure out what has changed between clients, kinda like a Merkle
// tree. It creates "buckets" that represent different time ranges,
// and divides time into smaller buckets the more recent they are. The
View ElementQuery.js
import React from 'react';
import lively from 'lively';
// Global registry and resize handler
let _registeredInstances = [];
function register(inst) {
if (_registeredInstances.length === 0) {
window.addEventListener('resize', onResize);

3 Gripes With React

I started using React 3.5 years ago, and I still love it. It was such a well-designed solution that not much has changed since then, only superficial stuff like naming. What I learned then is still wholly applicable today because it's such a good idea (although now you can choose from many other libraries). On top of that, we now benefit from an entirely new architecture (fiber) without changing much.


Head Over Heels for Snapshot Testing

Tests are interesting, because you're trying to test code. But to write tests, you have to write code. Who tests the tests? For tests to be worth it you need to be sure that for each line of code you add, the value being added is more than the liability.

Value > Liability

Because belive me, tests are a liability. First, they are code that

View gist:0edb53ce69cbd038d65e207f9586a1d0
Could not cast value of type 'DetoxAppDelegateProxy' (0x10ffafed0) to 'Blink.AppDelegate' (0x10f998c20).
Signal caught: Abort trap: 6
0 EarlGrey 0x0000000127e1d339 grey_signalHandler + 249
1 libsystem_platform.dylib 0x0000000116826b3a _sigtramp + 26
2 libsystem_kernel.dylib 0x00000001167ea430 libsystem_kernel.dylib + 1072
3 libsystem_c.dylib 0x000000011659588f abort + 127
4 libswiftCore.dylib 0x0000000115c4dd55 _ZN5swift10fatalErrorEjPKcz + 149
5 libswiftCore.dylib 0x0000000115c2bdbb _ZN5swift24swift_dynamicCastFailureEPKvPKcS1_S3_S3_ + 75
6 libswiftCore.dylib 0x0000000115c2be20 swift_dynamicCastClass + 0
7 libswiftCore.dylib 0x0000000115c2bec0 swift_dynamicCastClassUnconditional + 80
View original.js
new MyReadStream().pipe(new MyDuplex()).pipe(new MyTransform()).pipe(new MyWriteStream())
var Class = {
propTypes: {
field: React.PropTypes.oneOfType([

I did some poking around CodeMirror and how it works, particularly with it's current code folding implementation. My goal was to see if there was a way to only have part of the string in memory, render those parts, and still have line numbers be correct. My goal was to have the editor display something like this:

3  function() {
27 }
You can’t perform that action at this time.