Skip to content

Instantly share code, notes, and snippets.

View chriscz's full-sized avatar
🍎
vs 🍊

Chris Coetzee chriscz

🍎
vs 🍊
  • Activitar
View GitHub Profile

Built on-top of phusion/baseimage

Application is mounted at /app

  1. update-app-ids.sh
#!/bin/bash
set -eou pipefail
@chriscz
chriscz / conventional-commits-cheatsheet.md
Created August 15, 2024 05:09 — forked from qoomon/conventional-commits-cheatsheet.md
Conventional Commits Cheatsheet

Conventional Commit Messages

See how a minor change to your commit message style can make a difference.

Tip

Have a look at git-conventional-commits , a CLI util to ensure these conventions, determine version and generate changelogs

Commit Message Formats

Default

@chriscz
chriscz / ascript.sh
Last active July 22, 2024 04:22
Emoji QuickReference
# We generate a quick reference within a code block that can then be moved into your LogSeq
(echo '```' > quickref.md && curl -s https://raw.githubusercontent.com/DailyBotHQ/universal-emoji-parser/main/src/lib/emoji-lib.json | jq 'to_entries | .[] | "\(.key) -> \(.value.keywords | join(", "))"' -r >> quickref.md; echo '```' >> quickref.md)
@chriscz
chriscz / active_record_unpersisted_has_one_fix.rb
Created February 16, 2024 10:15
Fix for unpersisted has_one's through being inaccessible in Rails.
# FIXME Rails has-one through is nil on unpersisted objects (bug)
# https://github.com/rails/rails/issues/33155
module ActiveRecordUnpersistedHasOneFix
extend ActiveSupport::Concern
# Define utility methods
class << self
# @return [Array<String>, nil]
def association_path(model_class, association)
path = []
@chriscz
chriscz / vagrant-ssh-fast.sh
Created September 30, 2023 00:44
Bash script for speeding up vagrant ssh
#!/bin/bash
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
@chriscz
chriscz / yaml_autoloader.rb
Last active November 21, 2022 14:41
After the Rails 5.2.8.1 security release it's required to specify which classes are permitted for deserialization by YAML. However, when it's a high effort task to discover, it's easier to run production in "unsafe" mode for some time and collect which classes are being loaded.
# Place under initializers/yaml_autoloader.rb
class PsychLoaderPatch
include Singleton
def initialize
logfile = File.open(Rails.root.join("log/yaml_disallowed_classes.log").to_s, "a")
logfile.sync = true
@logger = Logger.new(logfile)
@chriscz
chriscz / 1_generate_certs.sh
Last active October 7, 2023 00:53 — forked from reillysiemens/signing-vbox-kernel-modules.md
Signing VirtualBox Kernel Modules
#!/usr/bin/env bash
set -eou pipefail
# This is probably waaay too long.
CERTIFICATE_VALID_DAYS=36500
NAME="$(getent passwd $(whoami) | awk -F: '{print $5}')"
OUTPUT_DIR="/root/module-signing"
KEY_FILE="${OUTPUT_DIR}/MOK.priv"
@chriscz
chriscz / Makefile
Last active July 11, 2021 21:04
Crystal Makefile which runs tests when files change
# Requires inotify-tools to be installed. On Ubuntu / Debian:
# sudo apt install inotify-tools
CRYSTAL=crystal
TEST_ARGS=--chaos --parallel 4 --verbose
SPEC_ARGS=--order=random --error-on-warnings --verbose
WATCH=src/**/*.cr spec/**/*.cr test/**/*.cr
# The make rule to use when running tests. Either spec or test
TEST_RULE=test
@chriscz
chriscz / ability.rb
Last active June 11, 2021 11:31
Add ActiveRecord::Relation support to CanCan can? check
require 'cancancan_ability_ext'
class Ability
include CanCan::Ability
include CanCanCanAbilityExt
def initialize(user)
can :clone, Post, { id: user.post_ids }
end
end