Skip to content

Instantly share code, notes, and snippets.

View lxynox's full-sized avatar
🌴
On vacation

⦇⦀∙ˇ∎ˇ∙⦀⦈ lxynox

🌴
On vacation
View GitHub Profile
@lxynox
lxynox / babel-webpack.md
Created March 26, 2020 07:56 — forked from ncochard/babel-webpack.md
The correct way to compile ES6 using babel...

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.
@lxynox
lxynox / sequencing-promises.md
Created September 24, 2019 03:03
Resolve promises one after another (i.e. in sequence)

asycn/await

async function readFiles(files) {
  for(const file of files) {
    await readFile(file);
  }
};

yield

@lxynox
lxynox / test-local-module.md
Last active November 19, 2019 14:45
Various ways to test a local module before publishing

Always starts from changing node_modules/ directly, for more complex use cases

🔰🔰🔰

npm link

/path/to/lib $ npm link
/path/to/app $ npm link lib
@lxynox
lxynox / mobx-state-tree.md
Last active May 29, 2020 04:10
Front-end (react) state management solutions

mobx-state-tree is a state container that combines the simplicity and ease of mutable data with the traceability of immutable data and the reactiveness and performance of observable data.

How???

feature/
  state/
 - index.js

Why statelessness

visibility

Every request contains all context necessary to understand it. Therefore, looking at a single request is sufficient to visualize the interaction.

reliability

Since a request stands on its own, failure of one request does not influence others.

Proxy

First of all, the word "proxy" describes someone or something acting on behalf of someone else.

In the computer realm, we are talking about one server acting on the behalf of another computer.

Forward proxy

Acting on behalf of client (browser)

forward proxy

@lxynox
lxynox / WebSockets.md
Created June 29, 2019 21:12 — forked from subudeepak/WebSockets.md
The problems and some security implications of websockets - Cross-site WebSockets Scripting (XSWS)

WebSockets - An Introduction

WebSockets is a modern HTML5 standard which makes communication between client and server a lot more simpler than ever. We are all familiar with the technology of sockets. Sockets have been fundamental to network communication for a long time but usually the communication over the browser has been restricted. The general restrictions

  • The server used to have a permanent listener while the client (aka browser) was not designated any fixed listener for a more long term connection. Hence, every communication was restricted to the client demanding and the server responding.
  • This meant that unless the client requested for a particular resource, the server was unable to push such a resource to the client.
  • This was detrimental since the client is then forced to check with the server at regular intervals. This meant a lot of libraries focused on optimizing asynchronous calls and identifying the response of asynchronous calls. Notably t
@lxynox
lxynox / cancellable-promise.md
Last active June 23, 2019 00:26
make promise cancellable in react

Problem

  • setState is called on unmounted component
  • race conditions among multiple in-flight requests (responses come back out of order)

Solution

Make the promise cancellable

@lxynox
lxynox / express.md
Last active June 22, 2019 09:00
Routers, middlewares etc

Middlewares

api: [app/router].use

Express middleware dataflow

Scope/Hierarchy of middlewares

  • Application-level middleware
  • Router-level middleware
@lxynox
lxynox / package[-lock].json.md
Last active June 23, 2019 05:42
package.json vs package-lock.json

package.json

"files" vs .npmignore

files - whitelisting all files that should be included in a npm release

.npmignore - blacklisting all files that should be included in a npm release

package-lock.json