Skip to content

Instantly share code, notes, and snippets.

View chriscz's full-sized avatar
🍎
vs 🍊

Chris Coetzee chriscz

🍎
vs 🍊
  • Activitar
  • Brisbane, Australia
  • 06:15 (UTC +10:00)
View GitHub Profile
@chriscz
chriscz / signalhandling.py
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:
#!/bin/bash
# https://gist.github.com/sofyanhadia/37787e5ed098c97919b8c593f0ec44d8
# Make sure you grab the latest version
set -euo pipefail
VERSION='3.5.1'
FILENAME=protoc-${VERSION}-linux-x86_64.zip
INSTALL="/opt/protobuf/protoc-${VERSION}"
CURRENT="/opt/protobuf/current"

Keybase proof

I hereby claim:

  • I am chriscz on github.
  • I am chriscz (https://keybase.io/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
chriscz / timewn.py
Last active January 6, 2021 02:35
A python script to notify you of your current TimeWarrior task
#!/usr/bin/env python
# Notifies the user of the curently active TimeWarrior task every m minutes (default 10min).
# Requirements
# - python 2.7
# - pynotify
# Usage:
# python timewn.py [optional seconds]
import sys
import pynotify
@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
@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 / mucow.c
Last active November 14, 2021 21:07
Dirty COW PoC with multipage support
/*
* Multipage COW PoC
*/
#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/stat.h>
@chriscz
chriscz / filemonitor.py
Last active April 8, 2022 15:20
Python snippet for monitoring where files were opened
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
@chriscz
chriscz / .gitignore
Last active June 12, 2022 10:53 — forked from phansch/yardoc_cheatsheet.md
Improved YARD cheatsheet
index.html
@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)