Skip to content

Instantly share code, notes, and snippets.

View endymion1818's full-sized avatar
🦈
47

Ben Read endymion1818

🦈
47
View GitHub Profile
@endymion1818
endymion1818 / fetch.js
Last active February 5, 2024 10:44
fetch
async function getStuff(token) {
const body = {}
// wrap in try / catch so we can resolve any network failures
try {
// initial request
const result = await fetch(`https://example.com/api/v1`, {
headers: {
"x-CSRF-Token": token,
"Content-Type": "application/json"
},
@endymion1818
endymion1818 / zathras.zsh-theme
Last active December 7, 2023 16:02
ZHS theme (forked from "amuse")
# vim:ft=zsh ts=2 sw=2 sts=2
# Must use Powerline font, for \uE0A0 to render.
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}\uE0A0 "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}!"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg_bold[red]%}‹"
@endymion1818
endymion1818 / matchWeatherCode.js
Last active November 3, 2023 12:13
matchWeatherCode.js
// @see https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM
function matchWeatherCode(code) {
switch (code) {
case 0:
return "🌥️"
case 1:
return "🌥️"
case 2:
return "🌥️"
case 3:
@endymion1818
endymion1818 / pre-push
Created October 18, 2023 15:01
git pre-push hook
# ~/.git_templates/hooks/pre-push
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "${protected_branch} is a protected branch, create PR to merge"
@endymion1818
endymion1818 / git config aliases
Last active October 18, 2023 15:00
Just in case my computer blows up, I have all of my git shortcuts here
[push]
autoSetupRemote = true
[user]
name = xxx
email = xxx
[core]
excludesfile = ~/.gitignore
[alias]
sla = log --oneline --decorate --graph --all
whowhen = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
@endymion1818
endymion1818 / restore-blog-scraper.js
Created September 7, 2023 15:08
restore blog scraper
const { parse } = require('rss-to-json');
const cheerio = require('cheerio');
const fs = require('fs');
const TurndownService = require('turndown')
const turndownService = new TurndownService({
codeBlockStyle: 'fenced',
bulletListMarker: '-',
headingStyle: 'atx',
})
@endymion1818
endymion1818 / index.d.ts
Created July 27, 2023 14:20
Pick only one
type RequireOnlyOne<T, Keys extends keyof T = keyof T> =
Pick<T, Exclude<keyof T, Keys>>
& {
[K in Keys]-?:
Required<Pick<T, K>>
& Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys]
type Events = 'play' | 'pause' | 'ready' | 'seek' | 'end';
@endymion1818
endymion1818 / toggle.html
Created April 27, 2023 13:06
tailwind toggle with pseudoelements
<span class="tw-flex tw-items-center tw-cursor-pointer">
<label for="autoplay" class="tw-text-xs tw-font-medium tw-text-zinc-400 dark:tw-text-zinc-500 tw-mr-2">Autoplay</label>
<input type="checkbox" id="autoplay" class="tw-bg-zinc-200 tw-relative tw-inline-flex tw-h-6 tw-w-11 tw-flex-shrink-0 tw-cursor-pointer tw-rounded-full tw-border-2 tw-border-transparent tw-transition-colors tw-duration-200 tw-ease-in-out focus:tw-outline-none focus:tw-ring-2 focus:tw-ring-primary-600 focus:tw-ring-offset-2 before:tw-content-[''] before:tw-translate-x-0 before:tw-pointer-events-none before:tw-inline-block before:tw-h-5 before:tw-w-5 before:tw-transform before:tw-rounded-full before:tw-bg-white before:tw-shadow before:tw-ring-0 before:tw-transition before:tw-duration-200 before:tw-ease-in-out before:tw-relative before:tw-z-10 checked:before:tw-translate-x-5 checked:tw-bg-zinc-200 checked:tw-text-zinc-200 checked:focus:tw-text-primary-600 checked:after:tw-block checked:after:tw-content-[''] checked:after:tw-bg-zin
@endymion1818
endymion1818 / theme.js
Last active April 19, 2023 10:43
toggles
document.addEventListener("DOMContentLoaded", function() {
// Theme Toggle
const themeToggle = document.getElementById("dark-mode-toggle");
const themeToggleCircle = document.getElementById("dark-mode-toggle-circle");
// Check if the user has set a theme preference set in localStorage or if the browser preferences
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
} else {