Skip to content

Instantly share code, notes, and snippets.

View snewcomer's full-sized avatar

Scott Newcomer snewcomer

View GitHub Profile
// Code from: http://patshaughnessy.net/2020/1/20/downloading-100000-files-using-async-rust
//
// Cargo.toml:
// [dependencies]
// tokio = { version = "0.2", features = ["full"] }
// reqwest = { version = "0.10", features = ["json"] }
// futures = "0.3"
use std::io::prelude::*;
use std::fs::File;
@snewcomer
snewcomer / fastboot-runtime-test.js
Created December 23, 2020 15:56
Ember FastBoot runtime test
/* eslint-env node */
/**
* This can be run as an npm script a part of your CI testing
*
* This is a "smoke test" to make sure that the application, when run
* within FastBoot, isn't calling APIs that aren't supported by the
* Node.js environment. (e.g. window.alert)
*/
@snewcomer
snewcomer / gist:589bcf6361e0ddf9d0f564c7042c6f87
Last active October 30, 2020 03:38
ember-unit-testing-components.js
// test helper
import { getContext } from '@ember/test-helpers';
export default function createComponent(lookupPath, named = {}) {
let { owner } = getContext();
let componentManager = owner.lookup('component-manager:glimmer');
let { class: componentClass } = owner.factoryFor(lookupPath);
return componentManager.createComponent(componentClass, { named });
}
@snewcomer
snewcomer / cli-fastboot-proposal
Created October 2, 2020 03:59
ember-cli-fastboot proposal
## Architecture
A possible future design of ember-cli-fastboot which achieves the goal of "production ready."
### General Design
ember-cli-fastboot combines a couple of critical components for a user's experience in development and production.
1. **Production** - fastboot service, utils to add to and clear the shoebox, and managing the HTML on handoff to the client.
2. **Development** - an express server that instantiates a FastBoot instance, plugs the FastBoot middleware into the pipeline, reload capabilities and build time utilities.
@snewcomer
snewcomer / ember-fastboot-architecture
Created September 25, 2020 20:24
Proposal: Ember FastBoot App Server architecture
## General Design
- Cluster management.
- Being aware of distribution changes and downloading of new assets.
- Delegation of responsibilities between three separate primary objects:
- Cluster Master
- Cluster Workers
- Express HTTP Server
## Constituent Components
@snewcomer
snewcomer / promise-timer.js
Created April 19, 2020 20:44
Promise timer
let counter = 0;
class MyPromise extends Promise {
constructor(cb) {
const stack = (() => { try { throw new Error(); } catch (e) { return e; } })().stack;
const id = `promise ${counter++}`;
console.time(id);
super(function(resolve, reject) {
const createDataTree = dataset => {
let hashTable = Object.create(null);
dataset.forEach(aData => {
return (hashTable[aData.id] = { ...aData, childNodes: [] });
});
let dataTree = [];
dataset.forEach(aData => {
if (aData.parentId) {
hashTable[aData.parentId].childNodes.push(hashTable[aData.id]);
} else {
@snewcomer
snewcomer / exponential.js
Created April 16, 2020 17:25
exponential-backoff
function createScheduler({
callback,
time,
callbackTimeout,
backoffMultiplier = 1.5,
backoffMaxTime = 20000
}) {
let run;
let timeoutId;
let ticker;
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class extends Component {
get handleStyles() {
const fraction = (this.args.currentValue / this.args.max) * 100;
return `left: ${fraction}%`;
}
@action
const getBooleanTable = number => Array(Math.pow(2, number))
.fill()
.map((_, idx) => idx)
.map(num => num.toString(2).padStart(number, '0'))
.map(stringOfBits =>
stringOfBits.split('').map(bit => Boolean(parseInt(bit)))
)
console.log(getBooleanTable(3))