Wayne Khan

Web developer musings… and then some.

Oneiric Ocelot

Since Ubuntu is released every six months, I’ve compiled a set of instructions/shell commands to get my development environment up ASAP. This one references packages applicable to 11.10 (Oneiric Ocelot). If you use a different one, your mileage will differ!

~/.bashrc

# Android.
export PATH=${PATH}:~/android-sdk-linux/tools:~/android-sdk-linux/platform-tools

# Oracle.
alias sqlplus=’rlwrap sqlplus’
. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh
export TNS_ADMIN=${ORACLE_HOME}/network/admin

# Text editor.
export VISUAL=/usr/bin/vim

~/.screenrc

# ~/.screenrc

defscrollback 10240
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
startup_message off
vbell off

screen -t root 0
screen -t bash 1
screen -t mysql/sqlplus 2
screen -t vim 3

Package management

Oneiric ships with — in my opinion only, of course — too many packages, so customize (or completely exclude) the apt-get remove, apt-get install sections as required.

sudo apt-get remove aisleriot quadrapassel gbrainy gnome-games-common gnome-mahjongg libreoffice-* gnome-sudoku gnomine -y; \
sudo apt-get autoremove -y; \
sudo apt-get update; \
sudo apt-get upgrade -y; \
sudo apt-get install barcode git-core git-doc git-gui gnome-do imagemagick libaio1 libapache2-mod-php5 meld mysql-server phpmyadmin php-pear php5 php5-cli php5-curl php5-dev php5-ffmpeg php5-gd php5-imagick php5-mcrypt php5-mysql php5-xdebug rlwrap ruby ruby-dev screen subversion tidy vim vim-gnome xclip -y --fix-missing;

Git

ssh-keygen -t rsa
xclip -sel clip < ~/.ssh/id_rsa.pub


; ~/.gitconfig

[alias]
ci = commit
di = diff
st = status

  1. Paste the copied public key into the “Public keys” section of your git repository provider.
  2. ~/.gitconfig creates Subversion-like aliases.

Apache

The recommended method to serve PHP pages is via mod_userdir; i.e. a public_html/ from the user’s home directory; e.g. /home/kzhiwei/public_html/. The following commands enable mod_rewrite and mod_userdir.

sudo a2enmod rewrite; \
sudo a2enmod userdir;

  1. Define ServerName in /etc/apache2/httpd.conf; e.g. “localhost”.
  2. Update AllowOverride in /etc/apache/mods-available/userdir.conf to “AllowOverride All”, so URL rewriting, .htaccess files work correctly.
  3. If using CakePHP with mod_rewrite, the default .htaccess files will not working correctly. Use RewriteBase to adjust accordingly; e.g. for http://localhost/~kzhiwei/github.com/kzhiwei/sandbox/ to work correctly; e.g.
    • /.htaccess: RewriteBase /~kzhiwei/github.com/kzhiwei/sandbox/
    • /app/.htaccess: RewriteBase /~kzhiwei/github.com/kzhiwei/sandbox/app/
    • /app/webroot/.htaccess: RewriteBase /~kzhiwei/github.com/kzhiwei/sandbox/app/webroot/
  4. Update /etc/apache2/mods-available/php5.conf by commenting “php_admin_value engine Off”, so PHP in user-directories work correctly.
  5. Issue ‘sudo service apache2 restart’ when done.

~/.vimrc

"~/.vmrc

"Basics.
colorscheme koehler
set autoindent
set nowrap
set ruler
syntax on

"Tabs, not spaces.
set shiftwidth=3
set softtabstop=3
set tabstop=3

"Others.
set directory=/tmp "Place swap files in /tmp.
set hidden "Switch between unsaved buffers. Beware :q!.
set ignorecase "Case-insensitive text search...
set smartcase "... unless specified.
set term=xterm "PuTTY/Command-T compatibility.

Command-T plugin for Vim

Command-T is the one plugin I use. For working with large code bases with multiple files, it helps me open multiple buffers quickly, with a couple of keystrokes. My explanation doesn’t do it much justice, you have to give it a try yourself. If it’s the only new thing you try in 2012, this is it!

wget http://www.vim.org/scripts/download_script.php?src_id=15560 -O ~/command-t.vba; \
vim ~/command-t.vba;

Command-T is distributed as a “vimball” which means that it can be installed
by opening it in Vim and then sourcing it.

:e command-t.vba
:so %

Next the C extension is built from the shell:

cd ~/.vim/ruby/command-t/; \
ruby extconf.rb; \
make;

Assuming make is successfully, the next time you open Vim you’ll be able to use the Leader key — defaults to backslash (/) — to summon Command-T. Thereafter, inputting the path/name of the file you’re interested in, then hit Enter to open.

Oracle Express Edition (XE)

