cat brain.log | less

Getting it down on `paper`

disk utilities

% List model/serial of drive.
$ /sbin/hdparm -I /dev/sda

% Find UUID of a drive.
$ ls -l /dev/disk/by-uuid/

% Show partition table information.
$ sudo fdisk -l

% Test disk read performance.
$ sudo /sbin/hdparm -tT /dev/sdb1

% Show processes performing disk I/O.
$ iotop


Add leading zeros to directory of numbered files

for a in [0-9]*.txt; do
    mv $a `printf %04d.%s ${a%.*} ${a##*.}`

Convert directory of .swf to .mp3

$ find swf/ -name '*.swf' -exec sh -c 'ffmpeg -i "{}" -vn -ar 44100 -ac 2 -ab 192k -f mp3 "mp3/$(basename "{}" .swf).mp3"' \;


Update Bash on Ubuntu Wheezy (amd64)

You may have heard about the bash security vulnerability. . You should update your systems to the latest (patched) versions of bash. The exploit also affects all busybox machines, and uncountable consumer-grade routers.

Test to see if you’re vulnerable:
$ env check='Not vulnerable' x='() { :;}; check=Vulnerable' bash -c 'echo $check'
> Vulnerable

If you see this, you’re not vulnerable:
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'

$ cat /etc/debian_version
> wheezy/sid
$ dpkg --print-architecture
> amd64

$ wget
$ wget
$ wget
$ wget

$ sudo dpkg -i libc-bin_2.15-0ubuntu10.7_amd64.deb
$ sudo dpkg -i libc6_2.15-0ubuntu10.7_amd64.deb
$ sudo dpkg -i libtinfo5_5.9-10_amd64.deb
$ sudo dpkg -i bash_4.3-9.2_amd64.deb

Test to see if you’re vulnerable:
$ env check='Not vulnerable' x='() { :;}; check=Vulnerable' bash -c 'echo $check'
> Not vulnerable

For Ubuntu distros still under support:
$ sudo apt-get clean && sudo apt-get update && sudo apt-get install -y bash

Redhat 4:
A patch has been provided by Oracle for el4 :
As it is a src RPM, you need to compile then rpmbuild. may be your best resource for obtaining out-of-support RHEL4 patches for this bash bug.

Off-site links to source:


Trigger Pylint (or PHP Syntax Checking) in Vim with Hotkeys

first: install
sudo apt-get install pylint

second: update ~/.vimrc – add the following lines:

" Enable filetype detection for per-file plugin loading.
filetype on
filetype plugin on

third: for each filetype you wish to tweak, update its ftplugin/*.vim file.

cd /usr/share/vim/vim73/ftplugin/
sudo vi python.vim

Add the following lines:

"Trigger pylint on current file by pressing ';'
noremap ; :!pylint %<CR>

sudo vi php.vim
Add the following lines:

"Trigger php syntax checking on current file by pressing ';'
noremap ; :!php -l %<CR>

Not that bad, right?


A* Algorithm Implementation

Code from:

Here for personal reference.

def heuristic(a, b):
   # Manhattan distance on a square grid
   return abs(a.x - b.x) + abs(a.y - b.y)
frontier = PriorityQueue()
frontier.put(start, 0)
came_from = {}
cost_so_far = {}
came_from[start] = None
cost_so_far[start] = 0
while not frontier.empty():
   current = frontier.get()
   for next in graph.neighbors(current):
      new_cost = cost_so_far[current] + graph.cost(current, next)
      if next not in cost_so_far or new_cost < cost_so_far[next]:
         cost_so_far[next] = new_cost
         priority = new_cost + heuristic(goal, next)
         frontier.put(next, priority)
         came_from[next] = current