Bold Shell Command like the Rails Books

I've recently been reading some books about Ruby on Rails.

One little thing that I thought was cool was the example commands:

dave> cd work
work> rails demo
create
create app/controllers
create app/helpers
create app/models
: : :


I decided to try to make my shell look the same.

Putting the directory name in the prompt is easy. That can be achieved by setting PS1='$(basename "$PWD")> '

(if you use zsh, you may need to run setopt promptsubst first)

Making everything you type after the prompt bold is the tricky bit. You have to enable bold mode at the end of the prompt, but disable it as soon as the user has pressed Enter, so the command's output isn't bold too.

This can be achieved in zsh by adding %{$(tput bold)%} to the end of your PS1 line, e.g.

PS1='$(basename "$PWD")> %{$(tput bold)%}'


and adding a function called preexec that resets the font to normal.

preexec()
{
tput rmso
}


And to finish up, I like to handle things properly if tput and basename aren't available, so I test if tput is present using command -V tput and use POSIX-style ${parameter##word} to delete everything except the last part of the path.

So the stuff you need to add to ~/.zshrc now looks like this
setopt promptsubst

init_terminal()
{
if command -V tput >/dev/null 2>&1; then
bold="$(tput bold)"
underline="$(tput smul)"
normal="$(tput sgr0)"
fi
}

last_part_of_path()
{
local full_path="$1"
local last_part="${full_path##*/}"

if test -n "$last_part"; then
echo "$last_part"
else
echo "/"
fi
}

preexec()
{
print -n "$normal"
}

init_terminal

PS1='$(last_part_of_path "$PWD")> %{$bold%}'


And the end result looks like this



Unfortunately, you can't do this in bash because it doesn't have an equivalent to the preexec function, so everything including the command's output will be bold. (There is a patch to add something similar, but it causes bash to crash in some situations, so I think it's safer not to use it.)

Labels: , , ,

Goodbye iiNet, Hello Internode!

The saga of my home ADSL connection.

No ADSL2 for you! (a.k.a. Internet in Australia sucks)


When I first moved to Elsternwick in November 2005, one of my important decisions was which internet service provider to use. I had previously been with iiNet, then Internode. Their ADSL plans were both quite reliable, which was essential, since I run my web site (including this blog) over my ADSL connection. The main factors in my decision were price and speed.

