Skip to content

Instantly share code, notes, and snippets.

View budparr's full-sized avatar
🎯
Focusing

Bud Parr budparr

🎯
Focusing
View GitHub Profile
@TimothyLoyer
TimothyLoyer / sn-convert-img
Last active May 8, 2023 16:36
Bash script to convert images for use with Supernote A6X and A5X
#!/usr/bin/bash
################################################################################
#
# Description:
# Convert images for compatibility with the Supernote A6X and A5X.
#
# If an original image's size exceeds the ratio required to be compatible
# with the Supernote, it will automatically be centered and cropped.
#
# Usage:
@System-Glitch
System-Glitch / go-worker.go
Last active January 5, 2022 15:11
A resilient Go worker
package main
// This is an example of a resilient worker program written in Go.
//
// This program will run a worker, wait 5 seconds, and run it again.
// It exits when SIGINT or SIGTERM is received, while ensuring any ongoing work
// is finished before exiting.
//
// Unexpected panics are also handled: program won't crash if the worker panics.
// However, panics in goroutines started by the worker won't be handled and have
@TownLake
TownLake / blog-dev.sh
Created December 27, 2019 17:19
Shell script that will switch to your blog directory, start a testing Hugo server, wait for it to begin, and then connect it to the Internet via a free Cloudflare Argo Tunnel.
#!/bin/bash
trap "exit" INT TERM ERR
trap "kill 0" EXIT
# These lines make sure that the Hugo server and the Argo Tunnel processes are killed when you ctrl+c the terminal window.
cd /Users/samrhea/blog-samrhea
# This changes the directory to where my blog lives. Replace this with your own by running `pwd` in your blog directory and adding the output here.
@kmelve
kmelve / MyTool.js
Created November 25, 2019 22:25
Proof of Concept Kanban tool for Sanity Studio
import React from 'react'
import client from 'part:@sanity/base/client'
import ReactKanban from 'react-kanban-dnd';
const columns = [
]
const query = `{
"draft": *[_type == "post" && editorial == "draft"],
@dephiros
dephiros / package.json
Created May 31, 2019 15:44
Webpack + Sapper + Tailwind
{
"scripts": {
"dev": "sapper dev",
"format:check": "prettier --check './**/*.{js,ts,css,html,svelte}'",
"format": "prettier --write './**/*.{js,ts,css,html,svelte}'",
"build": "NODE_ENV=production sapper build",
"export": "NODE_ENV=production sapper export",
"start": "node __sapper__/build",
"cy:run": "cypress run",
@rordi
rordi / hugo-prev-next-navigation-custom-section.order.md
Last active April 18, 2021 18:33
Previous / Next Navigation in Hugo with custom section order

Previous/Next navigation in Hugo with custom order based on param / attribute

This gist let's you return previous/next pages based on a frontmatter parameter in Hugo. In this exmaple, the frontmatter parameter is called position, where lower positions come first.

This prev / next navigation is looping: if there is no "next >" entry anymore, the first entry of the collection will be linked. Same for "< prev": if there is no previous element, the last element of the collection will be linked.

<div class="nav-prev-next">
    {{ $currentSection := (($.Site.GetPage "section" .Section).Pages.ByParam "position") }}
<html>
<head>
<link
rel="prefetch"
as="image"
href="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg"
onload="fetch('https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg')"
/>
</head>
<body>
@chris-79
chris-79 / image.html
Created February 4, 2019 16:10
Hugo shortcode for Imgix
{{/* Assemble imgix URL without the query bit */}}
{{ $path := ((.Get "url") | default (.Get 0)) }}
{{/* Handle public shared images from Google Drive */}}
{{ if (in $path "drive.google.com") }}
{{ $path = ($path | replaceRE "([^=\\s]+id=)([\\w_-]+)" "https://drive.google.com/uc?id=$2") }}
{{ end }}
{{/* Encode paths that are full URLs or contain a "?" */}}
{{ if ((in $path "?") | or (findRE "^https?:\\/\\/" $path 1)) }}
{{ $path = (delimit (slice "/" (strings.TrimPrefix "=" (querify "" $path))) "") }}
{{ end }}
@DavidWells
DavidWells / dynamic-html-lambda.js
Created January 26, 2019 01:37
Respond with dynamic HTML from a lambda function
module.exports = (event, context, callback) => {
let name
if (event.pathParameters && event.pathParameters.name) {
name = event.pathParameters.name
}
/* generate the hello paragraph */
const helloParagraph = greetPerson(name)
// callback is sending HTML back
@hopsoft
hopsoft / prefetch.js
Last active December 27, 2023 02:45
Turbolinks Prefetching
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {