Skip to content

Instantly share code, notes, and snippets.

View prmichaelsen's full-sized avatar
🌚

Patrick Michaelsen prmichaelsen

🌚
  • Phoenix
  • 10:48 (UTC -06:00)
View GitHub Profile
@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() {
function hashString(s) {
let hashValue = 0;
for (let i = 0; i < s.length; i++) {
hashValue = (hashValue * 31 + s.charCodeAt(i)) % 4294967296;
}
let bucket = Math.floor((hashValue / 4294967296) * 8);
return bucket;
}
@font-face {
font-family:Slack-Lato;
font-style:normal;
font-weight:300;
src:local("☺"),url(https://a.slack-edge.com/bv1-10/lato-light-0b50f74.woff2) format("woff2"),url(https://a.slack-edge.com/bv1-10/lato-light-1475c14.woff) format("woff");
unicode-range:u+0000-f8fe,u+f900-ffff;
}
@font-face {
font-family:Slack-Lato;
font-style:normal;
@prmichaelsen/parm@2.0.0 /Users/patrick/workplace/parm-v1.0.0
├─┬ @angular/forms@14.1.2
│ ├─┬ @angular/common@14.1.2
│ │ ├── @angular/core@14.1.2 deduped
│ │ ├── rxjs@7.5.6 deduped
│ │ └── tslib@2.4.0 deduped
│ ├─┬ @angular/core@14.1.2
│ │ ├── rxjs@7.5.6 deduped
│ │ ├── tslib@2.4.0 deduped
│ │ └─┬ zone.js@0.11.8
@prmichaelsen
prmichaelsen / Img.tsx
Last active August 12, 2022 19:21
renders an image element that dynamically updates its bottom margin s.t. it always has a total height that is some multiple of 1.5em
import React, {
useEffect, useRef,
useState, useCallback,
} from 'react';
export function useResize() {
const getSize = () => {
return {
width: window.innerWidth,
height: window.innerHeight
#!/usr/bin/env ts-node
const grades: [number, string][] = [
[96, 'A+'],
[93, 'A' ],
[90, 'A-'],
[86, 'B+'],
[83, 'B '],
[80, 'B-'],
[76, 'C+'],