Skip to content

Instantly share code, notes, and snippets.

View abstractmachines's full-sized avatar
🤸

Amanda Falke abstractmachines

🤸
View GitHub Profile
@abstractmachines
abstractmachines / transducers.js
Created October 9, 2017 19:08
JS transducers
/** Implementing transformations (like map and filter) with reducers. **/
// https://www.webpackbin.com/bins/-Kvmn0gWkIMmtnFnkcu_
// https://medium.com/@roman01la/understanding-transducers-in-javascript-3500d3bd9624
// take all evens, multiply by 2, log that.
const arr = ['1', '2', '3', '4', '5', '6']
console.log('Chaining map and filter.')
@abstractmachines
abstractmachines / promiseunderthehood.js
Created October 26, 2017 22:08
Dave's pwomise. Remember that the catch is not implemented correctly, recall the tree structure of Promise.
class Pwomise {
constructor (fn) {
fn(this._resolve.bind(this), this._reject.bind(this))
this._thens = []
this._catches = []
}
_resolve (value) {
while (this._thens.length > 0) {
this._thens.pop()(value)
@abstractmachines
abstractmachines / iterator-string-for-of-spread.js
Last active November 2, 2017 23:15
JavaScript Iterators: Strings, spread, and for of
/* JavaScript Iterators
Strings as data source; for of and spread operator as data consumers
Strings can be consumed as iterables using the spread operator.
Note that strings will be parsed according to code points, not by character,
and so num characters parsed will be somewhat nondeterministic.
Sources:
1 - Axel Rauschmeyer: http://exploringjs.com/es6/ch_iteration.html
2 - http://www.zsoltnagy.eu/es6-iterators-and-generators-in-practice/
@abstractmachines
abstractmachines / Symbol.hasinstance.js
Last active February 23, 2018 23:09
Well Known Symbols : instanceof via custom Symbol.hasinstance
/* Well Known Symbols : Symbol.hasinstance
sources:
1 - https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols/
2 - http://exploringjs.com/es6/ch_symbols.html
3 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
4 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance
Well Known Symbols are Reflection via implementation in ES6.
Reflection in Metaprogramming: observing low level internals of a programming language/program.
@abstractmachines
abstractmachines / arrayiterator.js
Last active July 5, 2018 19:10
JavaScript Iterators : Arrays
/* JavaScript Iterators
An Iterator Object is a data structure that has a .next() method that can be called repeatedly.
Iterators use the Well Known Symbol called Symbol.iterator.
(The Iterable Object has an Iterator pointer for indexing.)
The Iterator object has two properties, value and done (boolean). Iteration will continue so
long as done is falsey. Once done is truthy, iteration stops.
Just like C++ iterators for C++ data structures, JavaScript iterators iterate through an entire
@abstractmachines
abstractmachines / set-map-iterator.js
Last active July 5, 2018 19:17
JavaScript Iterators: Sets and Maps
/* JavaScript Iterators
Sets and Maps
Sets and Maps can be made Iterable/Iterator by using the methods .entries(), .keys(),
values(), and/or via for of construct.
A Set is a unique (non repeated) version of a Bag data structure. Characteristic equation
is contains() or has().
A Map (in JS) is a key-value pair data structure, unordered (in order of insertion).
@abstractmachines
abstractmachines / proptypes-static-default-more.md
Last active March 22, 2020 21:01
React for C/C++ developers: PropTypes (Static, default, and more)

React PropTypes: Static, Default, and what it all means

You may have seen a couple of different ways to handle React PropTypes.

  • You've seen declarations of propTypes/PropTypes including "static proptypes" and "default proptypes."
  • You've seen declarations of propTypes/PropTypes inside or outside of the class.

Default PropTypes

  • These set a default value for PropTypes.
  • Recall also that you can simply use initialization in the component itself (in the inherent little "constructor" that React functional components tend to have, e.g.
@abstractmachines
abstractmachines / upgrade-repo-to-sagas.js
Last active March 22, 2020 21:15
Repo upgrading: Dummy sagas + test w/ thunks
/* To upgrade a repo from using only thunks, to using sagas and thunks,
1. Create a dummy saga
2. Add in Saga middleware to store configuration, and start/run sagas from store config
3. Test sagas (generators with generator.next() { value: someValue, done: false } until { ... done: true }
4. Since thunks and sagas can live together in the same repo, you can now move forward with handling async side effects
with new code by using sagas (and being able to test them), and slowly migrate your legacy thunks over to sagas over time.
*/
// 1. rootSaga.js
@abstractmachines
abstractmachines / the-base-is-the-place-understanding-radix.md
Last active June 17, 2020 18:28
The Base Is The Place: A tutorial on radix for students of systems engineering

WIP

The Base Is The Place: Understanding Radix

How to understand radix: A tutorial for students of systems engineering

Radix : Number of unique digits that exists in a system.

Binary "base 2" : the number 2 is 0010

Note the binary number 0010. Binary is read RTL or right-to-left.

@abstractmachines
abstractmachines / git-workshop.md
Last active August 3, 2020 17:39
git workshop

git Workshop

Motivation for this workshop

The majority of blogs and documentation about git are one of two things:

  1. technically correct while being very difficult for newbies to digest,

OR

  1. technically incorrect "guides" which help people learn, but miss many CS fundamentals and details and/or advise learners to "avoid/ignore" "advanced" features which software engineers use daily on the job.