Skip to content

Instantly share code, notes, and snippets.

View martypdx's full-sized avatar

Marty Nelson martypdx

  • martypdx, llc
  • Portland, OR
View GitHub Profile
@martypdx
martypdx / README.md
Last active December 17, 2021 17:19
AoT Template Extraction

AoT Template Extraction

Rather than creating DOM nodes in JavaScript, an AoT system can extract the html, deliver as html, and then only need reference the relevant DOM nodes in JavaScript. This has a number of performance benefits:

  1. It takes advantage of fast parsing of html by the browser and avoids the additional JavaScript bundle size and parsing tax.
  2. Only elements involved in binding need to be managed or even referenced
  3. Faster mechanisms like cloneNode can be used to produce cheaper copies
  4. Like html templates can be consolidated

Based on the current Svelte 3.0 output, it seems well poised to take advantage of this.

@martypdx
martypdx / R&D 01.md
Last active February 24, 2019 22:11
Reference & Documentation
@martypdx
martypdx / Alchemy.md
Last active November 29, 2018 20:41
Pitch

TAM

  • Current ~500K open developer jobs
  • By 2020 likely to be 1.5M
  • CS Grads ~50k/yr
  • Code Schools ~20k/yr

Our Traction

@martypdx
martypdx / mongoose-array-validation.test.js
Last active July 19, 2018 16:53
Tests showing that objects in arrays are not all validated when one fails
const assert = require('assert');
const mongoose = require('mongoose');
const RequiredString = { type: String, required: true };
const schema = new mongoose.Schema({
name: RequiredString,
type: RequiredString,
colors: [{
name: RequiredString,
@martypdx
martypdx / respond.js
Created November 12, 2017 17:38
A helper function for promise returning express middleware
// Assumes:
// 1. application/json response content type
// 2. registered error handler capable of handling rejections
module.exports = function respond(handler) {
return async (req, res, next) => {
try {
const result = await handler(req);
res.json(result);
}
catch(err) {
@martypdx
martypdx / mjs.sh
Last active October 16, 2021 09:02
# rename all .js to .mjs
for f in **/*.js; do mv -- "$f" "${f%.js}.mjs"; done
# add .mjs to all file-based import statements*
find . -type f -name "*.mjs" -exec sed -i '' -E "s/(import.+'\.[a-zA-Z0-9\.\/-]+)';/\1\.mjs';/g" {} \;
# *NOTES:
# 1. This will double up existing .mjs extension in imports.
# Couldn't get phrase negation working in this sed substitution regex :(
#

control flow

  • if, else, while, for, do

functions

closures

var a = 'foo';
function b(){

control flow

  • if, else, while, for, do

functions

closures

```js
var a = 'foo';
function b(){

return a;

control flow

  • if, else, while, for, do

functions

closures

```js
var a = 'foo';
function b(){

return a;

control flow

  • if, else, while, for, do

functions

closures

```js
var a = 'foo';
function b(){

return a;