A Proposal for Phoenix's Transit Network

Tags:

[caption id="attachment_988" align="alignnone" width="300"]Proposed System Map Proposal for a Valley-wide Phoenix Transit System, showing expanded METRO, heritage streetcars, and commuter and regional rail. Also available in PDF format for printing[/caption]

Shortly after the December 2008 opening of METRO, Phoenix Arizona's new trolley system, I wrote several documents in an effort to raise awareness of the need for better station names, and better Valley-wide transit planning. I have updated these after several requests following an article in the Arizona Republic ("Next stop: Better light-rail station descriptions" by Amy B Wang, Tuesday Aug 20, 2013).

The diagram above shows a complete proposed eventual build-out of the Phoenix transit system, commuter rail, regional rail, and Amtrak services -- showing proper station names, streetcar ("light rail") lines with color-names, and heritage streetcar ("trolley") service in Phoenix. The Tempe streetcar ("Trolley") is not shown, but is suggested to be built south along Rural Rd. to Southern Ave, thence east via Fiesta Mall to Country Club, connecting at its east end to the Red Line to downtown Chandler.

These recommendations are based on my experience using transit all over America and Europe since the 1970s. I would be pleased if you get these to whoever would benefit. I would be happy to answer any questions. Please email me or telephone (+1) 480-947-6100.

Importing an existing heritage project into Git

Tags:

For many years I have kept my projects in various archive directories. Now I am converting most of them to git, as a useful means of version control and because it's convenient to use with my repositories on GitHub and BitBucket.

Here is an amusing little Bash script which may help you create and populate new git repositories, with existing file history based on the files' dates.

#!/usr/bin/bash

# call as:
#   git-create.sh myfile.pl.*
# Assuming a directory containing files
    # myfile.pl.20090627
    # myfile.pl.20101202
    # myfile.pl.20120123
    # myfile.pl.20120409
    # myfile.pl.20130123
    # myfile.pl.20130220
    # myfile.pl.20130817
# ...or any set of files where the final extension part is different,
# we want to:
# * create a git repository, if it does not already exist
# * delete the existing myfile.pl~
# * for each of the files on the command line, remove the final
#   extension (date part) so the file is renamed to (in this example)
#   myfile.pl
# * "git add" the first myfile.pl to the repository
# * "git commit" each of the versions, using the file's date as the
#   "Author Date" of the commit.
# * When finished, rename myfile.pl~ back to myfile.pl

if [ ! -e .git -a ! -d .git ]
then
  echo "Creating Git Repository"
  git init
fi

firstfile=$(basename "$1")
base="${firstfile%.*}"

# If both primary and backup file exist -- erase the backup.
# (If only backup file exists, it will remain after)
if [ -e "${base}~" -a -e "${base}" ]
then
  rm "${base}~"
fi

if [ -e "${base}" ]
then
    mv "${base}" "${base}~"
    backup=1
fi

firsttime=1

# OK now we have clearance to start renaming and committing files.

for oldfile in "$@"
  do
    newfile="${oldfile%.*}"

    mv "$oldfile" "$newfile"
    if [ $firsttime ]
    then
        # Add the file, if not already in git
        git add "${newfile}"
        firsttime=0
    fi

    git commit --date="`stat -c %y $newfile`" "$newfile" -m "Automatic import (update comment later!)"
  done

A more useful Numpad on Linux

Tags:

I put this into my ~/.bash_profile

xmodmap -e "keysym KP_Add = comma"
xmodmap -e "keysym KP_Divide = BackSpace"
xmodmap -e "keysym KP_Multiply = Tab"

Now the numpad has a backspace, tab, and comma key! This makes it really useful for data entry in LibreOffice.

Virtualmin, MariaDB, and NginX on Debian 7

Tags:

Installing Debian 7

If you're on a local machine or virtual machine, you will want to download the Net Install image from here. If you're on Linode or another VPS (virtual private server), use their installation copy of Debian 7.

Create an ordinary user if you haven't already. Let's call him george.

  1. First, if your system is local and you need to know its IP address, find it with: ip addr

  2. From a terminal on your regular machine, log in to your new server with SSH, as your ordinary user. Then install sudo, which we use even at the expense of a little typing, so all your commands stay in your ~/.bash_history -- install it like this: su apt-get install sudo and set your ordinary user to be in the sudo group (see /etc/sudoers for details): addgroup -G sudo george

  3. Exit the root shell. Create (mkdir) a temporary directory under your home directory and move (cd) into it. Download the Virtualmin install script into there by running wget http://software.virtualmin.com/gpl/scripts/install.sh

  4. Now change the permissions of the install script to make it executable, and copy it to the global /opt directory chmod 744 install.sh sudo mkdir /opt/virtualmin sudo mv install.sh /opt/virtualmin

  5. Run the installer by by running sudo /opt/virtualmin/install.sh

  6. You'll be asked if you want to continue. Type y, then press Enter.

The installation should proceed without error and give you a standard prompt back.

I also like to add a favorite program or two, and disable root SSH logins:

sudo apt-get install emacs23-nox emacs /etc/ssh/sshd_config

And change the line that says:

PermitRootLogin yes

to:

PermitRootLogin no

At this point, if you can, you might want to clone your virtual machine, or take a snapshot, or do a backup... so you can get back to here easily if the next step goes sideways.

You must install MariaDB after Virtualmin; otherwise you will probably have great difficulties with apt-get trying to re-install MySQL "on top of" MariaDB, or otherwise encounter dependency problems.

Install MariaDB to replace MySQL

We will be using MariaDB 10.0 following the installation instructions here. Login as your regular user and run the following commands

