Skip to content

Instantly share code, notes, and snippets.

View prmichaelsen's full-sized avatar
🌚

Patrick Michaelsen prmichaelsen

🌚
  • Phoenix
  • 06:14 (UTC -06:00)
View GitHub Profile
function compareSemver(a: string, b: string) {
const aSemver = a.split('-')[1].split('.');
const bSember = b.split('-')[1].split('.');
for (let i = 0; i < 3; i++) {
const aPart = parseInt(aSemver[i], 10);
const bPart = parseInt(bSember[i], 10);
if (aPart > bPart) {
@prmichaelsen
prmichaelsen / jestDiff.ts
Last active August 20, 2024 13:05
This script generates test output files for each jest test so you can view the diffs in an external diff viewer
#!/usr/bin/env ts-node
import { spawn } from 'node:child_process';
import * as fs from "node:fs";
// This script generates test output
// files for each jest test so
// you can view the diffs in an external
// diff viewer
function sortByKey(obj: any): any {
// ==UserScript==
// @name Alt Click Copy
// @namespace http://tampermonkey.net/
// @version 0.1.0
// @description Alt click an HTML element on the page to copy it to your clipboard.
// @author mchpatr
// @match *://*/*
// @icon https://github.com/prmichaelsen/alt-click-copy/releases/download/alt-click-copy/save.icon.png
// @run-at document-start
// ==/UserScript==
@prmichaelsen
prmichaelsen / session.ts
Created June 5, 2024 18:23
example single command terminal exec using streams
import { Readable, Writable } from "node:stream";
import { spawn } from "node:child_process";
export const execCommand = async (cmd: string) => {
const ps = spawn("sh", { env: process.env });
const data: string[] = [];
const outputStream = new Writable({
write(chunk, encoding, callback) {
@prmichaelsen
prmichaelsen / rmrf.sh
Created May 21, 2024 21:28
Send your files to .trash instead of the void
rmrf () {
trash="$HOME/.trash"
mkdir -p $trash
if [ -z "$1" ]; then
echo "Usage: rmrf <dir>";
return 1
else
while [ -n "$1" ]
do
dir="$PWD/$1"
@prmichaelsen
prmichaelsen / gitf.sh
Created April 16, 2024 17:48
Git force push
gitf ()
{
prefix="dev/$USER/"
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" = $prefix* ]]; then
echo "[INFO]: Force pushing to branch '$branch'..."
git push origin ":$branch" ; git push origin -u "$branch"
else
echo "[INFO]: Cannot push to branch '$branch' because it does not match prefix '$prefix'."
}
@prmichaelsen
prmichaelsen / entity-readme.md
Created February 26, 2024 09:26
Entity definition

Let's examine the type for Entity.

export interface Model {};
export type Entity<
  TModels extends Model[],
> = {
  id?: string,
  creatorId?: string,
 createTimeMs?: number,
import { NonObject } from "./core-types";
export type DeepComplete<T> = T extends NonObject
? Exclude<T, undefined>
: T extends Array<infer U>
? DeepCompleteArray<U>
: T extends Map<infer K, infer V>
? DeepCompleteMap<K, V>
: DeepCompleteObject<T>;
@prmichaelsen
prmichaelsen / _app.tsx
Created October 5, 2023 04:38
Minimal example of passing hotkey strokes between VSCode and an internal webview
// Within SPA webapp
import { useEffect } from 'react';
export default function() {
useEffect(() => {
window.addEventListener('keydown', (event) => {
if ((event.ctrlKey || event.metaKey) && event.code === "KeyC") {
document.execCommand("copy");
} else if ((event.ctrlKey || event.metaKey) && event.code === "KeyX") {
document.execCommand("cut");
import { useState, useEffect, useCallback } from 'react';
const getSize = () => {
return {
width: window.innerWidth,
height: window.innerHeight,
};
};
export function useResize() {