Skip to content

Instantly share code, notes, and snippets.

View joeworkman's full-sized avatar

Joe Workman joeworkman

View GitHub Profile
@joeworkman
joeworkman / total-cms-get-random-post.js
Created April 20, 2022 16:18
This will parse through the posts in a Total CMS blog and randomly return one. This was made to help with automations in Zapier.
const url = 'https://sandbox.joeworkman.net/cms-data/blog/store/_blog.json';
const res = await fetch(url);
const json = await res.text();
const posts = Object.values(JSON.parse(json).post).filter(post => !post.draft);
const winner = posts[Math.floor(Math.random()*posts.length)];
return winner;
@joeworkman
joeworkman / f6-ajax-example.php
Last active January 25, 2022 17:47
This is a sample of a PHP script that could be used with the Custom AJAX request for Foundation 6 Stacks at foundationstacks.com
<?php
ini_set('display_errors', '0');
function returnError($msg)
{
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json; charset=UTF-8');
die(json_encode(array('message' => trim(strip_tags($msg)), 'code' => 500, 'post' => $_POST)));
}
@joeworkman
joeworkman / npm.sh
Created January 9, 2022 16:53
Store a set of folders that will run pnpm instead of npm without having to remember what repos use what command. This is a simple shell function that you can add to your shell rc file.
npm() {
pnpm_folders=(/dev/repo1 /dev/repo2)
if printf '%s\n' "${pnpm_folders[@]}" | grep `pwd` ; then
pnpm $@
else
npm $@
fi
}
@joeworkman
joeworkman / brightness.rb
Last active April 9, 2020 18:36 — forked from ttscoff/brightness.rb
Ruby wrapper for brightness CLI (https://github.com/nriley/brightness)
#!/usr/bin/env ruby
# Brett Terpstra 2019/Joe Workman 2020
# This script adds the ability to increment/decrement display brightness
# levels to the nriley/brightness CLI (Copyright (c) 2014-2019, Nicholas Riley)
# Requires CLI installation: `brew install brightness`
# See https://github.com/nriley/brightness
CMD = "/usr/local/bin/brightness"
# Display usage and exit
def usage(code)
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=es6%2Ces7%2Ces5%2Cdefault"></script>
@joeworkman
joeworkman / swap-stacks.sh
Created March 30, 2019 16:34
This script will swap between Stacks 3 and 4. You will need to configure the `rwfolder` to be the location of your RapidWeaver addons. You will also need to create `tgz` archives of the Stacks 3 and 4 plugins so that they can be swapped. This script will always archive the plugins with every swap. This allows you to update the plugins to new ver…
#!/bin/bash
rwfolder=~/Library/Mobile\ Documents/com\~apple\~CloudDocs/RapidWeaver
cd "$rwfolder"
stacks=Stacks.rapidweaverplugin
plist=$stacks/Contents/Info.plist
version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$plist" | cut -f1 -d.`
@joeworkman
joeworkman / meta-tag-to-input.js
Created March 22, 2019 21:26
This will get the property name of meta tag and it will take that value and set the input value.
function getMeta(metaName) {
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('property') === metaName) {
return metas[i].getAttribute('content');
}
}
return '';
@joeworkman
joeworkman / upgrade_sendy.sh
Created March 21, 2019 18:55
This upgrades the version of Sendy installation for you. It creates a symlink from public_html to the actual version that you are running live. The public_html folder is doc root.
#!/usr/bin/zsh
if [ "$#" -ne 2 ]; then
echo "Usage: $0 OLD_VERSION NEW_VERSION" >&2
exit 1
fi
export OLD=$1
export NEW=$2
@joeworkman
joeworkman / replace-cms-data.sh
Created March 15, 2019 21:24
You can run this script as a cron/scheduled job on your host to replace the cms-data folder contents with a templated version that you may have. You will need to replace the paths to the cms-data folders inside this script in order for it to work.
#!/bin/bash
rm -r /home/username/websites/total-cms.com/cms-data/
cp -r /home/username/websites/total-cms.com/cms-data-template/ /home/username/websites/total-cms.com/cms-data/
@joeworkman
joeworkman / total-cms-category-post-submenu.php
Last active March 16, 2019 02:41
This will create a Total CMS menu of categories/tags/authors with a submenus of all posts in that are assigned to that category/tag/author
<?php
$cmsid = "blog";
$attribute = "category"; // tag, category, author
$href = "/blog/?category="; // URL to blog list with category filter
//-----------------------------------------------
// Do not modify below this line
//-----------------------------------------------
if ($publish) {
$totalblog = new \TotalCMS\Component\Blog($cmsid);
$attrs = $totalblog->list_attributes($attribute);