sudo apt-get install python-software-properties ``sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db sudo add-apt-repository 'deb http://mirror.stshosting.co.uk/mariadb/repo/10.0/debian wheezy main'

Once the key is imported and the repository added you can install MariaDB with:

sudo apt-get update ; sudo apt-get install mariadb-server

This removes the MySQL server and installs MariaDB.

Next we visit the Virtualmin login page at https://*xxx.xxx.xxx.xxx*:10000 where the x's are your server's IP address. Login with the regular user you created -- since you have sudo ability, that will work.

Let Virtualmin check your configuration. If things have gone smoothly so far, there should be no errors to resolve.

NginX

The final big step is to replace Apache with NginX.

At this point again I recommend doing a snapshot, clone, or backup of your machine for easy recovery if these steps go wrong. Then, logged in as your regular user at the terminal:

  1. Shut down Apache: sudo /etc/init.d/apache2 stop

  2. Remove Apache from the system startup: sudo update-rc.d -f apache2 remove

  3. In addition to the NginX web server, we now install the APC cache for PHP: sudo apt-get install nginx php-apc

  4. Start NginX: sudo /etc/init.d/nginx start

  5. Install the Nginx plugin for Virtualmin: sudo apt-get install webmin-virtualmin-nginx

If you want to use SSL, you will need a package called webmin-virtualmin-nginx-ssl ... that is covered separately.

Back at https://xxx.xxx.xxx.xxx:10000 -- Turn on, and enable in the Defaults column,

Nginx website

Turn off, and remove from Defaults,

Apache website, Webalizer reporting, SSL website, AWstats reporting, Protected web directories

Click Save; then, back on the main System Information page, click Refresh system information to refresh the status bars. Click the right-arrow by the Status bar if it is not already open; you should see "Nginx Webserver" as a managed service.

Congratulations!

You now have a VPS running Debian 7, MariaDB, and NginX! Have fun.

If you are going to install WordPress, you will want manually edit the NginX configuration file through Webmin to make permalinks work properly.

From Webmin, open Servers in the left column, and click on Nginx Webserver. In the right pane, click Edit Configuration Files. In the drop down list, select the domain you are going to edit. At the bottom off that file, Virtualmin has added a stock location ... { stanza; you need to add one above it. The domain definition should now end like this:

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/php-nginx/1234567890123.sock/socket;
}

Back on the WordPress admin screen, under Settings/Permalinks, select Custom Structure and replicate the permalink directory structure you want. I use /%year%/%monthnum%/%day%/%postname%/ -- you cannot use the built-in settings like "Default" or "Day and Name" because WordPress will detect that mod_rewrite is not loaded and use its PATHINFO fallback which adds index.php into the path.

NOTE: Originally the last bit of the try_files line was: /index.php?q=$uri&$args; but WordPress now understands the simpler /index.php?$args; just fine.

Merging Git repositories

Tags:

Git is an excellent version control system, but it does get complex. On the plus side, it gives you enough power to recover from strange situations.

I had done several modifications to my AutoNav plugin on, basically, an orphan repository. Thanks to Ben Atkin, I now have a copy of the AutoNav repository and history in GitHub, transitioned from WordPress's authoritative Subversion system. However I had done some work in a newly-created repository before that happened, having simply copied the latest source code into it, and wanted to merge the changes into the global repo.

There are several possible ways to do that -- by adding remotes, by merging, by rebasing changes -- but the simplest to understand seems to be using a patch file. Cheers to the folks at Code & Coffee for help this morning with this.

Starting in my little scratchpad orphan repository, I did a git log to see what the very first base revision and the latest were. Then I use these first and last numbers as a range to format-patch, and send the result to a file:

$ <strong>git format-patch bc0ab0..3324c --stdout > 201307-autonav.patch</strong>

OK now let's go to a new directory somewhere and clone the official repo from GitHub into it:

$ <b>git clone https://github.com/lindleyw/autonav.git</b>
Cloning into 'autonav'...
remote: Counting objects: 417, done.
remote: Compressing objects: 100% (219/219), done.
remote: Total 417 (delta 222), reused 392 (delta 197)
Receiving objects: 100% (417/417), 988.36 KiB | 984.00 KiB/s, done.
Resolving deltas: 100% (222/222), done.
$

Now, let's see what will happen if we apply our patchfile (I saved this in a directory called Xgit). This doesn't actually any changes, just gives us some statistics:

$ <strong>git apply --stat ../Xgit/201307-autonav.patch </strong>
 TODO.txt               |   30 +++++
 autonav-widget.php     |  259 +++++++++++++++++++++++++++++++++++++++++++++++
 autonav-wl-options.php |  267 ++++++++++++++++++++++++------------------------
 autonav-wl.php         |   36 ++++--
 readme.txt             |   62 ++++++++++-
 wl-config-form.php     |   75 +++++++++++++
 TODO.txt               |   12 ++
 description            |    1 
 8 files changed, 590 insertions(+), 152 deletions(-)
$

OK that looks good, now let's make sure there are no errors:

$ <strong>git apply --check ../Xgit/201307-autonav.patch</strong>
$

Excellent. We are now using to use the git am command which applies patches from a mailbox, or from mailbox format. We can use the signoff switch to make a record that we approved this:

$ <strong>git am --signoff < ../Xgit/201307-autonav.patch</strong>
Applying: Preview of version 1.5.6
<em>[......]</em>
$ <strong>git status</strong>
# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
$ <strong>git push</strong>

And we're done!

Further reading: Git-format-patch (kernel.org); How to create and apply a patch with Git (ariejan.net)