Software Projects

Setting up X11 Forwarding on Ubuntu

Posted in Uncategorized by rmtheis on July 22, 2011

Edit /etc/ssh/ssh_config to contain the following:

ForwardX11 yes

Now you can connect from a remote location by doing:

ssh -X user@hostname

set DISPLAY localhost:0.0

Test the X11 forwarding:

xclock &

Setting Up an sftp Site on Amazon Web Services EC2, and a Guest Account

Posted in Uncategorized by rmtheis on July 3, 2011

(Adapted from and

This consists of three parts:

  • setting up an sftp site on EC2
  • creating a new user account
  • configuring the new user account to do read-only ftp, with no ssh privileges

This is intended for transferring files to and from trusted users. I use this as an adequate solution for occasionally sending very large files to clients, using an EC2 instance dedicated to that task. After the transfer is complete, I shut down or delete the instance.

Set up a server using Amazon Web Services EC2, choosing an Ubuntu Amazon Machine Image (AMI). (You can find an AMI using You may want to choose one that’s free tier eligible, such as ami-1aad5273)

ssh into the server:

ssh -i keyfile.pem

Install vsftpd:

sudo apt-get install vsftpd

Create a new user:

sudo adduser newusername

Using the AWS Management Console, generate a new key pair for the third-party user.

Using puttygen, import the new key (keyname.pem) and copy its public key.

On the server, create the .ssh directory for the new user:

sudo mkdir /home/newusername/.ssh

Paste the public key into /home/newusername/.ssh/authorized_keys.

Set permissions:

sudo chmod 700 /home/newusername/.ssh

sudo chmod 600 /home/newusername/.ssh/authorized_keys

sudo chown -R newusername:newusername /home/newusername/.ssh

Test the new user’s sftp login from your local machine:

sftp -o IdentityFile=newkeypair1.pem

Make a new group for users who should be limited to using only sftp:

sudo groupadd sftponly

sudo adduser newusername sftponly

Edit /etc/ssh/sshd_config and change the Subsystem line to:

Subsystem sftp internal-sftp

and add these lines to the end of /etc/ssh/sshd_config:

Match group sftponly
ChrootDirectory /home/%u
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

Set permissions, without clobbering files necessary for EC2’s key-based authentication:

sudo chown root:root /home/newusername

sudo chown -R newusername:newusername /home/newusername/.ssh

sudo /etc/init.d/ssh restart

Now the new user can connect by sftp, but not by ssh. Place the files you want to share in /home/newusername, and share the key with the user.

Search for a Package Using apt-get

Posted in Uncategorized by rmtheis on June 25, 2011

sudo apt-cache search some-software-name

Setting up a Static IP Address and Enabling ssh on Ubuntu

Posted in Uncategorized by rmtheis on June 25, 2011

To use a static IP address, edit /etc/network/interfaces to contain:

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address <IP address>
netmask <value, which is sometimes>
network <value, sometimes same as IP but ending with .0>
broadcast <value, sometimes same as IP but ending with .255>
gateway <value, sometimes same as IP but ending with .254>

# The loopback network interface
auto lo
iface lo inet loopback

To install ssh:

sudo apt-get install openssh-server

This should configure the ssh service to be automatically started during boot.

Arabic glyph support test

Posted in Uncategorized by rmtheis on June 13, 2011

Full stop: ۔

1536: ؀
1537: ؁
1538: ؂
1539: ؃
1540: ؄
1541: ؅
1542: ؆
1543: ؇
1544: ؈
1545: ؉
1546: ؊
1547: ؋
1548: ،
1549: ؍
1550: ؎
1551: ؏
1552: ؐ
1553: ؑ
1554: ؒ
1555: ؓ
1556: ؔ
1557: ؕ
1558: ؖ
1559: ؗ
1560: ؘ
1561: ؙ
1562: ؚ
1563: ؛
1564: ؜
1565: ؝
1566: ؞
1567: ؟
1568: ؠ
1569: ء
1570: آ
1571: أ
1572: ؤ
1573: إ
1574: ئ
1575: ا
1576: ب
1577: ة
1578: ت
1579: ث
1580: ج
1581: ح
1582: خ
1583: د
1584: ذ
1585: ر
1586: ز
1587: س
1588: ش
1589: ص
1590: ض
1591: ط
1592: ظ
1593: ع
1594: غ
1595: ػ
1596: ؼ
1597: ؽ
1598: ؾ
1599: ؿ
1600: ـ
1601: ف
1602: ق
1603: ك
1604: ل
1605: م
1606: ن
1607: ه
1608: و
1609: ى
1610: ي
1611: ً
1612: ٌ
1613: ٍ
1614: َ
1615: ُ
1616: ِ
1617: ّ
1618: ْ
1619: ٓ
1620: ٔ
1621: ٕ
1622: ٖ
1623: ٗ
1624: ٘
1625: ٙ
1626: ٚ
1627: ٛ
1628: ٜ
1629: ٝ
1630: ٞ
1631: ٟ
1632: ٠
1633: ١
1634: ٢
1635: ٣
1636: ٤
1637: ٥
1638: ٦
1639: ٧
1640: ٨
1641: ٩
1642: ٪
1643: ٫
1644: ٬
1645: ٭
1646: ٮ
1647: ٯ
1648: ٰ
1649: ٱ
1650: ٲ
1651: ٳ
1652: ٴ
1653: ٵ
1654: ٶ
1655: ٷ
1656: ٸ
1657: ٹ
1658: ٺ
1659: ٻ
1660: ټ
1661: ٽ
1662: پ
1663: ٿ
1664: ڀ
1665: ځ
1666: ڂ
1667: ڃ
1668: ڄ
1669: څ
1670: چ
1671: ڇ
1672: ڈ
1673: ډ
1674: ڊ
1675: ڋ
1676: ڌ
1677: ڍ
1678: ڎ
1679: ڏ
1680: ڐ
1681: ڑ
1682: ڒ
1683: ړ
1684: ڔ
1685: ڕ
1686: ږ
1687: ڗ
1688: ژ
1689: ڙ
1690: ښ
1691: ڛ
1692: ڜ
1693: ڝ
1694: ڞ
1695: ڟ
1696: ڠ
1697: ڡ
1698: ڢ
1699: ڣ
1700: ڤ
1701: ڥ
1702: ڦ
1703: ڧ
1704: ڨ
1705: ک
1706: ڪ
1707: ګ
1708: ڬ
1709: ڭ
1710: ڮ
1711: گ
1712: ڰ
1713: ڱ
1714: ڲ
1715: ڳ
1716: ڴ
1717: ڵ
1718: ڶ
1719: ڷ
1720: ڸ
1721: ڹ
1722: ں
1723: ڻ
1724: ڼ
1725: ڽ
1726: ھ
1727: ڿ
1728: ۀ
1729: ہ
1730: ۂ
1731: ۃ
1732: ۄ
1733: ۅ
1734: ۆ
1735: ۇ
1736: ۈ
1737: ۉ
1738: ۊ
1739: ۋ
1740: ی
1741: ۍ
1742: ێ
1743: ۏ
1744: ې
1745: ۑ
1746: ے
1747: ۓ
1748: ۔
1749: ە
1750: ۖ
1751: ۗ
1752: ۘ
1753: ۙ
1754: ۚ
1755: ۛ
1756: ۜ
1757: ۝
1758: ۞
1759: ۟
1760: ۠
1761: ۡ
1762: ۢ
1763: ۣ
1764: ۤ
1765: ۥ
1766: ۦ
1767: ۧ
1768: ۨ
1769: ۩
1770: ۪
1771: ۫
1772: ۬
1773: ۭ
1774: ۮ
1775: ۯ
1776: ۰
1777: ۱
1778: ۲
1779: ۳
1780: ۴
1781: ۵
1782: ۶
1783: ۷
1784: ۸
1785: ۹
1786: ۺ
1787: ۻ
1788: ۼ
1789: ۽
1790: ۾
1791: ۿ

Ubuntu VirtualBox Development Environment Setup

Posted in Uncategorized by rmtheis on June 2, 2011

To start fresh after encountering problems like bugs in VirtualBox’s snapshots/clones crashing the VM, the following are my notes for installing a clean-slate Ubuntu dev environment on a VirtualBox VM. These instructions work on my computer, and are a work in progress. Some instructions are for Ubuntu 11.04, and some are for Ubuntu 12.04.

Create new VM

Start VM and Install Ubuntu from ISO. Choose Download updates while installing. If computer name causes a problem, do Back then Forward, and the problem should disappear. Name=first name, Login=last name.

When prompted to restart, do Devices->CD/DVD Drive->Eject disk from virtual drive, and shut down VM

Configure VM Settings and Host/Guest Shared Folders:

Settings: System->Processor->8 CPUs
System->Acceleration->Enable VT-x
Display->Video Memory: Increase to max
Display->Video: Enable 3D Acceleration
USB->USB Device Filters->Add and choose handset hardware that’s connected to USB
USB->USB Device Filters->Add Empty Filter
Shared Folders: Add Folder Path to C:\eclipse-workspace on host
Check the checkbox for Auto-mount (Folder will be automatically mounted as /media/sf_eclipse-workspace on the Ubuntu guest system owned by root, and is mountable using mkdir ~/eclipse-workspace;sudo mount.vboxsf -o fmode=0777,dmode=0777 eclipse-workspace /home/username/eclipse-workspace/)
[Modification: don’t choose Auto Mount, just choose Make Permanent, and mount by doing the edit listed below to /etc/rc.local.]

Start VM
(Note message saying “It seems that you do not have the hardware required to run Unity…”)

Switch to Gnome classic desktop
Disable the screen saver and screen lock, and power management in System->Preferences->Screensaver or do

gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
gsettings set org.gnome.desktop.screensaver lock-enabled false

Disable startup sound in System->Preferences->Startup Applications Preferences->GNOME Login Sound
Disable login sound in System->Administration->Login Screen, and choose “Ubuntu Classic” as window manager
Install updates in Update Manager
Restart Ubuntu

Ensure packages are updated:

sudo apt-get update
sudo apt-get upgrade

Do Devices->Install Guest Additions for copy/paste support. Ignore the message saying “the headers for the current running kernel were not found.”

Install packages:

sudo apt-get install vim chromium-browser eclipse-platform libarchive-zip-perl libtext-csv-xs-perl libxml-simple-perl git-core subversion mercurial ia32-libs conky-all proguard gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z1-dev libgl1-mesa-dev libarchive-zip-perl libfile-find-rule-perl subversion build-essential g++ pkg-config gawk libxml2 libxml2-dev libxml2-utils xsltproc flex automake autoconf libtool libpcre3-dev maven2

Set Nautilus preferences: List view
Set Terminal preferences: Scrolling->Unlimited, Use custom default terminal size: 120 columns, 60 rows
Add the Eclipse and Chromium launchers to the panel
Set up Chrome preferences/sync/authentication, Firefox preferences
Restart Ubuntu

Install Android SDK:

Restart Ubuntu

Install Android ADT Plugin for Eclipse:
Put in Eclipse->Help->Install New Software…
If this step fails with “There are no categorized items” or “There are no items available,” re-run as “eclipse -clean” and try this step again

Set location of Android SDK in Eclipse Window->Preferences->Android->SDK Location

Restart Ubuntu

Start Android SDK and AVD Manager and install all packages (except Real3D by LG, because its download speed is slow)

Install Android NDK

Install Subclipse: Eclipse->Help->Install New Software->

Install EGit: Eclipse->Help->Eclipse Marketplace->egit

Edit ~/.ssh/config (and add keystore as a read-only shared folder):
IdentityFile ~/keystore/github-id_rsa

Set up git:
git config --global "Your Name"
git config --global

Install vim-instant-markdown:
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
sudo gem install redcarpet pygments.rb
sudo npm -g install instant-markdown-d

Add to ~/.bashrc:

PATH=$PATH:/home/$USER/android-ndk-rXX [where XX is 5c, for example]
export PATH

Add shared folder mount to /etc/rc.local:
sudo mount.vboxsf -o fmode=0777,dmode=0777 eclipse-workspace /home/username/eclipse-workspace/

Configure to log in automatically in System->Administration->Login Screen Settings

Test: Set handset to “PC Mode” and do “adb devices” to check if attached

Add conky to System->Preferences->Startup Applications

Configure conky system monitor panel

Save the following lines as ~/.conkyrc:

background yes
use_xft yes
xftfont 123:size=8
xftalpha 0.1
update_interval 0.5
total_run_times 0
own_window yes
own_window_type normal
own_window_transparent no
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 250 5
maximum_width 400
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_color white
default_shade_color red
default_outline_color green
alignment top_left
gap_x 10
gap_y 10
no_buffers no
uppercase no
cpu_avg_samples 2
net_avg_samples 1
override_utf8_locale yes
use_spacer yes
text_buffer_size 256


${voffset -10}
${color DimGray}
${font Arial:bold:size=10}${color Tan1}SYSTEM ${color DarkSlateGray} ${hr 2}
$font${color DimGray}$sysname $kernel $alignr $machine
Intel Pentium D $alignr${freq_g cpu0}Ghz
Uptime $alignr${uptime}
File System $alignr${fs_type}

${font Arial:bold:size=10}${color Tan1}PROCESSORS ${color DarkSlateGray}${hr 2}
$font${color DimGray}Core 1 ${cpu cpu1}% ${cpubar cpu1}
Core 2 ${cpu cpu2}% ${cpubar cpu2}
Core 3 ${cpu cpu3}% ${cpubar cpu3}
Core 4 ${cpu cpu4}% ${cpubar cpu4}

${font Arial:bold:size=10}${color Tan1}MEMORY ${color DarkSlateGray}${hr 2}
$font${color DimGray}MEM $alignc $mem / $memmax $alignr $memperc%

${font Arial:bold:size=10}${color Tan1}HDD ${color DarkSlateGray}${hr 2}
$font${color DimGray}/home $alignc ${fs_used /home} / ${fs_size /home} $alignr ${fs_free_perc /home}%
${fs_bar /home}
/disk $alignc ${fs_used /media/disk} / ${fs_size /media/disk} $alignr ${fs_free_perc /media/disk}%
${fs_bar /media/disk}
/disk-1 $alignc ${fs_used /media/disk-1} / ${fs_size /media/disk-1} $alignr ${fs_free_perc /media/disk-1}%
${fs_bar /media/disk-1}

${font Arial:bold:size=10}${color Tan1}TOP PROCESSES ${color DarkSlateGray}${hr 2}
${color DimGray}$font${top_mem name 2}${alignr}${top mem 2} %
$font${top_mem name 3}${alignr}${top mem 3} %
$font${top_mem name 4}${alignr}${top mem 4} %
$font${top_mem name 5}${alignr}${top mem 5} %

${font Arial:bold:size=10}${color Tan2}NETWORK ${color DarkSlateGray}${hr 2}
$font${color DimGray}IP on eth0 $alignr ${addr eth0}

Down $alignr ${downspeed eth0} kb/s
Up $alignr ${upspeed eth0} kb/s

Downloaded: $alignr ${totaldown eth0}
Uploaded: $alignr ${totalup eth0}

Add .vimrc:

Install Oracle JDK 7:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Perl subroutine for building a GFF3-formatted key-value pair string

Posted in Uncategorized by rmtheis on April 23, 2011

This Perl subroutine creates strings for writing to the ninth column (the “attributes” column) of a GFF format file.

Start with a hash of the keys/values you want to add to the GFF3 attributes column. When calling the subroutine, pass it a reference to your hash like this:

my $attribs = &stringconcat(\%keyvalue);

The hash indices and hash values will respectively become the tags and values in the returned string.

# Forms a concatenated string of key/value pairs given a reference to
# a hash of key/value pairs.
# Return value:
#  A string with the key/value pairs concatenated with '=' and ';',
#  for example, "key1=value1;key2=value2;key3=value3" and with
#  the "Name" and "ID" key/value pairs at the beginning as required by
#  Apollo.
sub stringconcat {
  my(%keyvalue) = %{$_[0]};

  # Put the "ID" and "Name" fields at the beginning
  my $attribs = "";
  if (exists $keyvalue{'ID'}) {
    $attribs .= "ID=$keyvalue{'ID'}";
  if (exists $keyvalue{'Name'}) {
    if (exists $keyvalue{'ID'}) {
      $attribs .= "\;";
    $attribs .= "Name=$keyvalue{'Name'}";

  # Form a string from the remaining key/value pairs
  foreach my $key (keys %keyvalue) {
    if ($key eq "Name" || $key eq "ID") {
    $attribs .= "\;$key=$keyvalue{$key}";
    print "$key=$keyvalue{$key}\n" if DEBUG;
  print "\n" if DEBUG;
  return $attribs;

Using this code snippet puts the “Name” and “ID” attributes first in the list, which seems to be required by Apollo in order to open the GFF file at all.

Cloning a VirtualBox Virtual Machine

Posted in Uncategorized by rmtheis on April 12, 2011

(Adapted from

cd "C:\Users\Username\VirtualBox VMs\Gentoo32-1"
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd Gentoo32-1.vdi "Gentoo32-1 clone.vdi"

Excel VBScript Arithmetic Rounding Function

Posted in Uncategorized by rmtheis on March 30, 2011


' Asymmetric arithmetic rounding - rounds .5 up always.
Function AsymArith(ByVal X As Double, _
    Optional ByVal Factor As Double = 1) As Double
    End Function
    AsymArith = Int(X * Factor + 0.5) / Factor
End Function

Gentoo x86 Linux Installation on a VirtualBox Image

Posted in Uncategorized by rmtheis on March 14, 2011

UPDATE: now has a one-page “quick install guide” that covers the Gentoo installation.
(Adapted from: This is a work in progress.)

Download VirtualBox. Get the appropriate version–your computer’s current operating system is the host OS for Virtualbox.

Download the ISO minimal installer for Gentoo x86 from this directory, getting the file install-x86-minimal-xxxxxxxx.iso:

Start the Virtualbox image, and select the ISO file as the installation media

Set up networking, choosing wired or wireless according to on your own computer’s network setup:

net-setup eth0

Test networking:


Create the boot partition:

fdisk /dev/sda

Create the swap partition:


Create the root partition:


Apply the ext2 filesystem to the boot partition:

mke2fs /dev/sda1

Apply the ext3 filesystem to the root partition:

mke2fs -j /dev/sda3

Create a swap signature and activate the swap partition:

mkswap /dev/sda2
swapon /dev/sda2

Mount the partitions:

mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda1 /mnt/gentoo/boot

Check the date:


Download and unpack the latest stage 3 tarball at the Gentoo mountpoint, getting the file stage3-i686-xxxxxxxx.tar.bz2:

cd /mnt/gentoo
tar xvjpf stage3-*.tar.bz2

Download portage from a mirror and install:

tar xvjf portage-latest.tar.bz2 -C /mnt/gentoo/usr

Don’t reconfigure any compile options

Choose a mirror for Gentoo base system installation

mirrorselect -i -o >> /mnt/gentoo/etc/make.conf

Copy DNS config

cp -L /etc/resolv.conf /mnt/gentoo/etc/

Mount filesystems for installation:

mount -t proc none /mnt/gentoo/proc
mount --rbind /dev /mnt/gentoo/dev

Change from installation CD to installation system

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

Update system

emerge --sync

Choose the eselect profile for “desktop/gnome”:

eselect profile list
eselect profile set 3

Update make.conf:

nano -w /etc/make.conf

Change variables in make.conf:

USE="firefox gnome gtk icu kdrive python sqlite -qt4 threads"

Set your locale by uncommenting the two en_US entries and doing locale-gen

nano -w /etc/locale.gen

Set the time zone

cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Install a kernel source

emerge gentoo-sources

Automatically configure and compile kernel source

emerge genkernel
zcat /proc/config.gz > /usr/share/genkernel/arch/x86/kernel-config
genkernel all


Don’t auto-load any kernel modules

Configure filesystem information

nano -w /etc/fstab

Insert these lines into fstab:

/dev/sda1   /boot        ext2    defaults,noatime     1 2
/dev/sda2   none         swap    sw                   0 0
/dev/sda3   /            ext3    noatime              0 1
/dev/cdrom  /mnt/cdrom   auto    noauto,user          0 0

proc        /proc        proc    defaults             0 0
shm         /dev/shm     tmpfs   nodev,nosuid,noexec  0 0

Set computer name

nano -w /etc/conf.d/hostname



Set the domain and DHCP:

nano -w /etc/conf.d/net


config_eth0=( "dhcp" )

Set to automatically start networking at boot

ln -s /etc/init.d/net.lo /etc/init.d/net.eth0

rc-update add net.eth0 default

Set up the hosts file

nano -w /etc/hosts

Insert: mycomputername localhost

Set the root password


Don’t edit /etc/rc.conf
Don’t edit /etc/conf.d/keymaps

Set clock options (set CLOCK to “UTC” for dual boot with Windows, non-Virtualbox)

nano -w /etc/conf.d/hwclock



Install system logger

emerge syslog-ng


Add system logger to update list:

rc-update add syslog-ng default

Install cron daemon

emerge vixie-cron
rc-update add vixie-cron default

Install file indexing

emerge mlocate

Install DHCP client

emerge dhcpcd

Install bootloader and configure

emerge grub
nano -w /boot/grub/grub.conf


default 0
timeout 30

title Gentoo Linux 2.6.36-r5
root (hd0,0)
kernel /boot/kernel-genkernel-x86-2.6.36-gentoo-r5 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=/dev/sda3
initrd /boot/initramfs-genkernel-x86-2.6.36-gentoo-r5

## Only in case you want to dual-boot
#title Windows XP
#rootnoverify (hd0,5)
#chainloader +1

grep -v rootfs /proc/mounts > /etc/mtab
grub-install --no-floppy /dev/sda

Unmount the partitions:

umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo

Shut down the system:

shutdown -h now

On VirtualBox, remove the installation disk from virtual drive, or change the boot order so you don’t boot from the installation CD.

Add a user: restart the VirtualBox image, log in as root and do:

useradd -m -G users,wheel,audio -s /bin/bash newusername
passwd newusername

Update applications and dependencies

emerge --sync

Remove stage 3 tarball and Portage snapshot

rm /stage3-*.tar.bz2*
rm /portage-latest.tar.bz2*

Install vi:

emerge vim

Update make.conf:

nano -w /etc/make.conf

Set variables in make.conf:

USE="firefox gnome gtk icu kdrive python sqlite -qt4 threads"


Attempt to add video drivers:

emerge --config nvidia-drivers

Install VirtualBox Guest Additions:

emerge virtualbox-guest-additions

Install GNOME:

emerge gnome


Configure settings for GNOME:

/etc/init.d/dbus start

rc-update add dbus default

echo "exec gnome-session" > ~/.xinitrc

sed -i '1i\export XDG_MENU_PREFIX=gnome-' ~/.xinitrc


Exit GDM

rc-update add xdm default

Add to /etc/conf.d/xdm:


Install Chromium:

export ACCEPT_KEYWORDS="~x86"

emerge -av www-client/chromium



Clone the VirtualBox VM for backup purposes.