Notes

Repo for code notes etc.

Convert All S3 Objects to RRD

1
2
3
4
5
6
7
8
#!/usr/bin/env python

import boto

s3 = boto.connect_s3()
b  = boto.lookup('bucket')

[x.change_storage_class('REDUCED_REDUNDANCY') for x in b.list() if x.storage_class == 'STANDARD']

Add Authentication to Gollum

  • Create a Rack config.ru like below:
1
2
3
4
5
6
7
8
9
10
11
require 'rubygems'

require 'gollum/frontend/app'

use Rack::Auth::Basic, "Restricted Area" do |username, password|
   [username, password] == ['admin', 'admin']
end

Precious::App.set(:gollum_path, '<repo-path>')
Precious::App.set(:wiki_options, {})
run Precious::App

Add Commas to Du Output

Note this requires GAWK

  • Create commas.awk:
1
{printf "%d %s\n", $1, $2}
  • Pipe du output through commas.awk:
1
2
$ du -sk | gawk -f commas.awk
38,522,624 .

Show Git Branch via Your Bash Prompt

  • Create the Bash function below to determine what branch you are using:
1
2
3
4
function parse_git_branch {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  echo "("${ref#refs/heads/}")"
}
  • Update your PS1:
1
export PS1="\[\033[01;36m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\\[\033[01;31m\] \$(parse_git_branch)\[\033[00m\]\n\[\033[01;34m\]\$\[\033[00m\] "

Track Upstream Branch in Git

  • Show upstream remotes:
1
2
3
4
5
6
7
8
9
10
11
12
13
$ git remote show octopress
* remote octopress
  Fetch URL: git://github.com/imathis/octopress.git
  Push  URL: git://github.com/imathis/octopress.git
  HEAD branch: master
  Remote branches:
    2.1                 tracked
    gh-pages            tracked
    linklog             tracked
    master              tracked
    refactor_with_tests tracked
    rubygemcli          tracked
    site                tracked
  • Create local branch tracking upstream:
1
2
3
$ git checkout -t -b rubygemcli octopress/rubygemcli
Branch rubygemcli set up to track remote branch rubygemcli from octopress.
Switched to a new branch 'rubygemcli'