Skip to content

Instantly share code, notes, and snippets.

View lukeed's full-sized avatar

Luke Edwards lukeed

View GitHub Profile
@lukeed
lukeed / cron-human.ts
Last active May 7, 2023 18:53
cron syntax & human readable output — https://t.co/CBThaezwzC
// https://crontab.guru/
// https://www.typescriptlang.org/play?ts=4.9.5#code/C4TwDgpgBAwgSgeQHJQLxQAYBIDe9kB0AogB5gBOEAzlQJYD2AdgL5S75LFmU0Mtt5EnUhWp0mrdkK6jeEgRxk9xLDAG4AUAHotUPVAB6Afg0bQkKABVqwAIxpY0gBIBXALYBDRgB4ARAGYABigATigAKgiI3wA+TR19QxMzcGhrKmAAJgdFV08fX0iwyJLY+N19Y1NzNJt-HOd3Lz9wrXriqPCy7Qq9KpSLdOAAFgbCPObCtoitUZLouJ7E-pqrGwBWMc4Jgtb6+dLFhMrk1aGANi2CHZaZ-c7u477T1LWMgHYrm99bTdbsg6PXpJaqvIYADi+TV2UXuXSOwJWYJsYXQuWhtxK00O5WWL0GNlswTRjXymKg+y0AKBeNBBIytnsJPGGMKsJm2WGNJOdNqDOyzO2rOCmUpAOxs25z15bzs9UF11ZYVFHLuUC5CNpAz5dlGCu+rV+M0ukX2UpB2tlRv1rIOFIWuJ5SwAtK6AMYuYCu52mAAmEDdABsPJQoIwPG5qGAPG7oBwoDgNHoIGR6ORgFBViJlHwHABycJ5qAAHzD7gARhByCXMK1cIwK1XmOpTMnU+nM68bpYoCngBBGL6qI5kDEHEnElZeyR+4Ph9gcLRGAAzKtQACykkXK7XTi3S9X1YAIpuBAe1+vT7hz8eAOrNieTqBGKy0SPeJwAGnXY77A6HmDXju1Y9n+c5QBk5BLgA5g+T6JC+R4eCA3iXp+UAnuhR63r+M7-vOQGHhh06zgBkEwXB8EIcRYEAb4vhQI+VH6C+lhMcxUAAFyATglisEwAhHpRHHcYwEAAG5Vuxk6iRJUlUbJknkJoE4JN6jETmcb4QB+9AuOQ6HrkunoQGO6BMUZDb9iR+FQAWRbSS+Th6dWtHDvZegvnmcnkCAUBuMZ-ZFgk8wAPpQOFoXSdxzn6TZ4ELjeUBOPFAENm4
@lukeed
lukeed / worktop.cache-kv.ts
Last active May 13, 2021 20:07
Demo showing how to integrate with the Cache API and then use custom KV lookup mechanics
import { Router } from 'worktop';
import * as Cache from 'worktop/cache';
import { read, write } from 'worktop/kv';
import type { Method } from 'worktop/request';
import type { Handler } from 'worktop';
import type { KV } from 'worktop/kv';
// KV Namespace Binding
declare const SAVED: KV.Namespace;
@lukeed
lukeed / astray-references.js
Created July 1, 2020 06:09
how to traverse an AST with astray and collect identifier sources + references
import * as astray from 'astray';
import { parse } from 'meriyah';
const AST = parse(`
var intro = greeting();
function greeting() {
return 'Hello world!';
}
@lukeed
lukeed / componenets-App-index.js
Last active April 7, 2020 18:46
PWA w/ styled-componets extracting CSS
import React from 'react';
import { HMR } from '@pwa/preset-react';
import Button from '@components/Button';
import style from './index.css';
class App extends React.Component {
render() {
return (
<div className={ style.app }>
<main className={ style.wrapper }>
// stick this somewhere in your local @types/** files
interface NetworkInformation extends EventTarget {
readonly downlink: number;
readonly downlinkMax?: number;
readonly effectiveType: 'slow-2g' | '2g' | '3g' | '4g';
readonly rtt: number;
readonly saveData: boolean;
readonly type: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';
onchange: EventListener;
@lukeed
lukeed / polka.next.d.ts
Last active March 6, 2021 07:28
TypeScript definitions for `polka@next` – These will be made available as "@types/polka" when 1.0 is ready!
declare module 'polka' {
import { Server } from 'net';
import { IncomingMessage, ServerResponse } from 'http';
import Trouter from 'trouter';
export interface IError extends Error {
message: string;
code?: number;
stack?: string;
status?: number;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Perflink | JS Benchmarks</title>
<meta
name="description"
content="JavaScript performance benchmarks that you can share via URL."
/>
<meta
@lukeed
lukeed / micro.js
Created January 12, 2018 09:15
Polka vs Micro vs Native
const micro = require('micro');
micro((req, res) => {
if (req.url === '/') {
return 'Hello';
}
if (req.url.indexOf('/user/') === 0) {
// cheating, but ok
return `Hello user ${req.url.substring(6)}`;
}
@lukeed
lukeed / cached-loops.js
Created July 10, 2017 06:49
cached vs non-cached perf
const LOOPS = 1e6;
const LEN = 1e3;
function test(fn) {
let i = 0;
const data = new Array(LEN);
const start = Date.now();
for (; i < LOOPS; i++) {
fn(data);
}
@lukeed
lukeed / OSX-Dock-Spacers.md
Last active November 12, 2021 20:51
OSX Dock Spacers

Huh?

Some MacOS users have very cluttered Docks & wish they could organize them without removing any App icons from the mix.

This snippet will add an empty "spacer" that you can drag around and use to separate icons into groups! See example.

Command

Paste this into your Terminal. Run the command for additional placeholders!