Skip to content

Instantly share code, notes, and snippets.

@badsyntax
badsyntax / paths.ts
Last active February 11, 2025 21:41
Fast & Flexible TypeScript dot notation key extraction that supports nested objects to a depth of 10
/**
* Example usage:
*
* // default depth of 3: (fastest)
* type keys = Paths<SomeNestedObject> // returns "property" | "nested.property" | "nested.nested.property"
*
* // depth of 10: (can be slow)
* type keys = Paths<SomeNestedObject, 10>
*
* // depth of 10 with keys of type string and number: (slowest)
@badsyntax
badsyntax / replace.sh
Created May 28, 2010 10:15
Simple recursive search and replace string in files
#!/usr/bin/env bash
#
# simple recursive search and replace string in files
# setup: alias replace='~/replace.sh'
# notes: you will need to escape special chars! eg: replace '\/dir1' '\/dir2' .
# usage: replace <oldstring> <newstring> <path> <depth>
# examples:
# replace "([^\s]+.php)" "\/\1" .
# replace "\"\/([^\/]+.php)" "\"\/dir\/\1" .
@badsyntax
badsyntax / INSTRUCTIONS.md
Last active December 3, 2024 16:09
Getting started with Java development on macOS

Getting started with Java development on macOS

Install multiple Java versions

To start, list current installed Java versions:

/usr/libexec/java_home -verbose
@badsyntax
badsyntax / QueryClientProvider.ts
Last active November 1, 2024 12:39
React Native, React Query Offline Persisted Queries & Mutations
import React, { type PropsWithChildren } from 'react';
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client';
import { onlineManager } from '@tanstack/react-query';
import { queryClient } from './queryClient';
import { storagePersister } from './storagePersister';
export function QueryClientProvider(props: PropsWithChildren) {
return (
<PersistQueryClientProvider
client={queryClient}
@badsyntax
badsyntax / android-emulator-setup.yml
Created August 4, 2021 12:39
Setup the android emulator on Azure Devops Pipelines
# NOTE: must be run on a MacOS Agent!
steps:
- script: |
# Install AVD files
yes | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-29;default;x86_64'
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-29;default;x86_64' --force
@badsyntax
badsyntax / find-unused-sass-variables.sh
Last active July 17, 2024 03:36 — forked from axelerator/Find unused variables in sass files
Find unused SCSS variables. Usage: `./find-unused-sass-variables.sh sassDir/`
#!/usr/bin/env bash
#
# Approach:
# 1. Find variable declaration in the form of "$my-var: anyvalue"
# 2. Loop through found variables and find occurrences of each variable in all sass files
# 3. Filter out vars that occurred only once
if [ -z "$1" ]; then
echo "Please specify a directory as the first argument."
exit 1
@badsyntax
badsyntax / default
Last active May 28, 2024 16:25
My basic nginx config files for proxying to a node.js application
server {
listen YOUR_IP_ADDRESS:80 default_server;
root /var/www/nginx;
index index.html index.htm;
# This is just an invalid value which will never trigger on a real hostname.
server_name _;
server_name_in_redirect off;
@badsyntax
badsyntax / android_emulator_cli_ci.md
Last active May 3, 2024 04:01
start an android emulator with screen dimensions (specifically for use in CI)
# Install AVD files
yes | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-29;default;x86'
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses

# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-29;default;x86' --force

$ANDROID_HOME/emulator/emulator -list-avds
@badsyntax
badsyntax / cloc.sh
Created October 11, 2023 16:31
react native cloc
cloc --exclude-dir=vendor,.xcodeproj,xcuserdata,build,Pods,node_modules,.gradle,dist,yarn.lock,package-lock.json .
@badsyntax
badsyntax / gist:375dfe6258695e5b488d0860ef47ad18
Created March 13, 2024 08:41
remove dotnet bin and obj
find . -iname "bin" -o -iname "obj" | xargs rm -rf