Skip to content

Instantly share code, notes, and snippets.

View chriscz's full-sized avatar
vs 🍊

Chris Coetzee chriscz

vs 🍊
  • Activitar
  • Brisbane, Australia
  • 02:13 (UTC +10:00)
View GitHub Profile
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)
module ActiveRecordUnpersistedHasOneFix
extend ActiveSupport::Concern
# Define utility methods
class << self
# @return [Array<String>, nil]
def association_path(model_class, association)
path = []
chriscz /
Created September 30, 2023 00:44
Bash script for speeding up vagrant ssh
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
SCRIPT_DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
chriscz / yaml_autoloader.rb
Last active November 21, 2022 14:41
After the Rails 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 ="log/yaml_disallowed_classes.log").to_s, "a")
logfile.sync = true
@logger =
chriscz /
Last active October 7, 2023 00:53 — forked from reillysiemens/
Signing VirtualBox Kernel Modules
#!/usr/bin/env bash
set -eou pipefail
# This is probably waaay too long.
NAME="$(getent passwd $(whoami) | awk -F: '{print $5}')"
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
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
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 }

Keybase proof

I hereby claim:

  • I am chriscz on github.
  • I am chriscz ( on keybase.
  • I have a public key whose fingerprint is 53C4 0540 6C16 09E7 F32A A341 AA42 2257 9499 8735

To claim this, I am signing this object:

chriscz / .gitignore
Last active June 12, 2022 10:53 — forked from phansch/
Improved YARD cheatsheet
# Make sure you grab the latest version
set -euo pipefail
chriscz /
Last active December 27, 2016 13:17
Snippet for signal handling in Python (useful for monitoring)
import signal
import os
import readline
from pprint import pprint
def handle_shell(signal, frame):
frames = []
while frame: