Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

swyx sw-yx

🎯
Focusing
View GitHub Profile
@sw-yx
sw-yx / 0_reuse_code.js
Created Nov 10, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sw-yx
sw-yx / fsa-cs-saturday-compilers.js
Last active Jul 30, 2017
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…
View fsa-cs-saturday-compilers.js
function Calculator(inputString){
this.tokenStream = this.lexer(inputString);
console.log(this.tokenStream);
}
Calculator.prototype.peek = function () {
return this.tokenStream[0] || null;
};
@sw-yx
sw-yx / flexbox-cheat-sheet.md
Last active Feb 15, 2020
cheat sheet from flexbox.io
View flexbox-cheat-sheet.md
@sw-yx
sw-yx / text.md
Last active Sep 5, 2017
the precedence order of `this`
View text.md

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) => {
@sw-yx
sw-yx / install-webpack-from-scratch.md
Last active May 28, 2019
install-webpack-from-scratch.md
View 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",
@sw-yx
sw-yx / timediff.js
Created Oct 12, 2017
time difference in words
View timediff.js
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
@sw-yx
sw-yx / .block
Created Jan 26, 2018
Film Flowers, Single Complete
View .block
license: gpl-3.0
@sw-yx
sw-yx / .block
Last active Jan 26, 2018
Film Flowers Petal Starter Code
View .block
license: gpl-3.0
@sw-yx
sw-yx / .block
Last active Jan 26, 2018
Film Flowers, Single Starter Code
View .block
license: gpl-3.0
@sw-yx
sw-yx / gist:41a401f5a8feceba97d559ac2679f459
Created Mar 25, 2018
React Rally Talk Proposal: React Mind, Beginner's Mind
View gist:41a401f5a8feceba97d559ac2679f459