wget http://oss.oracle.com/debian/dists/unstable/non-free/binary-i386/oracle-xe-universal_10.2.0.1-1.1_i386.deb; \
sudo dpkg -i oracle-xe-universal_10.2.0.1-1.1_i386.deb; \
sudo /etc/init.d/oracle-xe configure; \
. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh; \
sudo pecl install oci8; \
sudo touch /etc/php5/conf.d/oci8.ini;

  1. When prompted to provide the path to the ORACLE_HOME directory, use ‘/usr/lib/oracle/xe/app/oracle/product/10.2.0/server’.
  2. Using oracle_env.sh to define Oracle-related environment variables mostly works correctly, except two naggy “[[: not found” errors. This can be resolved by editing lines 108, 110 of /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/nls_lang.sh and removing the extra set of brackets.
  3. Add “extension=oci8.so” to /etc/php5/conf.d/oci8.ini.
  4. Add “export LD_LIBRARY_PATH=’/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib:’; export ORACLE_HOME=’/usr/lib/oracle/xe/app/oracle/product/10.2.0/server’” to /etc/apache2/envvars so that Oracle works correctly in PHP.
  5. In case “pecl install oci8″ fails, check if php5-dev, php-pear is installed.
References

Command-T : Fast file navigation for VIM
Oracle and PHP5 in Debian-like systems

No Comments »

2011 in review

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 7,000 times in 2011. If it were a NYC subway train, it would take about 6 trips to carry that many people.

Click here to see the complete report.

No Comments »

Sitting up

Found that he could sit up fairly straight on his own now. No need to grab onto the sides of the bath tub anymore — though he still does that, a lot! It makes bathing a bit easier, good boy!

No Comments »

Teething

Was applying Dentinox to his sore gums just now; felt his first front bottom tooth. It’s sharpish, and I’m quite touched. Heh

No Comments »

MVP HOSTS file

MVP hosts is a good start if you’re looking to block advertisements-serving domains.

However, wildcard domains; e.g. “*.doubleclick.net” and sub-domains “doubleclick.net” do not work correctly. Furthermore, if you’re a network administrator — I administer my home network — the effect is not propagated for all clients.

Aside, the large filesize (~16k lines) means reduced performance, since there are entries like “activity.serving-sys.com”, “bs.serving-sys.com”. Typically, the entire domain should be blocked — although we might end up blacklisting “good” domains; e.g. “zdnet.com”, the end result is mostly desirable.

Since my TL-WR841N is fairly competent; i.e. it allows a dot-prefixed domain; e.g. “.servicing-sys.com” works correctly as expected, I wrote a script to extract, and process the contents of hosts.txt into ~7k lines, which is a bit more acceptable.

Now, I just need to figure out how to add more than 4 domains to a rule.

If you’re interested in the source, you can find it here.

No Comments »

CentOS: rpmbuild-ing Vim w/ Ruby support

Recently I switched from Ubuntu 11.04 to CentOS 5.7, only to find out that CentOS’s version of vim was build sans Ruby support:

$ vim --version | grep ruby
+python +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent

“-ruby” means that Ruby support is not available. This was an unhappy moment, as I’d been a big fan of Command-T, an excellent plugin for Vim requiring Ruby support. There are a couple of blog posts about it, but required consolidation, so here is my (mostly) repost on the solution.

The posts recommend setting up an “rpmbuild” environment for building from source, which is basically user “rpmbuild”, plus a “~/.rpmmacros” definition, plus the source RPM.

1. If “rpmbuild” already exists, the following part is not required:

# useradd rpmbuild

2. Now switch to “rpmbuild”:

# su - rpmbuild
$ vim ~/.rpmmacros

3. “.rpmmacros” is a file with the following contents:

%_topdir /home/rpmbuild/rpm
%_tmppath /home/rpmbuild/rpm/tmp

4. My build is for x86_64, so replace “$ARCH” with “x86_64″:

$ mkdir -p rpm/{BUILD,RPMS/$ARCH,RPMS/noarch,SOURCES,SRPMS,SPECS,tmp}
$ mkdir -p rpm/{BUILD,RPMS/x86_64,RPMS/noarch,SOURCES,SRPMS,SPECS,tmp}

5. Next, get the source RPM, removing the “perl-devel” dependency from “vim.spec”:

$ cd rpm/SRPMS
$ wget http://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/vim-7.2.411-1.6.el6.src.rpm
$ cd ~
$ rpm -Uvh --nomd5 ~/rpm/SRPMS/vim-7.2.411-1.6.el6.src.rpm
$ vim rpm/SPECS/vim.spec

BuildRequires: python-devel ncurses-devel gettext perl-devel
BuildRequires: python-devel ncurses-devel gettext

6. Now we are ready to start the build process:

$ rpmbuild -bb ~/rpm/SPEC/vim.spec

7. If “rpmbuild” is not installed — mine wasn’t — use “root” to install “rpm-build” first:

# yum install -y rpm-build

8. Assuming #6 completed successfully, we can use “root” to install the built RPMs:

rpm -Uvh ~/rpm/RPMS/x86_64/vim-{m,c,e}*

References

http://m.linuxweblog.com/vim-ruby-centos

http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment

http://www.lamolabs.org/blog/2662/fixing-ruby-support-in-vim-on-fedora-10-11-and-centos-5-installing-the-vim-textile-plugin/

No Comments »

PHP 4.3.9 $_SESSION values not being retained

Symptoms: After calling session_start() and assigning key-value pairs to $_SESSION, calling print_r($_SESSION) on subsequent pages result in an empty array; i.e. $_SESSION values are not retained across pages.

Solution: Assuming your php.ini (session) save_handler, save_path variables are set correctly, also check if sufficient disk space is available.

I spent 90 minutes trying to resolve the problem thinking it was a PHP-related issue, but in the end, nullifying the 5+ GiB of httpd error logs promptly resolved the problem. Doh!

HTH,
Wayne

No Comments »

The mystery of the disappearing laptop screen brightness slider (Windows 7)

I noticed this problem in the last 2 weeks or so, but searching around the ‘net returned no results.

So I noticed that if the power plug turned off during bootup, I would be unable to adjust my screen brightness. To resolve the problem, a restart — with the power plugged in — was required.

Right-clicking the Power system icon — located on the bottom right of the task bar, clicking Power Options -> High Performance -> Change plan settings showed just two options: “Turn off the display”, “Put the computer to sleep”. “Adjust plan brightness” had disappeared!

The solution is:

Start -> Control Panel -> Hardware and Sound -> Device Manager.

In the Device Manager window, look for “Monitors”, then right-click your monitor and select “Uninstall”. Be sure to also check the “Remove driver” option. Once removed, click the “Scan for hardware changes” icon.

Voila. “Adjust plan brightness” returns, mystery solved.

References

http://social.technet.microsoft.com/Forums/en-US/w7itprohardware/thread/08a3eb1d-b698-4639-af4b-5278b721fcdc/

11 Comments »

Synaptic games deinstall for Xubuntu 10.04

Copy the following text for use w/ Synaptic when marking game-related packages for deinstall in Xubuntu 10.04. It may also work with other GNOME2-based, Ubuntu derivatives. The alternate installer does not provide the option to mark/unmark any packages at inastall time, hence the need for this.

aisleriot deinstall
quadrapassel deinstall
gnome-mahjongg deinstall
gnome-games-common deinstall
gnome-sudoku deinstall
gnomine deinstall

Alternatively:

$ sudo apt-get remove aisleriot quadrapassel gnome-mahjongg gnome-games-common gnome-sudoku gnomine -y
2 Comments »

TrueHoop’s Stat Geek Smackdown 2011

So now that the real NBA session is taking place, here are my annual predictions for the playoffs. In terms of scoring, I get 5 points if I correctly pick the winner of the series, 7 points if I correctly pick the winner of a series in the specified number of games (e.g. 4 through 7 inclusive), and none if I incorrectly pick the winner of a series.

First Round (29)

MEM @ SAS: SAS in 5 (0, MEM advances in 6).
NOH @ LAL: LAL in 5 (5, LAL advances in 6).
POR @ DAL: POR in 6 (0, DAL advances in 6).
DEN @ OKC: OKC in 6 (5, OKC advances in 5).
IND @ CHI: CHI in 5 (7, CHI advances in 5).
PHI @ MIA: MIA in 5 (7, MIA advances in 5).
NYK @ BOS: BOS in 5 (5, BOS advances in 4).
ATL @ ORL: ORL in 5 (0, ATL advances in 6).

After the First Round, I have 29 points, 7 behind Benjamin Morris of Skeptical Sports.

Conf. Semis (17)

MEM @ OKC: OKC in 6 (5, OKC advances in 7).
DAL @ LAL: LAL in 6 (0, DAL advances in 0).
ATL @ CHI: CHI in 6 (7, CHI advances in 6).
BOS @ MIA: MIA in 6 (5, MIA advances in 5).

After the conference semi-finals, I’ve entered a 3-way tie for the lead with Stephen Ilardi and Benjamin Morris.

Conf. Finals (5)

CHI vs. MIA: MIA in 7 (5, MIA advances in 5).
OKC vs. DAL: OKC in 7 (0, DAL advances in 5).

After the conference finals, I now tally 51 points, dropping several places off the lead (65). My consistent picks against DAL has worked against me, but MIA must ultimately prevail!

Finals (0)

MIA vs. DAL: MIA in 6 (0, DAL wins in 6).

I made 4 picks against DAL, and they were all wrong My final position . Sigh. Oh well. There is always next year. Congratulations to Kidd, Nowitzki, Chandler & Co., NBA champions for 2010/2011, and to Benjamin Morris who tallied 68 points in Truehoop’s Stat Geek Smackdown 2011!

References

  1. http://sports.espn.go.com/nba/playoffs/2011/news/story?page=Smackdown-11
  2. http://kzhiwei.wordpress.com/2010/04/17/truehoops-stat-geek-smackdown-2010/
  3. http://kzhiwei.wordpress.com/2009/04/29/truehoops-stat-geek-smackdown-2009/
No Comments »

Follow

Get every new post delivered to your Inbox.