Skip to content

Instantly share code, notes, and snippets.

View joshuabaker's full-sized avatar
🎭

Joshua Baker joshuabaker

🎭
View GitHub Profile
@joshuabaker
joshuabaker / languages.json
Last active April 30, 2024 17:07
List of languages with ISO 639-1 Alpha-2 codes in JSON.
[
{
"code": "aa",
"name": "Afar",
"native": "Afar"
},
{
"code": "ab",
"name": "Abkhazian",
"native": "Аҧсуа"

Tailwind class autocomplete in object strings

Using Tailwind’s intellisense in VSCode and other IDEs, it’s possible to autocomplete classes in class, className, et al.

In some cases you want to introduce variants, which mean autocomplete is not available. To get around this, I use the following setup.

//                Add this to objects
//                ↓     ↓
const variants = /* tw */ {

How to fix Cloudflare Worker unregister on macOS

[ERROR] Failed to unregister worker TypeError: fetch failed

I noticed that, from time to time, Wrangler worker instances get stuck and cannot be unregistered. Use the following command to force unregister.

kill -9 $(lsof -ti:6284)
@joshuabaker
joshuabaker / composer.json
Created June 20, 2023 15:26
Craft CMS project config deploy script for Fortrabbit
{
"scripts": {
"deploy-project-config": [
"ssh {app-name}@deploy.eu2.frbit.com rm -rf config/project/*",
"rsync -av ./config/project/* {app-name}@deploy.eu2.frbit.com:~/config/project",
"ssh {app-name}@deploy.eu2.frbit.com php craft clear-caches/all",
"ssh {app-name}@deploy.eu2.frbit.com php craft migrate/all",
"ssh {app-name}@deploy.eu2.frbit.com php craft project-config/apply"
]
}
@joshuabaker
joshuabaker / ignored-build-step.sh
Created May 15, 2023 17:22
For use on Vercel. Ignores the build step if a commit includes #nodeploy.
#!/bin/bash
echo "VERCEL_GIT_COMMIT_MESSAGE: $VERCEL_GIT_COMMIT_MESSAGE"
if [[ "$VERCEL_GIT_COMMIT_MESSAGE" == *"#nodeploy"* ]]; then
# Don't build
echo "🛑 - Build cancelled"
exit 0;
else
# Proceed with the build
@joshuabaker
joshuabaker / useChakraResponsiveImageSizes.jsx
Last active January 4, 2023 13:01
Converts Chakra responsive syntax (array or object) to sizes for use with image elements.
import { useTheme } from "@chakra-ui/react";
import { objectToArrayNotation } from "@chakra-ui/utils";
export default function useChakraResponsiveImageSizes(sizes) {
const theme = useTheme();
const details = theme.__breakpoints.details;
if (!sizes) {
return null;
}
@joshuabaker
joshuabaker / border-image-border-radius.css
Created November 29, 2022 18:53
Example of using border image with border radius using a exclusion mask.
.box {
--radius: 3px;
position: relative;
width: 64px;
height: 64px;
background: linear-gradient(to bottom, green, gold);
border-radius: var(--radius);
}
.box::after {
@joshuabaker
joshuabaker / gist:313648
Last active May 11, 2022 07:17
Get all images in a HTML string
<?php
/**
* Returns all img tags in a HTML string with the option to include img tag attributes
*
* @author Joshua Baker
*
* @example $post_images[0]->html = <img src="example.jpg">
* $post_images[0]->attr->width = 500
*
@joshuabaker
joshuabaker / Sanitise for web
Last active January 6, 2022 10:30
Name Mangler snippet to sanitise filenames for web.
[concatenate
[lowercase
[findRegularExpression
"-+"
in [findRegularExpression
"([^a-zA-Z0-9-])"
in [findRegularExpression
"([^A-Z])([A-Z])"
in <name>
replace with "$1 $2"
@joshuabaker
joshuabaker / http-status-codes.sh
Created June 30, 2021 15:11
Takes a list of URLs and outputs the HTTP status code.
#!/bin/sh
# Usage
#
# chmod 755 http-status-codes.sh
#
# cat list-of-urls.txt | xargs http-status-codes.sh
for arg in $@ ; do
statusCode=`curl -I 2>/dev/null $arg | head -n 1 | awk '{print $2}'`