Skip to content

Instantly share code, notes, and snippets.

@jrson83
jrson83 / update-config.js
Created February 6, 2023 21:47 — forked from jbreckmckye/update-config.js
Beanstalk / general-purpose JSON mass updater
const fs = require('fs');
const cliArgs = process.argv.slice(2);
const key = cliArgs[0];
const val = cliArgs[1];
function parseJSON(string) {
const sanitised = string.replace(/\s\$\w*/g, substr => `"__SANITISED__${substr}"`);
return JSON.parse(sanitised);
}
// Adapted from https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_transpiler_loader
import { readFileSync, writeFileSync } from 'fs'
import { dirname } from 'path'
import { URL, pathToFileURL, fileURLToPath } from 'url'
import esbuild from 'esbuild'
const baseURL = pathToFileURL(`${process.cwd()}/`).href
const tsExtensionRegex = /\.(tsx?)$/
function readJSON(path) {
@jrson83
jrson83 / action.test.ts
Created February 11, 2023 22:28
github-action-test
import { RunOptions, RunTarget } from 'github-action-ts-run-api'
import assert from 'node:assert'
import fs from 'node:fs'
import http from 'node:http'
async function runTest() {
const port = 8234
const server = http
.createServer((req, res) => {
if (req.url === '/repos/owner/repo') {
@jrson83
jrson83 / glob.ts
Created March 1, 2023 02:02 — forked from jonathantneal/glob.ts
Return a list of files, like import.meta.glob in Vite, without calling the files.
import glob from 'fast-glob'
import nodeURL from 'url'
import process from 'process'
/** Returns pathnames matching the given pattern. */
const sync = (source: string) => glob.sync(source, options()) as string[]
/** Returns pathnames matching the given pattern. */
const async = (source: string) => glob(source, options()) as Promise<string[]>
@jrson83
jrson83 / deep-merge.ts
Created March 2, 2023 23:16 — forked from havenchyk/deep-merge.ts
deep merge
function isPlainObject(item: unknown): item is Record<string, unknown> {
return item && (item as object).constructor === Object
}
function filterProto([key, value]: [string, unknown]) {
// Avoid prototype pollution
return key !== '__proto__'
}
const deepmerge = (
@jrson83
jrson83 / Action.ts
Created March 2, 2023 23:21 — forked from TClark1011/Action.ts
TS - Helpful Utilities
// branded types to allow for better type inference
// with default generic types
/* eslint-disable @typescript-eslint/naming-convention */
type NO_PAYLOAD = {
JgJES6BF8uyaOwF1: "FY7eBhPYJlqOxuVp";
};
type OPTIONAL_PAYLOAD = {
A7nWdXs0r5RLuHRf: "zPcrRNRIl4r5IHbA";
};
@jrson83
jrson83 / home.tsx
Created March 9, 2023 21:58
persistent layouts
import Layout from '../Layouts'
import { Fragment } from 'react'
const Home: React.FC = () => {
return (
<Fragment>
<h1>Home</h1>
<p>Hello, welcome to your first Inertia app!</p>
</Fragment>
)
@jrson83
jrson83 / cleanModules.js
Last active April 1, 2023 13:43
Deletes node_modules folders inside a workspace recursively & parallel
#!/usr/bin/env node
import { readdir, rm } from 'node:fs/promises'
/**
* @license
* MIT License
*
* Copyright (c) 2023 Jörn Spangenberg <https://jrson.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@jrson83
jrson83 / install-zsh-windows-git-bash.md
Created April 12, 2023 11:01 — forked from fworks/install-zsh-windows-git-bash.md
Zsh / Oh-my-zsh on Windows Git Bash
@jrson83
jrson83 / alert.svg
Created May 15, 2023 01:01
alert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.