Skip to content

Instantly share code, notes, and snippets.

View regexyl's full-sized avatar

Regina Liu regexyl

View GitHub Profile
@regexyl
regexyl / aot-day8.ts
Last active December 9, 2023 09:48
Advent of Typescript 2023
// Filter out key-value pairs in an object that start with 'naughty'
type RemoveNaughtyChildren<T extends {}> = {
[key in keyof T as key extends `naughty_${string}` ? never : key] : T[key]
}
// Test cases
import { Expect, Equal } from 'type-testing';
@regexyl
regexyl / index.js
Last active January 23, 2024 19:20
Shortcut to render the first page of commits from a public GitHub repo
// Execute this code snippet in the browser console when you're
// already on a repo's webpage. This is pretty helpful when you
// want to read a large OSS project but feel overwhelmed or not
// sure where to start - this is a neat hack to take you to see
// the original core concepts of the project, which might not
// always work but does the job most of the time.
(async () => {
try {
const pathMatches = window.location.pathname.match(/\/([^\/]+\/[^\/]+)(?:\/tree\/([^\/]+))?/);
@regexyl
regexyl / diceCombinations.py
Created March 28, 2023 12:09
Solving the leftover dice combinations problem
from functools import cache
"""
You are throwing a dice for a fixed number of times (`throwCount`), of which
you know the average of the total score. The total score is calculated by
adding up all the dice scores from each throw. You only know the score of a
few of the dice throws.
Find all possible combinations of the remaining dice that fulfill
the above information.
@regexyl
regexyl / TIL-2022-03.md
Last active March 31, 2022 10:13
TIL snippets in point form. This is the very first TIL note! Planning to do 1 TIL.md per month.

TIL - March 2022

31 Mar 2022

  • re: Obsidian scheduled backups - Tried to get launchd to work via plist at ~/Library/LaunchAgents/com.gilite-notes.notes.plist, but it didn't have enough permissions to access the Node files at /usr/local/bin/node.
    • Originally preferred launchd over cron since it allows the job to run right after the computer wakes from sleeping, if the job was supposed to run but the computer was in sleep mode.
    • Also attempted moving the plist to ~/Library/LaunchDaemons/ so that the job can be executed even if I'm logged out, but the same error as above occurred.
    • cron worked after a few tries, incl. setting the git config to replace https://github.com/ with git@github.com: since one of the errors specified fatal: could not read Username for 'https://github.com': No such file or directory. (see this)
  • To get over the same error wit

VSCode Settings

Mac Keyboard Shortcuts

Not exclusive to VSCode.

  • opt + backspace: Deletes 1 word to the left of cursor
  • opt + fn2 + backspace: Deletes 1 word to the right of cursor

Navigate

  • ^⌘→: Shift focused editor into right group

Frontend Tools

  • Bundlephobia: Find out bundle size, download times and composition percentages of NPM packages.
@regexyl
regexyl / regex.md
Last active February 25, 2022 13:43

Regex Cheatsheet

The JavaScript version.

Frequent Examples

Search for: [^moz-eg]

  1. "/example/": /\/example\/[a-z]+/i
  2. Switch words in a string
let re = /(\w+)\s(\w+)/;
let str = 'John Smith';
@regexyl
regexyl / git.md
Last active March 31, 2022 01:42

Git Commands

Commit

git commit --allow-empty -m "trigger build" # Commit no new changes to trigger build
Amend to last commit

You should never amend public commits (i.e. already pushed to a public reop).

@regexyl
regexyl / .eslintrc.js
Created February 18, 2022 09:07 — forked from nkbt/.eslintrc.js
Strict ESLint config for React, ES6 (based on Airbnb Code style)
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": ["react"],
"ecmaFeatures": {
@regexyl
regexyl / commands.sh
Last active April 8, 2022 01:35
Linux/MacOS commands I use a lot
# ***** FILE SYSTEM *****
# Find paths of all files beginning with a regex in the current directory
find . -regex '.*/learn.*' -maxdepth 1
# Move all files matching the regex to a folder ./learn
# Warning: An error will appear but it's ok, all files except for ./learn itself are moved
# mv: rename ./learn to learn/learn: Invalid argument
mv $(find . -regex '.*/learn.*' -maxdepth 1) learn