Around this time, iiNet said on their ADSL2+ coverage page that they were planning to install the required equipment (an ADSL2+ capable DSLAM) in my exchange in November/December. Their prices were very good (in fact, cheaper than most of their slower ADSL1 products), and the speeds should have been excellent. (According to Whereis, I'm 1.43 km from the Elsternwick exchange, and this graph of ADSL2+ speeds suggests I could get up to 20 Mb/s at that distance.) iiNet also don't block ports and allow using the connection to run servers, so it seemed like a no-brainer.

I applied for the service at the beginning of November.

About a week later, I had an ADSL1 service.

That was fine, since I knew they hadn't installed their DSLAM in Elsternwick yet, so I would be connected to a Telstra DSLAM, who at the time only offered ADSL1.

At the end of November, I received an email from iiNet saying "Congratulations, your exchange has been selected for a Broadband upgrade". This was great, and was what I was waiting to hear!

The date came and went, and I was still on ADSL1. Apparently the upgrade had been postponed.

I received another message in January 2006 telling me the same thing. Some time around the beginning of February, they actually installed their DSLAM and started migrating customers to ADSL2+. Unfortunately I wasn't one of them.

I contacted iiNet, and was told that I wasn't migrated because iiNet has to submit the list of customers to migrate to Telstra well in advance of the migration, and they had done so in October, before I was even a customer. I was told to wait for the "next migration".

Every few months, I contacted iiNet to ask when the migration would be. I was told they only performed bulk migrations (at least twenty customers at a time), and there were no plans to do such a bulk migration (presumably because I was one of the few customers who didn't get migrated in February).

In mid-2006, there were discussions of a single-port migration process, probably starting in September. Telstra called this a "single service migration" or a "single service transfer", depending on whether you were staying with the same ISP or changing to another one.

Several deadlines for single-service migration slipped, then it sounded like it might really happen in February 2007.

It did, but not for iiNet. For some reason, Internode and some other ISPs supported the process, but since Internode only had ADSL1, I had to wait for iiNet to get on board if I wanted ADSL2+.

Last month, it seemed like iiNet were joining the migration process, but I contacted them and they advised I still couldn't transfer. I would have to do a full disconnect, wait for about two weeks for the "lines codes" to be removed, then apply as a new customer and pay the full $200 connection fee. Since I rely on this connection for my web site and email, I can't accept a two-week outage.

The final straw was trying to watch a low-bandwidth video on YouTube the other day, and the playback kept stopping because my connection wasn't fast enuff.


Choosing a new ISP (a.k.a. which plan sucks the least)



I checked out the plans on Broadband Choice. Internode were cost competitive (they're all too expensive and slow, but Internode isn't much more expensive than the other options for my usage), and they're known to be a very reliable company. Indeed, they're ranked #1 by the users on Broadband Choice. They also allow me to run servers and have a local mirror site where I can get my Linux downloads fast and free. I looked at some of the other, newer ADSL2 providers such as Spin, hoping they would support single-service transfers, but they also had a long contract period and higher set-up cost, which my house mates weren't happy with, so Internode it was!


The churn process (a.k.a. I can't live without Internet)



To complicate things, Internode don't provide phone services like iiNet do, and Telstra (Australia's near-monopoly telco) requires we have an active landline phone service to get ADSL. The only real option was Telstra, who provide a $20 a month plan called HomeLine Budget, but they don't let you sign up for that if you want to use another company for ADSL. Instead I would have to go with their next-least-expensive plan, HomeLine Complete, which costs $27 a month.

I read the forums on the Whirlpool broadband user group web site to figure out whether it would be better to change the phone to Telstra or the internet to Internode first, in order to minimize downtime. I came to the conclusion that I could get my faster internet sooner if I changed my internet provider first, and that there were no downsides to doing it that way. In Australia, the process of changing an existing ADSL connection from one ISP to another ISP is called "churning" (however most Telstra documentation calls it a "rapid transfer").

I signed up for the Internode HOME-1500-Power-10 plan, a 1.5 Mb/s plan for $49.95 a month, and heard back from them within a couple of days. They sent an email detailing the new plan and the process for transferring to them. It included a PDF telling me that I should not change phone providers once my Internode plan went active, as this could remove the "ADSL line codes", causing an outage of a few days.

I immediately called Internode to confirm this, then ended up having to cancel the process.

I had to go to plan B: changing my phone provider to Telstra first, so I called Telstra to do so. I was told this would take a few weeks. It did, and in the mean time, Internode changed the price on the plan I wanted from $49.95 to $54.95. I decided to go ahead with it anyway, since it would now cost the same as the old arrangements with iiNet ($33.36 + $49.95 versus $26.95 + $54.95).

Two weeks later, and finally my phone was with Telstra. I called Internode to re-apply, accepting the new plan price.

Last night, I got an SMS telling me that the ADSL service was provisioned, i.e. was now ready to use!


Setting up my new connection (a.k.a. why doesn't my Internet work?)



I left work around 6.15pm, eager to set up the new connection.

I set the DNS of my web site to my backup server (on a frend's ADSL connection), pointed my Debian PPP configuration to the Internode "dsl-provider" account details, restarted PPP and crossed my fingers. Of course, it didn't work.

I learned two things:
  • On Debian, you need to change three files, /etc/ppp/dsl-provider, /etc/ppp/provider, and /etc/network/interfaces
  • My D-Link DSL-300 modem is really strange to configure in bridge mode


The first is because there are three sets of PPP initialization scripts.
ppp_on_boot (dsl-provider)
I think this used to be called from a script in /etc/init.d. It used dsl-provider, but is no longer referenced.
pon/off (provider)
This is used by pon and poff, the old dial-up ("dip",) scripts that allow privileged users to start and stop the PPP connection.
ifup (interfaces)
PPP devices can now be configured along with Ethernet devices in the standard Debian interfaces file. The provider is named in that file.


In all cases, the script for each provider is stored in /etc/ppp/peers, for example /etc/ppp/peers/internode.

The second is weirder, since there is no documentation (I never got a manual, and there's nothing helpful on the D-Link web site), so it's more a matter of trial-and-error.

I was receiving the familiar "Timeout waiting for PADO packets" message (note that it's PADO with the letter O, not PAD0 with the number 0) which I've seen numerous times before with there were connection problems.

The first thing I did was to add an account on the ADSL modem to test whether my iiNet or Internode account was active, and whether the username and password were correct. I determined that my Internode account was indeed working.

I then enabled debug mode in pppd, and noticed some other messages before the PADO timeout message, in particular "LCP: timeout sending Config-Requests". I figured the problem would have to be that pppd couldn't set up the connection on the modem, so wondered whether the modem was in bridge mode (which it needed to be to allow my Debian server to override the address configuration and provide other services such as address translation that allow me to share the connection between multiple computers).



I checked the main "account configuration" page and ensured there was no username and password entered, that on-demand connection was disabled, and that the connection was disconnected. When I clicked OK, I let it save its settings to Flash memory and reboot. Still nothing.

Next, I tried setting the connection type to "RFC1483 Bridge" mode. It still didn't work.

Finally, I played the old game I learned from years of using Microsoft products: go thru every menu and see what settings are where they shouldn't be. (At least with this modem, there aren't too many settings to get lost in!)

I went to the accounts management page, and noticed there was an entry for some account. The fields didn't give much information, but I figured the best idea was to make sure there was as little configuration on the modem itself. (Besides, the current setup wasn't working, why not give it a try!)



After deleting the entry it still didn't work, but after powering the modem off and on, my "pon" script worked, and I had an internet connection!


Success! (a.k.a. this Internet connection sucks less!)


I made sure my server settings were correct, redirected my web site to my new connection, and sent a test message thru the new Internode email server. All went well!

The very next thing I did was enter youtube.com in my browser. I clicked on the first link it showed me to some dodgy party with beer movie. It played without pausing!

Mission accomplished!

Labels: , , ,

Microsoft Remix 2007

I spent the past two days at Remix 2007, a Microsoft web development conference.

My main motivation was to see what Microsoft's web development tools were like, particularly for designing and building a web site using graphical tools. At the moment, I build my web sites by hand, writing my own HTML and CSS. In theory, Microsoft's development tools such as Visual Studio should be able to create similar results much more quickly. Remix 07 seemed like a good way to find out about the latest tools and trends.

The event was held at the Crown Promenade Hotel, which is a hotel hidden just behind the main Crown Casino on Southbank.

According the registration email, attendees would receive a free copy of Expression Web, Microsoft's new web site development tool. When I arrived there around 9am, there was a booth handing out 60-day evaluation versions, but nothing else. Time to pick up a program and head in for the first session.

The event started with a keynote address about Silverlight and Expression. Silverlight is Microsoft's answer to Adobe's Flex. It's supposed to allow developers to write more interactive web sites. Unlike Flex, however, there didn't seem to be any real push to use Silverlight for desktop applications.

The first interesting session was by Lee Brimelow. He's a geek with a multimedia bent, somebody with a lot of Flash experience and the author of The Flash Blog. His session on Windows Presentation Framework (WPF) showed a lot of interesting multimedia techniques implemented using Microsoft's latest graphics framework, such as rotating shapes, 3D audio visualizations, and some photo browsing applications using the Flickr API. His talk was from the perspective of somebody familiar with Flash trying to do similar and interesting things with Microsoft's new stuff. It gave the impression of something very interesting to multimedia and design peeple, but not much that couldn't be achieved using existing technologies. That said, it was interesting from a developer's perspective.

The next talk was from Laurence Moroney about "Building Rich Web Experiences with Silverlight and JavaScript". It was a fairly basic talk about Microsoft's XAML mark-up language. If you've seen HTML and SVG or perhaps Mozilla's XUL, as I have, you would have been totally bored. Maybe it was useful for the designers.

After lunch there was a talk by Steve Marx provocatively titled "PHP and Microsoft". He said that Microsoft's IIS web server had recently become pretty good at running PHP. The rest of the talk was about using a library he'd written to provide a better user experience using Microsoft's AJAX library on your PHP-based web sites. It got me thinking about a few places I could use AJAX to dynamically update parts of a web page, and introduced me to Microsoft's SourceForge equivalent, CodePlex.

At 3.15, a Kiwi named John-Daniel Trask gave a talk. If I remember rightly it showed ways of providing web site content in other formats, such as RSS and XML. It was heavily based on an ASP.NET web site and used a lot of features of Visual Studio. The code itself wasn't particularly memorable.

The formalities for the first day finished with a talk about "Orcas", the version of Visual Studio that will be released as Visual Studio 2008. The main things it proved were that Visual Studio now has some good tools for web development including a split source/page view that reminded me of Firebug for Firefox and that Visual Studio 2008 was still buggy and a long way from being ready for release!

The end of the day was really good. Most of us went to an event down the road at Galactic Circus, involving ten-pin bowling, laser force, arcade games, and free beer. You can guess which one I focussed on. ;-)

Day two started with lots of marketing presentations and a demo of a state-of-the-art web site that Guy Gadney's team had developed for the Discovery Channel. The content and technology themselves weren't very interesting, but what was, was that it had only taken his team a few weeks to build the web site in question. The site showed off the Silverlight video streaming capabilities.

The mid-morning talk was by Russ Weakley, and was the kind of material I was used to and hoping to hear more of. It was also good to see and meet the main guy behind Max Design and the Web Standards Group. Unfortunately, it was mostly old news for me. His talk was about using different CSS hacks to target rules to different browsers. They weren't traditional hacks like the Holly Hack or Voice Hack, but rather import hacks that used the different ways that each browser parses the style sheet include code to hide some code from older or less standards compilant browsers. I had already used these techniques a few months ago, probably from reading Max Design's "Links for Light Reading", so credit where credit's due, and good that more peeple are being encouraged to use the technique (rather than using hacks or tables), but nothing new to me as a regular reader. At the end of his talk, I mentioned a script by Dean Edwards called "IE7", since I've found it greatly reduces the number of hacks I need to use when making my CSS work in Internet Explorer.

The last session of the morning was another one from John-Daniel Trask. He advocated designing with standards in mind, and reminded us of accessibility (primarily thru the Web Content Accessibility Guidelines). Again, not too much new for me, but refreshing to hear it being discussed at a Microsoft conference.

After lunch was a panel about "Web 2.0". It was a bit silly, with everybody talking around the topic rather than about it, talking about startups, trends, and trying to look cool.

Mid-afternoon was another talk from Steve Marx from Microsoft. It was technically rather light, since Visual Studio was doing much of the work, but it demoed using Visual Studio to AJAX enable a web site, and was made much more interesting by making the whole talk about juggling ("Asynchronous Juggling and XML" rather than the traditional "Asynchronous JavaScript and XML"). You can see how peeple like Linus Torvalds win the crowd over by being self-deprecating. :-)

The last session was another panel, discussing the differences between developers and designers. The host asked the audience to guess which of the panelists were developers, and which designers. It was fairly obvious: the designers had sunglasses, bad shirts and sideburns, while the developers had free polo shirts advertising technology companies and otherwise no fashion sense whatsoever. It was basically a wrap-up wishing that developers and designers worked more closely together, and reminding us to purchase their Expression software suite.

During the whole event, one recurring thought was that this new technology was largely futile, since nobody has the Silverlight runtime on their computer. Flash sites are only now coming into their own, and that's with an installed base of over 95%, it's hard to see how Microsoft would overtake Flash and Flex. Perhaps the one niche Silverlight might find is for intranet applications where the developers can specify a standard operating enviroment and target only one platform. For anything that has to be usable by everyone, HTML and JavaScript or Flash still seem like the only real options. (It was interesting to meet some peeple who were doing some marketing work for Microsoft who were attending. They, like many designers, were familiar with Adobe/Macromedia's tool suite, but were trying to move to Microsoft's products since they figured they had better use their client's own stuff.)

Otherwise, I'm left with a mildly positive impression. It was more informative than Sun or IBM events I've attended in the past, quite frank about what Microsoft could help you do while also acknowledging weaknesses, and rather more focussed on the developer.

After handing in my evaluation form, I was rather pleased to get a free copy of Expression Web!

Labels: , , , ,

Safari for Windows

Apple have just released their famous Safari web browser for Windows. Probably not everybody has heard of it, but it's famous in geek circles for being the first web browser to pass the Acid test, meaning it supports the latest web standards, and should be a good browser for web developers to test on.

Of course, being from Apple, it should also provide a really good user experience. I downloaded it this morning to take a look.


Safari on Windows




The first thing you notice is it uses the familiar Apple brushed metal look. This is expected, but it doesn't fit in very well with the rest of the system. That said, I tend to run my browser full screen, so it's not so important that it look identical to every other application, only that it behave like them.

Unfortunately, this first release for Windows doesn't do that very well either. I counted fifteen annoying differences.

The worst ones:

  • the default fonts are very dark
  • the address gets messed up if you press Ctrl+L and try to type a new address while the home page is loading
    (the same thing happens in Internet Explorer and is the #1 reason I don't use it)
  • the Windows task bar can't be accessed if it's in auto-hide mode
    (Safari doesn't leave a 1 or 2 pixel buffer at the bottom so you can move your mouse to the bottom of the screen and see what other programs are open)
  • new windows aren't the same size as the current one
  • many keyboard shortcuts don't work on Blogger
    (I couldn't use Ctrl+C, Left, Shift+Home, or my Alt Gr key)
  • no shortcut to switch between two most recent tabs
    (like Ctrl+Tab in Firefox when using the LastTab extension)
  • many menu items appear in the Edit menu (where they would be on Mac) rather than a Tools or Options menu (where they should be on Windows)
  • you have to hold down the mouse button while selecting an item from a drop-down list
  • no proxy support (meaning I can't use Safari at work)
  • no way to fix any of this! (I reported these as bugs, but who knows how long they'll take to fix; Safari isn't open source and isn't extensible like Firefox)



Bug: Pressing Ctrl+L then typing too quickly



Some of these are problems with the browser itself, some with particular web sites, and others with the user interface toolkit Apple use to make their Mac applications run on Windows. It would also be nice if it offered to migrate my passwords from Firefox. There's no way I'm typing in my passwords again for all the sites I go to.

On the upside, it has some nice features such as highlighting the active text field on a form with a clearly visible blue border, and showing the page loading progress using a nifty blue bar that takes up the whole address bar (this feature inspired the Fission addon for Firefox). It's also nice that my web site looks fine!


My web site in Safari



On the whole, the browser is quite usable, and hasn't crashed on me yet, it's just lacking several features that I want before making it my default web browser.

Update: June 28, 2007


I just tried Safari 3.0.2 at work behind an authenticating proxy, and it works fine. It's just the proxy settings button is grayed out. Apparently it uses the operating system settings (Control Panel->Internet Options).

Update: November 20, 2007


Safari 3.0.4 was released today. It seems to fix the taskbar hiding bug, and new windows are now the right size. There's now a Ctrl+Tab shortcut. It doesn't work the way I want, but at least it's there. Blogger also seems to work, but it crashed the first time I tried. The Ctrl+L bug isn't fixed, and sometimes Ctrl+L doesn't do anything.

Labels: , , , ,

Free Fonts

My interest in fonts began a few years ago when I discovered Lucida Sans. It was embedded in a paper about Plan 9, an operating system by the creators of UNIX. It's a nice, easy-to-read font without serifs (the ornaments on fonts like Times New Roman) that isn't as boring as Arial or Helvetica.

I was trying to find out how I could get the font on my computer, when I discovered that the Sun Java package includes the original Lucida Sans fonts. I now make a point of installing Java on all of my computers, then copying the fonts from the lib/fonts folder into my system fonts folder.

Lucida Grande



There's a similar font that comes with Mac OS X called Lucida Grande. If you're running Windows, you can get it by installing the Safari web browser public beta and copying the TTF files from the Safari.resources folder.

Microsoft Windows also comes with a version of Lucida Sans called Lucida Sans Unicode. On some systems (e.g. Windows 2000 without ClearType) this doesn't look very good and it doesn't differentiate between normal and bold, so I only use this as a fall back if the other two aren't available.

I use these three fonts as the default fonts on my web site. Since at least one of these is included in recent Windows and Mac systems, most peeple should see a Lucida Sans variant.

It also turns out there's a number of other good fonts available for free download, starting with the Microsoft Windows Core Fonts, including Andale Mono, Arial, MS Comic Sans, Courier New, Georgia, Impact, Tahoma, Times New Roman, Trebuchet MS, Webdings, and Verdana. Most peeple will be familiar with these fonts, but I'd like to point out Andale Mono as it's a really good font for programming and much better looking than Courier New. They can be downloaded from the SourceForge Core Fonts Project Page.

Andale Mono



Other worthwhile downloads are the Windows ClearType Fonts, including Calibri, Cambria, Candara, Consolas, Constantia, and Corbel. They are all included in a standard install of Windows Vista or Microsoft Office 2007, but you can also get them in the Microsoft PowerPoint 2007 Viewer package. Calibri is the definite highlight. It's the default font in Word 2007, so you're certain to see it more in future.

The Microsoft Office Fonts includes some classics, particularly Century Schoolbook, Gill Sans MT, and Lucida Sans. You can get them with most versions of Microsoft Office, but you can also get them in the freely available Microsoft Publisher 98 Euro Fonts Update. Run PubUpd.exe /c /t:c:\temp, then copy the TTF files from c:\temp into c:\windows\fonts.

I discovered today that Adobe Reader version 8 includes Myriad Pro. It's an attractive humanist font similar to Lucida Sans. It's the font used in Apple ads. You can download it here. Install it and then copy the OTF files from the Resource/Font folder into the system fonts folder.

Myriad Pro



Another set of good fonts that deserve more attention is the Bitstream Vera family. They are included as the default fonts in many recent Linux distributions, and can be downloaded from the GNOME Fonts web page. They can be used as pretty good replacements for Verdana, Georgia, and Andale Mono.

Thanks to GearedBull for releasing his excellent Wikipedia font previews into the public domain.

Labels: , , , , , ,

New Web Site Design

A number of peeple told me that my site looked boring.

I had been wanting to come up with a radical new style, having been inspired by sites like Modern Life and an excellent list of 50 beautiful sites on Smashing Magazine.

After many battles with CSS to get exactly the right results in all browsers, and realizing that it would take forever if I wanted something unusual, I decided to try something simple yesterday. The result is now the default theme on my web site.


New Home Page



The main focus is the new banner, which is a bright "cornflower" blue (probably my favorite color, even if it does remind me of Fight Club). At the bottom of the banner are simple white all caps words that are links to each section of the site.

I decided to remove the page titles and the crumbs. I'm going to leave them out to reduce any clutter until I'm sure they're necessary.


New-Look Blog



The other major change is to specify a font size. In the past, all my sites have respected the browsers's preferred font size. Unfortunately, the default font size on Windows systems is quite large, and a lot of peeple don't know how to change it. The new theme specifies a default size of 10 points small, which should make fonts somewhat smaller than in the past, matching most peeple's expectations, making the site look better with default browser settings, while allowing peeple to make the fonts smaller or larger using their browser's text size or zoom feature.

There's also an improved "page not found" page. If you mistype an address, you are shown a list of similar pages if there are any, and a list of popular pages if there aren't any.

As always, the site should work on all platforms.

Let me know what you think!

Labels: , , ,