Skip to content

Instantly share code, notes, and snippets.

View Avery2's full-sized avatar

Avery Chan Avery2

View GitHub Profile
@Avery2
Avery2 / filter.js
Last active April 29, 2024 21:36
filter json for key or value that have term
function filterJSON(json, searchTerm, maxDepth = 10) {
// Function to check if the key or value matches the search term
function isMatch(value) {
if (value === null || value === undefined) return false;
if (typeof value === 'symbol') return value.toString().includes(searchTerm.toLowerCase());
if (typeof value === 'object') return false; // Avoid stringifying complex objects here
return value.toString().toLowerCase().includes(searchTerm.toLowerCase());
}
// Recursive function to filter the JSON based on searchTerm and depth
@Avery2
Avery2 / searchjson.js
Last active April 29, 2024 21:01
courtesy of chat gpt
function searchInJSON(json, searchTerm) {
console.log({ json });
// Function to check if the key or value matches the search term
function isMatch(value) {
if (value === null || value === undefined) return false;
if (typeof value === 'symbol') return false;
if (typeof value === 'object') return false;
return value.toString().toLowerCase().includes(searchTerm.toLowerCase());
}

Delete local branches that don't have a branch active on the remote.

git fetch -p ; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
@Avery2
Avery2 / semantic-commit-messages.md
Last active December 13, 2023 20:55 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@Avery2
Avery2 / script
Created July 10, 2023 08:21
This AppleScript transforms each nickname into 🥚. Old nicknames are quietly relocated to the notes. Rest assured, actual names stay unchanged. Now you get to identify each text sender by their vibe.
tell application "Contacts"
repeat with aPerson in people
-- Get old note, default to empty string if not present
set oldNote to note of aPerson
if oldNote is missing value then
set oldNote to ""
end if
-- Get old nickname, default to empty string if not present
set oldNickname to nickname of aPerson
@Avery2
Avery2 / ... in keybindings.json
Created February 7, 2023 21:17
using multi command https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command to open recent editors and select previous
{
"key": "shift+cmd+a",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.showAllEditorsByMostRecentlyUsed",
"workbench.action.quickOpenNavigateNext"
]
}
}
@Avery2
Avery2 / index.html
Created December 1, 2022 07:48
Minimal website with minimal styling
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Koya Saito | Website Redirect</title>
<!-- Minified version -->
<!-- <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> -->
<!-- Un-Minified version -->
@Avery2
Avery2 / zip longer
Created March 25, 2022 22:25
How to use zip_longer to create a zip that uses the length of the longer of the two iterables
import itertools
a = [i for i in range(10)]
b = [chr(ord('a') + i) for i in range(5)]
print(f"{len(list(itertools.zip_longest(a, b)))=}")
for x, y in itertools.zip_longest(a, b):
print(f"{x=} {y=}")
@Avery2
Avery2 / refresh.yml
Created January 13, 2022 15:19
Workflow for GitHub actions to trigger page rebuild. Token with repo access required.
name: Refresh
on:
workflow_dispatch:
jobs:
refresh:
runs-on: ubuntu-latest
steps:
- name: Trigger GitHub pages rebuild
x = [i*"hi" for i in range(1, 10)]
print(x)
# print(x[0], x[1])
# print(*x)
print(*x, sep="\n", end="\n"*2)
print(*x, sep="\n", end="\n"*2)
print(*x, sep="\n", end="\n"*2)