Skip to content

Instantly share code, notes, and snippets.

View jonsmithers's full-sized avatar
🐧
doing stuff

Jon Smithers jonsmithers

🐧
doing stuff
View GitHub Profile
@jonsmithers
jonsmithers / useSystemThemePreference.ts
Created June 9, 2023 21:43
useSystemThemePreference
export const useSystemThemePreference = (): 'dark' | 'light' => {
const systemPrefQuery = useMemo(
() => window.matchMedia('(prefers-color-scheme: dark)'),
[]
);
const [systemThemePreference, setSystemThemePreference] = useState<
'dark' | 'light'
>(systemPrefQuery.matches ? 'dark' : 'light');
const onSystemPreference = useCallback(() => {
setSystemThemePreference(systemPrefQuery.matches ? 'dark' : 'light');
@jonsmithers
jonsmithers / these-are-a-few-of-my-favorite-hooks.ts
Last active February 14, 2022 19:45
these are a few of my favorite hooks
/**
* Calls the provided factory on first render, then returns THAT value on all
* renders thereafter.
*/
export function useMakeOnce<T>(factory: () => T): T {
const [value] = useState(factory);
return value;
}
/**
@jonsmithers
jonsmithers / weakref.d.ts
Last active November 11, 2020 19:49
WeakRef type definition
/**
* WeakRef is supported by major browsers but doesn't appear to be available in
* Typescript 4.0.5. Here is a temporary type definition until TypeScript adds
* native support.
*
* See https://github.com/microsoft/TypeScript/issues/32393
*/
interface WeakRef<V> {
deref(): V | undefined;
@jonsmithers
jonsmithers / all-imperative-verbs
Last active October 24, 2022 12:17
All imperative verbs - useful for validating git commit messages
aah
abacinate
abandon
abase
abash
abate
abbreviate
abdicate
abduce
abduct
@jonsmithers
jonsmithers / anti-wip pre-push
Last active October 11, 2019 01:10
Prohibit WIP commits
#!/bin/bash
read -r local_ref local_sha remote_ref remote_sha
check_for_wip_commits() {
if [[ "$remote_ref" != 'refs/heads/master' ]]; then
return
fi
commits=$(git log --format=%s "$remote_sha".."$local_sha")
local IFS=$'\n'
@jonsmithers
jonsmithers / intellij-open-in-vim
Last active March 19, 2019 15:09
IntelliJ - Open in Vim
Settings > External Tools > Add
Name: Open in Vim
Program: gvim
Arguments: $FilePath$ "+call cursor($LineNumber$, $ColumnNumber$)" "+set cursorline" "+set lines=100" "+set columns=1000" "+autocmd VimLeavePre * execute '!idea ' . expand('%') . ':' . line('.')"
Working directory: $ProjectFileDir$
Advanced > Open console for tool output: OFF
@jonsmithers
jonsmithers / queue.js
Created May 8, 2018 16:33
A missing queue implementation for JavaScript, implemented with a linked list
/**
* Simple Queue implementation based on a linked-list
*/
class Q {
/**
* Construct a queue
* @param {array} [items] - Items to put in the queue (in left-to-right order)
*/
constructor(items) {
this._size = 0

Keybase proof

I hereby claim:

  • I am jonsmithers on github.
  • I am jonsmithers (https://keybase.io/jonsmithers) on keybase.
  • I have a public key ASCK8kq3ik-vqpcrTb34aFTxGKriHs5vG0wBM_DRH5LBTAo

To claim this, I am signing this object: