Skip to content

Instantly share code, notes, and snippets.

View swyxio's full-sized avatar
🎯
Focusing

swyx.io swyxio

🎯
Focusing
View GitHub Profile
@swyxio
swyxio / 0_reuse_code.js
Created November 10, 2016 20:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@swyxio
swyxio / fsa-cs-saturday-compilers.js
Last active July 30, 2017 06:16
this is a javascript calculator compiler built for the calculators class. to evaluate, create a new `Calculator` with a mathematical expression and it will parse the tree with `parseExpression()`. Then pass a `Visitor` (we have 3 options) to `tree.accept` to get either polish notation, original notation, or evaluated result. Scroll down to the b…
function Calculator(inputString){
this.tokenStream = this.lexer(inputString);
console.log(this.tokenStream);
}
Calculator.prototype.peek = function () {
return this.tokenStream[0] || null;
};
@swyxio
swyxio / flexbox-cheat-sheet.md
Last active January 19, 2023 07:35
cheat sheet from flexbox.io
@swyxio
swyxio / text.md
Last active September 5, 2017 20:30
the precedence order of `this`

Precedence

In many card games, there are certain cards or combinations of cards that "beat" or "trump" others. For example, in poker, a straight beats a three of a kind, and a three of a kind beats a two of a kind. Likewise, in the case of ties between two similar hands, an Ace will beat a King, and so on and so forth.

Precedence in programming languages is just like this. In regards to this context, we know quite a couple different ways that this context can be set - first there's the normal way (set dynamically as method on an object), then there's the new keyword, then also call, apply and bind, and now arrow functions. But what happens if these different methods collide? For example:

fig 1

const Dog = (name, breed) => {
@swyxio
swyxio / install-webpack-from-scratch.md
Last active May 28, 2019 15:32
install-webpack-from-scratch.md

my notes ripped shamelessly from https://webpack.academy

  1. add webpack yarn add webpack --dev. this adds to devDependencies
  2. add {"build": "webpack"} under scripts to package.json. optionally:
  • "watch": "webpack --watch",
  • "start:dev": "webpack -w & nodemon server/app.js",
  • "build-watch": "npm run build -- -w",
  • "start-watch": "nodemon server/start.js --watch server --watch db --watch index.js --watch package.json",
  • "start-dev": "cross-env NODE_ENV=development npm run start-watch",
@swyxio
swyxio / timediff.js
Created October 12, 2017 09:18
time difference in words
function timeDifference(current, previous) {
const milliSecondsPerMinute = 60 * 1000
const milliSecondsPerHour = milliSecondsPerMinute * 60
const milliSecondsPerDay = milliSecondsPerHour * 24
const milliSecondsPerMonth = milliSecondsPerDay * 30
const milliSecondsPerYear = milliSecondsPerDay * 365
const elapsed = current - previous
@swyxio
swyxio / .block
Created January 26, 2018 06:04
Film Flowers, Single Complete
license: gpl-3.0
@swyxio
swyxio / .block
Last active January 26, 2018 09:20
Film Flowers Petal Starter Code
license: gpl-3.0
@swyxio
swyxio / .block
Last active January 26, 2018 09:20
Film Flowers, Single Starter Code
license: gpl-3.0
@swyxio
swyxio / gist:41a401f5a8feceba97d559ac2679f459
Created March 25, 2018 20:06
React Rally Talk Proposal: React Mind, Beginner's Mind