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##*.}`
done
 

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. https://github.com/blog/1893-security-vulnerability-in-bash-addressed . 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 http://ftp.us.debian.org/debian/pool/main/b/bash/bash_4.3-9.2_amd64.deb
$ wget http://ftp.us.debian.org/debian/pool/main/n/ncurse/libtinfo5_5.9-10_amd64.deb
$ wget http://security.ubuntu.com/ubuntu/pool/main/e/eglibc/libc-bin_2.15-0ubuntu10.7_amd64.deb
$ wget http://security.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6_2.15-0ubuntu10.7_amd64.deb

$ 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 :
https://oss.oracle.com/el4/SRPMS-updates/bash-3.0-27.0.2.el4.src.rpm
As it is a src RPM, you need to compile then rpmbuild.

Serverfault.com may be your best resource for obtaining out-of-support RHEL4 patches for this bash bug.

Off-site links to source:
http://packages.ubuntu.com/da/precise/libc-bin
http://packages.ubuntu.com/da/precise/libc6
https://packages.debian.org/wheezy/libtinfo5
https://packages.debian.org/wheezy/bash

 

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.

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

Add the following lines:

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

PHP:
sudo vi php.vim
Add the following lines:

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

Done.
Not that bad, right?

 

A* Algorithm Implementation

Code from: http://www.redblobgames.com/pathfinding/a-star/introduction.html

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