Skip to content

Instantly share code, notes, and snippets.

View kane-c's full-sized avatar

Kane kane-c

View GitHub Profile
@kane-c
kane-c / premii.user.js
Created May 8, 2024 06:59
UserScript: Premii Hacker News improvements
// ==UserScript==
// @name Premii Hacker News improvements
// @namespace github.com/kane-c
// @version 1.0.0
// @description Enhance hn.premii.com
// @author @kane-c
// @match https://hn.premii.com/
// @icon https://hn.premii.com/a/icon/hn/Icon-32.png
// @grant none
// @updateURL https://gist.github.com/kane-c/c812e42be4accb0ff1db92562f6d5bf2/raw/2196f413be8abdd3793c2ab5adef715d7ca5dea5/premii.user.js
@kane-c
kane-c / woocommerce-force-shipping-pickup.php
Created July 23, 2014 05:40
WordPress WooCommerce: Force local pickup as the only shipping option when products in the cart require it.
<?php
// Force pickup as a shipping option if one or more products in the catalog is marked as pickup only.
// To do this, add a shipping class with the slug 'pickup-only' then set products with that class as required.
// Add this script to your theme's functions.php or similar.
function hideShippingWhenPickupRequired($rates, $package)
{
foreach ($package['contents'] as $item) {
$product = $item['data'];
$shippingClass = $product->get_shipping_class();
@kane-c
kane-c / backup
Last active September 5, 2020 04:25
Simple Postgres & MySQL regular maintenance + backup script
#!/usr/bin/env bash
# Usage: backup.sh type database username host gdrive-parent-folder-id gpg-recipient
# Requires gdrive: https://github.com/prasmussen/gdrive
set -e
timeslot=$(date '+%Y%m%d%H%M')
type=$1
database=$2
user=$3
host=$4
@kane-c
kane-c / GoogleMeet.bsstrategy
Created September 4, 2018 01:58
BeardedSpice strategy to un/mute Google Meet via media keys/headphones button
//
// GoogleMeet.js
// BeardedSpice
//
// Created by @kane-c.
// Copyright (c) 2015-2017 GPL v3 http://www.gnu.org/licenses/gpl.html
//
// We put the copyright inside the plist to retain consistent syntax coloring.
# Make the Django server from LiveServerTestCase multi-threaded
# so that you can make requests to yourself during tests without
# deadlocking.
# Note that this prevents being able to use in-memory sqlite for
# tests unless you use something like `/dev/shm`
# May cause other bugs too
from django.core.servers.basehttp import WSGIServer
from django.test import testcases
from django.utils.six.moves import socketserver
@kane-c
kane-c / backup-dokku.sh
Last active July 21, 2017 04:54
Postgres backup script to be used with Docker/Dokku
#!/usr/bin/env sh
# Usage: backup.sh database username container-name drive-folder-id gpg-recipient
# Requires gdrive: https://github.com/prasmussen/gdrive
# wget 'https://docs.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA&export=download' -O /usr/local/bin/gdrive
# chmod +x /usr/local/bin/gdrive
# Store Postgres credentials in `.pgpass` and gdrive configuration in `.gdrive.conf`
# Ensure GPG is configured too
timeslot=`date '+%Y%m%d%H%M'`
user=$2
database=$1
@kane-c
kane-c / brew-upgrade.sh
Created May 16, 2017 01:17
Upgrade Brew and all installed packages including casks, then clean up
brew-upgrade() {
(set -x; brew update;)
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
casks=( $(brew cask outdated) )
for cask in ${casks[@]}
@kane-c
kane-c / git-bump
Last active August 18, 2016 06:28
Handy git shortcut scripts
#!/bin/sh -e
# Semantic versioning automatic bump and optional push
# First, add this to your `.gitconfig`
# [alias]
# max-tag = !echo $((echo $(git config --get bump.prefix)0.0.0 && git tag -l "$(git config --get bump.prefix || echo)*.*.*") | (git config --get bump.prefix && sed "s/$(git config --get bump.prefix)//g" || cat) | sort -s -t . -k 1,1n -k 2,2n -k 3,3n | tail -n 1)
# Then add this file (chmod +x) to your PATH.
# Optionally add a tag prefix (e.g. `v`) globally or per repo:
# git config --global --add bump.prefix v
@kane-c
kane-c / Preferences.sublime-settings
Created July 16, 2016 01:14
Sublime Text settings
{
"color_scheme": "Packages/User/SublimeLinter/base16-ocean.dark (SL).tmTheme",
"detect_indentation": true,
"dictionary": "Packages/Language - English/en_GB.dic",
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns":
[
".git",
".hg",
".idea",
@kane-c
kane-c / macos-update.sh
Created June 29, 2016 23:05
Update and clean stuff for macOS
#!/bin/sh
# Usage: . ./macos-update.sh (so that upgrade_oh_my_zsh works)
echo 'Updating brew'
brew update
brew upgrade --all
brew cleanup
echo 'Updating shell'
upgrade_oh_my_zsh
echo 'Updating Docker and its images'
dinghy upgrade