Skip to content

Instantly share code, notes, and snippets.

View mxdvl's full-sized avatar
🧭
I love me an SVG

Max Duval mxdvl

🧭
I love me an SVG
View GitHub Profile
@acutmore
acutmore / ts-blank-space-doc.md
Last active July 19, 2024 17:16
Learnings from 'ts-blank-space`

Learnings from ts-blank-space

tags: TypeScript, type erasure, type stripping

ts-blank-space

As part of my work on the JavaScript Tooling team at Bloomberg I have implemented an experimental (not yet used in production) package to transform TypeScript into JavaScript using a somewhat novel approach.

This is a description of what I learned from implementing the idea. The source code will be open sourced soon - it just needs some regular IP approval.

@jonathonherbert
jonathonherbert / script.sh
Last active April 22, 2024 15:26
Select git branch by date (requires fzf)
fbr() {
local branches branch
branches=$(git reflog show --pretty=format:'%gs ~ %gd' --date=relative \
| grep 'checkout:' \
| grep -oE '[^ ]+ ~ .*' \
| awk -F~ '!seen[$1]++' \
| head -n 20 \
| awk -F' ~ HEAD@{' '{printf(" \033[33m%s: \033[37m %s\033[0m\n", substr($2, 1, length($2)-1), $1)}' \
| nl \
| sort -nr \
@jakelazaroff
jakelazaroff / i-frame.js
Last active December 4, 2023 10:16
simple web component that sandboxes its slotted elements inside an iframe
customElements.define(
"i-frame",
class extends HTMLElement {
#shadow = this.attachShadow({ mode: "closed" });
constructor() {
super();
this.#shadow.innerHTML = `
<slot></slot>
<iframe part="frame" srcdoc=""></iframe>
function check_package_manager() {
current_dir=$(pwd)
while [ "$(pwd)" != "/" ]; do
if [ -f "pnpm-lock.yaml" ]; then
if [ "${1}" != "pnpm" ]; then
echo "Looks like you're using the wrong package manager, partner!"
echo "It's pnpm time, cowboy."
cd "${current_dir}"
return 1
@feoktant
feoktant / Day4.scala
Created December 4, 2022 22:13
Day4
val InputRegex = "(\\d+)-(\\d+),(\\d+)-(\\d+)".r
def matchFullContain(str: String): Boolean = str match {
case InputRegex(t1, t2, e1, e2) =>
(t1.toInt <= e1.toInt && e2.toInt <= t2.toInt) ||
(e1.toInt <= t1.toInt && t2.toInt <= e2.toInt)
case _ => false
}
def matchOverlap(str: String): Boolean = str match {
@bryophyta
bryophyta / stack-traces.ts
Created August 19, 2022 16:03
Experiment: Stack traces with TypeScript
// `CallSite` is the class representing a stack frame in the V8 spec
// (see https://v8.dev/docs/stack-trace-api#customizing-stack-traces)
// hat tip to the callsites package, where I'm importing the `CallSite` type from: https://github.com/sindresorhus/callsites
import { CallSite } from "https://raw.githubusercontent.com/sindresorhus/callsites/7fb22a67645ea741cc016937e8f3662eb533eb6e/index.d.ts";
// there is a default implementation for preparing stack traces on the Error object, but TypeScript doesn't recognise
// this. (maybe because it's not present in all runtimes? or maybe the default is initialised in some other way?)
type ErrorWithPrepFn = ErrorConstructor & { prepareStackTrace?: (error: Error, stack: CallSite[]) => unknown}
@bryophyta
bryophyta / coauth.md
Last active December 5, 2023 10:31
git commit coauthor search

Generate co-author messages for git repos

A zsh function which searches through the contributors to the repo in the current working directory, and generates 'co-authored by' messages for them, that can then be copied into your commit messages.

Searches through names and email addresses that have been used in commit messages in the current repo. The -S flag means that searches are 'smart case' by default: case insensitive, unless upper case letters are included in the search string, in which instance it will switch to case sensitive search. Other options can be found in the ripgrep user guide.

Setup

Dependencies

@dgcoffman
dgcoffman / require-named-effect.js
Created May 23, 2022 16:16
libs/eslint-rules/require-named-effect.js
const isUseEffect = (node) => node.callee.name === 'useEffect';
const argumentIsArrowFunction = (node) => node.arguments[0].type === 'ArrowFunctionExpression';
const effectBodyIsSingleFunction = (node) => {
const { body } = node.arguments[0];
// It's a single unwrapped function call:
// `useEffect(() => theNameOfAFunction(), []);`
if (body.type === 'CallExpression') {
var Ta = ["cigar", "rebut", "sissy", "humph", "awake", "blush", "focal", "evade", "naval", "serve", "heath", "dwarf", "model", "karma", "stink", "grade", "quiet", "bench", "abate", "feign", "major", "death", "fresh", "crust", "stool", "colon", "abase", "marry", "react", "batty", "pride", "floss", "helix", "croak", "staff", "paper", "unfed", "whelp", "trawl", "outdo", "adobe", "crazy", "sower", "repay", "digit", "crate", "cluck", "spike", "mimic", "pound", "maxim", "linen", "unmet", "flesh", "booby", "forth", "first", "stand", "belly", "ivory", "seedy", "print", "yearn", "drain", "bribe", "stout", "panel", "crass", "flume", "offal", "agree", "error", "swirl", "argue", "bleed", "delta", "flick", "totem", "wooer", "front", "shrub", "parry", "biome", "lapel", "start", "greet", "goner", "golem", "lusty", "loopy", "round", "audit", "lying", "gamma", "labor", "islet", "civic", "forge", "corny", "moult", "basic", "salad", "agate", "spicy", "spray", "essay", "fjord", "spend", "kebab", "guild", "aback", "motor", "alone
@arelra
arelra / launch.json
Created January 5, 2022 17:23
VSCode launch.json for Jest using package.json configuration
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest watch current file",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": [
"${fileBasename}",