Skip to content

Instantly share code, notes, and snippets.

@maxholman
maxholman / LICENSE.md
Last active September 7, 2022 17:38
Simple CORS for Express

Copyright 2022 Block65 Pte Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

@maxholman
maxholman / README.md
Last active June 19, 2021 11:30
jscodeshift/codemod to add .js extensions to relative module specifiers

Description

jscodeshift/codemod transform to add .js extensions to relative module specifiers

Uses Nodes module resolution algorithm so it can handle import './example' -> import './example/index.js'

Usage

For Typescript files

@maxholman
maxholman / async-generator-url.ts
Last active November 27, 2022 06:56
Recursive readdir typescript
import { readdir, stat } from 'node:fs/promises';
async function* recursiveReaddir(dir: URL): AsyncGenerator<URL> {
for await (const file of await readdir(dir)) {
const path = new URL(file, `${dir}/`);
const x = await stat(path);
if (x.isDirectory()) {
yield* recursiveReaddir(path);
} else {
yield path;

Keybase proof

I hereby claim:

  • I am maxholman on github.
  • I am maxholman (https://keybase.io/maxholman) on keybase.
  • I have a public key ASAka7eqrk-zIA177YjM8ut6qJvpGGjDVT-D95jasneDnwo

To claim this, I am signing this object:

@maxholman
maxholman / snoitca.js
Last active March 8, 2018 05:39
Hyperapp HOA that changes the wired action signature from data => (state, actions) => result to (state, actions) => data => result
interface WiredActions<S> {
[key: string]: (...args: any[]) => S | WiredActions<S>;
}
type GenericState = any;
type Actions = HyperAppActions<GenericState, WiredActions<GenericState>>;
function rewriteActions(actions: Actions): Actions {
return Object.entries(actions).reduce((accum, [name, action]) => {
interface WiredActions<S> {
[key: string]: (...args: any[]) => S | WiredActions<S>;
}
type GenericState = any;
type Actions = HyperAppActions<GenericState, WiredActions<GenericState>>;
function rewriteActions(actions: Actions): Actions {
return Object.entries(actions).reduce((accum, [name, action]) => {
@maxholman
maxholman / mkimage.sh
Last active August 29, 2015 14:03
Create a CentOS image for docker
#!/usr/bin/env bash
#
# Create a base CentOS Docker image.
#
# Original: https://github.com/dotcloud/docker/blob/master/contrib/mkimage-rinse.sh
# Added tweaks from: https://github.com/dotcloud/docker/blob/master/contrib/mkimage-rinse.sh
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1