Skip to content

Instantly share code, notes, and snippets.

View phenomnomnominal's full-sized avatar
🥑
Hangry

Craig Spence phenomnomnominal

🥑
Hangry
View GitHub Profile
@phenomnomnominal
phenomnomnominal / index.js
Last active January 20, 2021 01:18
workerRequire example
// BEFORE:
const { somethingCPUIntensive } = require('./cpu-intensive');
somethingCPUIntensive(); // run synchronously blocking the main thread
// AFTER:
const { somethingCPUIntensive } = workerRequire('./cpu-intensive');
await somethingCPUIntensive(); // run asynchronously in a worker thread
@phenomnomnominal
phenomnomnominal / index.js
Last active January 22, 2021 21:15
workerRequire!
import callsite from 'callsite';
import { releaseProxy, wrap } from 'comlink';
import nodeEndpoint from 'comlink/dist/umd/node-adapter';
import path from 'path';
import { Worker } from 'worker_threads';
const WORKER_PATH = path.resolve(__dirname, './worker.js');
export function workerRequire(id) {
const [, call] = callsite();
@phenomnomnominal
phenomnomnominal / ParseDate.ts
Created October 3, 2020 23:22
TypeScript Template Types Date Validator
// Check it out here:
https://www.typescriptlang.org/play?ts=4.1.0-dev.20201001#code/C4TwDgpgBAcgrgWwEYQE4GcoF4oHIAMuUAPngIxGm4BMleAzHbgCxMCsTAbEwOxMAcTAJy4A3AChQkWAHsAdgC00M7FACiADwDGAGzgATCAB54yNOgA0eQgD4Jk8NACaEAIapVAAwAkAb1MoGAC+fgHmIf6IgegRYcGeElLQALLywAAWmDie+KHySqgyQZ4k5ISluGQUFWS0iY5QACKuIFlQPr4ETNVUtLH5ysUV9OVU9BT2SVAAEjJwGF65kWbxpZ5koVHhJb2jeNQ9+7QV1IwnrPXSCvIQs-NtMAOFa0uPioM7Zd2HlbQO0skAJZyODACBtDpdGpMY5jJisCocWJbeKXaAAZQgWnk+jaQJBYPQaKgQJ0OkB6CxOIhmxWMVp0WRdOKkwa1zkEAACqgIAAzQEaVS4ADUTAAtGJxP9oM0wZz3JS1KhCqgjMlwehXABzaAQDRguS4qDoYCoYFamyqXxQNAqgBcJI12ugQVZ0llEAAKoCEMZxFAA1BPTb9RBDZgTWa5FrxJacP7A8G9QajR1gby0E1XGDvb6ggo-OnM+yIEMAPxQBOBwPyjAQD25iAlowNn0QKwly12qtBkMpzBpuQZjwe8s96u1ymt32PZseruV6seycQJUqoyeacQB0ASTkADdXOT9Fmc22HX5PcU7FKpiut82e1v0aa+2GjZHzRYeyWXx5k++Eaml+PYrvoW6qPe2Zem2s43C20GNn+NjfhOCoQPoJaQehza-qaNixthdbgYhbZvuGp4wb6f5QGW441uhmE3ORRp4R4dHVpxgYdGBW75n4YElkM3ZcQGgnMSJDHEVubrQFBZ4zjIj5LqRilsSxQFRjGcaLoGW5wRyNEARRg7DpRQSeoWQ6Zo25a6Vx8lUcYHpWI2XZPqpEAGRARmhiZVlmaOJQcaJjkIWCC4eXK6FrjIqqeI5jb
// Check it out here:
// https://www.typescriptlang.org/play?ts=4.1.0-dev.20201001#code/C4TwDgpgBAMg9gdwgJwMYEMDOECCAbMAC3SgF4oBydCqAH0oCMb6LVnKATdiibgM24BzboW4BLbgCtuAa255uAW24A7bnG5huAR27JumbsG4BXbgDduCbgA9uIbgC8KAbgBQoSFACqYSGixcAmIyKABhdDAxYHQ8MUcIAB54JADsfCJ0AD53T2gM4gYIYFCUlAx04JJ6X38KoMzc8GgAORNFIuRMUIoABm4ARm4AJm4AZm4AFm4AVm4ANm4Adm4ADm4ATlcPZqgAZRAOuDxu8goAWm4AfQodrwBJDggVYDE+MRRTqAL0IpL6NodFB0faHBjHTBNLwAdUI0QgmDA6FQ0DOlBBFAAOmoMZjjLiBLi1FDoABFExwYAI0IAIgoNIxdJJUAAKsh0OZPrEegAabhZbiJbgAP24AGptnkoI8egBiSW7MJ4LBfCgAOgVXm8KjEnK63LOACpblKAKIAeQAYj1NdBLWIdZhCBAODbmThgMBkGIGCYqebICoegBtW3fT3e31UpVwbA9AC6YY9Xp9fogEWwqtFGIAetwACTcY0YgCE3FoYdN2hMBsopCTEdTVK+ycjaYDzxBrab6bwseg9G7UfTgW69CrNbwzLCxC6oUez1e70+INh8MRyIHUHJlOp9DZHK5eBBMvoSpVIO1uqPIIt1sHjeHkLcd2gMAgNlNyGQcGQiQAsgimDoII0AflSKgcN0mApioghZKEADeUCKEBIEQAAXFAgGYMBoFQAAvu4r6sugMhBHgiRuFANFQAAalA4HPFBUAwd6cE8tRtEzugXRuAh5BcTRDFMZB3QAAb5ohDp8MCYQEVJMnAgASgR4lQAA-FAQm0TRYSMTYEEsTxc5aTpum6SyZEUYkyk8uEs6YAhWHmbRDEYTpdHEVKVnkdqryUZ5BlGdBsGCJxukmd0oksWxDqCPxoRBT
async function setLotsOfReminders(name, reminder, times) {
await Promise.all(Array.from({ length: times }, (_, i) => i + 1).reduce(async (p, days) => {
await p;
document.querySelector('[role="textbox"]').innerHTML = `remind @${name} to ${reminder} in ${days} days at 4am`;
return new Promise(resolve => {
setTimeout(() => {
document.querySelector('button[aria-label="Send message"]').click();
setTimeout(resolve, 1000);
}, 1000);
});
@phenomnomnominal
phenomnomnominal / stylelint-betterer.ts
Created May 16, 2020 14:12
Betterer test for StyleLint errors
import { BettererFileTest, BettererFileIssuesMapRaw } from '@betterer/betterer';
import * as stack from 'callsite';
import { promises as fs } from 'fs';
import * as glob from 'glob';
import LinesAndColumns from 'lines-and-columns';
import * as minimatch from 'minimatch';
import * as path from 'path';
import { lint } from 'stylelint';
import { promisify } from 'util';
type Freezable = {
unfreezable?: never; // Need to make the unfreezable property optional
};
type Frozen<T extends Freezable = Freezable> = T & {
frozen: true;
};
type Thawed<T> = T extends Frozen<infer R>
? R
<youtube-player
videoId="dQw4w9WgXcQ"
suggestedQuality="highres"
[height]="600"
[width]="1080"
[startSeconds]="43"
[endSeconds]="60">
</youtube-player>
import { Component, OnInit } from '@angular/core';
@Component({
template: '<youtube-player videoId="dQw4w9WgXcQ"></youtube-player>',
selector: 'app-video'
})
export class VideoComponent implements OnInit {
ngOnInit() {
const tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
import { NgModule } from '@angular/core';
import { YouTubePlayerModule } from '@angular/youtube-player';
import { VideoComponent } from './video.component';
@NgModule({
imports: [YouTubePlayerModule],
declarations: [VideoComponent],
exports: [VideoComponent]
})