Skip to content

Instantly share code, notes, and snippets.

@mattslack
mattslack / pull-config.sh
Last active August 4, 2023 20:36
Pull craftcms project config down from production on fly.io
#!/bin/sh
# Pull down the current project config from production and overwrite the local
# config files with it.
cd "$(git rev-parse --show-toplevel)" || exit 1
if [ -n "$(git status --porcelain config/project)" ]; then
echo "You have uncommitted changes to your local project config."
exit 1
fi
@mattslack
mattslack / deploy
Created August 2, 2023 20:41
Deploy to fly.io
#!/usr/bin/env bash
generate_label () {
SHA=$(git rev-parse --short HEAD)
if [ -z "$(git status --porcelain | wc -l)" ]; then
STATE="clean"
else
STATE="dirty"
fi
LABEL="deployment-${SHA}-${STATE}"
@mattslack
mattslack / bb.sh
Last active July 23, 2021 13:02
Open a new PR in BitBucket with the branches pre-selected
#!/usr/bin/env bash
#
# Name this file 'bb', put it somehwere in your PATH and make it executable.
#
if [[ $# -eq 0 ]]; then
echo ""
echo " Create a pull request on BitBucket"
echo ""
@mattslack
mattslack / pre-commit
Last active March 10, 2020 19:38
git hooks
#!/bin/bash
# Built off of Standard JS's pre-commit example: https://standardjs.com/#is-there-a-git-pre-commit-hook
# Ensure all files staged for commit pass standard code style
function xargs-r() {
# Portable version of "xargs -r". The -r flag is a GNU extension that
# prevents xargs from running if there are no input files
if IFS= read -r -d $'\n' path; then
{ echo "$path"; cat; } | xargs $@
@mattslack
mattslack / remaster.sh
Last active May 8, 2020 14:17
Checkout a branch, update gems, run migrations, and prune merged branches
#!/bin/sh
BRANCH="master"
ROOT=`git rev-parse --show-toplevel`
[[ 0 < $# ]] && BRANCH=$1
[[ `git status -b -s --porcelain | egrep '^\#\# ($BRANCH)'` ]] || git checkout ${BRANCH} && {
(git pull origin ${BRANCH} || git pull --rebase origin ${branch} ) &&
git fetch -a &&
@mattslack
mattslack / dupefinder.js
Last active March 1, 2017 21:36
Find duplicate IDs in a document.
(function () {
"use strict";
var find_dupes = function () {
var identified = document.querySelectorAll('[id]'),
unique = [],
dupes = [],
id,
idx = 0;
while (idx < identified.length) {
id = (identified[idx]).getAttribute('id');

Keybase proof

I hereby claim:

  • I am mattslack on github.
  • I am mattslack (https://keybase.io/mattslack) on keybase.
  • I have a public key whose fingerprint is 705E 29C1 8381 0626 0938 288C 99D3 7AA5 F656 C3FD

To claim this, I am signing this object:

@mattslack
mattslack / selector_count.js
Last active September 14, 2017 15:08
Count the number of CSS selectors used on a given page.Refactored from: http://stackoverflow.com/questions/5228459/selector-count-in-css
/*properties
cssRules, href, length, log, selectorText, split, styleSheets
*/
(function () {
"use strict";
var j = 0,
totalRules = 0,
totalSelectors = 0,
count_rules = function (styleSheet) {
@mattslack
mattslack / gitclean.sh
Created October 17, 2013 13:53
Clean up a directory full of git repos. Maybe get back some hard disk space.
#!/bin/zsh
PROJECTS_DIR="${HOME}/Projects"
cd $PROJECTS_DIR
for client in `find ${PROJECTS_DIR} -type d -name ".git"`; do
cd ${client}
cd ..
echo "Checking: `pwd`"
git gc
git remote prune origin
if [ -d log ]; then
@mattslack
mattslack / pocket_readability.user.js
Last active August 10, 2017 17:11
Improve the readability on Pocket (formerly Read it Later).
// ==UserScript==
// @name Pocket Readability
// @version 1.3
// @author Matt Slack
// @description Improve the readability on Pocket (formerly Read it Later).
// @match https://getpocket.com/a/*
// ==/UserScript==
// Stolen from https://developer.mozilla.org/en-US/docs/DOM/CSSStyleSheet/insertRule
function addStylesheetRules(decls) {