Skip to content

Instantly share code, notes, and snippets.

@chrisberkhout
chrisberkhout / README.md
Last active October 24, 2024 12:58
CyberArk Vault syslog translator file: RFC5424Changes.xsl
@chrisberkhout
chrisberkhout / depth.py
Last active August 7, 2024 15:22
Build simplifed representations of the the OCSF schema with required attributes only
#!/bin/env python
import json
import urllib.request
import argparse
def by_class(all_fields_to_depth):
url = "https://raw.githubusercontent.com/ocsf/ocsf-lib-py/main/schema_cache/schema-1.3.0.json"
schema = json.loads(urllib.request.urlopen(url).read().decode('utf-8'))
@chrisberkhout
chrisberkhout / .bash_profile
Created January 25, 2017 14:33
Git aliases taken from oh-my-zsh's git plugin and translated to bash
# git aliases - taken from oh-my-zsh's git plugin and translated to bash
# https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet#helpful-aliases-for-common-git-tasks
# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/git/git.plugin.zsh
function git_current_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
function git_current_repository() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
@chrisberkhout
chrisberkhout / ruby_foundations.rb
Created July 7, 2016 11:57
Ruby foundations quiz
# PURPOSE ######################################################################
# This exercise aims not to practice or build skills, but to quickly identify
# topics and details of the Ruby language for further review. It intentionally
# ranges from easy to things that are probably hard or unknown.
# INSTRUCTIONS #################################################################
# There are 70 small tasks. Aim to spend one hour on them. If you don't know the
# answer just move on. If you are unsure of the syntax just guess. Answer
@chrisberkhout
chrisberkhout / csort
Created March 17, 2015 10:55
wrapper to use `sort` with traditional, native byte value order (in which whitespace is significant)
#!/bin/bash
LC_ALL=C exec sort "$@"
@chrisberkhout
chrisberkhout / extralf
Created October 9, 2014 09:20
extralf: Extra Line Feed - select files with EOL-EOL-EOF
#!/bin/bash
if [ -z "$1" ] || [ "$1" = "--help" ]; then
echo "extralf: Extra Line Feed - select files with EOL-EOL-EOF"
echo "Usage: extralf FILE [FILE] [FILE]..."
echo "Example: find . -name '*.rb' | xargs extralf"
else
@chrisberkhout
chrisberkhout / notes.md
Last active January 4, 2016 21:29
Notes from Melbourne Node.JS Meetup - January

Melbourne Node.JS Meetup - January

News and events

  • CampJS III in Melbourne on May 23-26, tickets on sale now
  • JSConf (& CSSConf, & hackathon) in April, Melbourne
  • Event: RubyConfAU 2014, coming up in Sydney
  • Meetup: MelbJS meetup in Melbourne happens monthly, and is quite big, usually front end
  • Newsletter: Node Weekly, also check out Axel Rauschmeyer @rauschma
@chrisberkhout
chrisberkhout / heroku-pg-extras-bloat.sql
Last active December 21, 2022 03:16
Heroku's pg-extras queries in plain SQL (assumes pg >= v9.2)
-- show table and index bloat in your database ordered by most wasteful
-- https://github.com/heroku/heroku-pg-extras/blob/master/init.rb
WITH constants AS (
SELECT current_setting('block_size')::numeric AS bs, 23 AS hdr, 4 AS ma
), bloat_info AS (
SELECT
ma,bs,schemaname,tablename,
(datawidth+(hdr+ma-(case when hdr%ma=0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr,
(maxfracsum*(nullhdr+ma-(case when nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2
FROM (
@chrisberkhout
chrisberkhout / with_credentials.rb
Created June 21, 2013 05:33
Load credentials set by shell script into current Ruby environment - in one line
require "json"
JSON.parse(`. /etc/credentials.sh; ruby -rjson -e'puts ENV.to_hash.to_json'`).each_pair { |k,v| ENV[k] = v }