Skip to content

Instantly share code, notes, and snippets.

@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 }
@chrisberkhout
chrisberkhout / mirror-apt-opengeo-org.sh
Last active November 21, 2016 17:49
A script to mirror the OpenGeo APT repository on S3 (so you still have packages for your version of the suite when OpenGeo releases a new version). Depends on `wget` and `s3cmd`.
#!/bin/bash
repo_host="apt.opengeo.org"
repo_dir="suite/v3/ubuntu"
repo_release="lucid"
echo -n "===> Please enter a bucket name: "
read -e bucket
echo "===> Confirming you have s3cmd configured..."
@chrisberkhout
chrisberkhout / pascals_triangle.rb
Created April 3, 2013 05:20
Generate a row of Pascal's triangle, in Ruby
def pt(row)
return [1] if row == 0
return [1, 1] if row == 1
last = pt(row-1)
[1] + (0..row-2).to_a.map { |i| last[i] + last[i+1] } + [1]
end