Skip to content

Instantly share code, notes, and snippets.

View hitsthings's full-sized avatar
🐳
failin'

Adam Ahmed hitsthings

🐳
failin'
View GitHub Profile
@hitsthings
hitsthings / description.md
Created December 3, 2019 07:20
Async iterators, generators, and try-finally

Turns out JS can throw an error on a line like return 42;

generator - loops forever sleeping 1s at a time, and when you try to stop it, it waits 1s and then throws an error.

iteration - calls generator via a for-await and attempts to return within the iteration. This forces iteration to wait for generators finally section to run which includes a 1s await!

@hitsthings
hitsthings / keybase.md
Created September 16, 2019 01:10
keybase.md

Keybase proof

I hereby claim:

  • I am hitsthings on github.
  • I am hitsthings (https://keybase.io/hitsthings) on keybase.
  • I have a public key ASBWdlHf_rABh8nhnp5p1MPIUZ-vmbBgj11PEhgkLeHu7Ao

To claim this, I am signing this object:

@hitsthings
hitsthings / some.js
Last active September 1, 2018 10:34
Logic outside of React
// -- bit excessive for this case, but the example isn't realistic in the first place
export const probability = () => Math.random();
// -- some other file
export const diceRoll = () => Math.ceil(probability() * 6);
// -- some other file
export const coinFlip = () => probability() > 0.5 ? 'heads': 'tails';
// -- shared state can be stored however you like (this is just one example)
var toArray = Function.prototype.call.bind(Array.prototype.slice);
function partial(fn/*, ...args*/) {
var args = [].slice.call(arguments, 1);
return function() {
var lastArgs = toArray(arguments);
return fn.apply(this, args.concat(lastArgs));
};
}
Copyright (c) <year>, <copyright holder>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.