This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
sanitize_node() { | |
shopt -s extglob | |
filename=$(basename "$1") | |
directory=$(dirname "$1") | |
if [ -f "$1" ]; then | |
extension=".${filename##*.}" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react"; | |
const makeObservable = (target) => { | |
let listeners = []; | |
let value = target; | |
const getter = () => { | |
return value; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
const usePolling = (interval = null, pollingFunction, deps = []) => { | |
const [subscription, setSubscription] = useState(null); | |
useEffect(() => { | |
if (!!interval) { | |
const id = setInterval(pollingFunction, interval); | |
setSubscription(id); | |
} | |
return () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect } from "react"; | |
const useEventListener = (targetElement, eventType, callback, deps = []) => { | |
const callbackHandle = useCallback(callback, deps); | |
useEffect(() => { | |
targetElement.addEventListener(eventType, callbackHandle); | |
return () => { | |
targetElement.removeEventListener(eventType, callbackHandle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, body { | |
margin: 0; | |
padding: 0; | |
} | |
*[grid] { | |
box-sizing: border-box; | |
margin: 0 0; | |
padding: 0 0; | |
width: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
usage() { echo "Usage: $0 [-o <output file>] [-n <wifi name>] [-p <password>] [-t <WPA|WEP>]" 1>&2; exit 1; } | |
while getopts ":n:p:t:o:h" param; do | |
case "${param}" in | |
n) | |
n="${OPTARG}" | |
;; | |
p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Encodable { | |
fileprivate func encode(to container: inout SingleValueEncodingContainer) throws { | |
try container.encode(self) | |
} | |
} | |
/// A wrapper allowing Encodable types to be encoded — even | |
/// when only references as an existential `any Encodable`. | |
/// | |
/// source: https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional { | |
func orThrow(_ error: (any Error)? = nil) throws -> Wrapped { | |
switch self { | |
case .none: | |
if let error { | |
throw error | |
} else { | |
throw OptionalUnwrappingError(Wrapped.self) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ -t 0 ]; then # if no stdin to clip... | |
if [ -z "$*" ]; then # if no args to clip, paste | |
# paste | |
pbpaste | |
else # if there are args, execute as command and copy output | |
eval "${*}" | pbcopy | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval "$(starship init zsh)" | |
function _cursor_block() { echo -ne '\e[1 q' } | |
function _cursor_bar() { echo -ne '\e[3 q' } | |
function _cursor_beam() { echo -ne '\e[5 q' } | |
function zle-keymap-select zle-line-init | |
{ | |
case $KEYMAP in | |
vicmd) _cursor_block;; |