Vim, GNU Screen and arrow keys

Here’s a typcial scenario: I use Putty SSH into my University’s unix system, bring up screen and then proceed to do whatever work I have to do. Often this involves using Vim to write code or edit documents. Over the summer the CS department upgraded a bunch of their software - including upgrading Vim to Vim 7. Starting classes again I went to do my usual routine and found that the Arrow Keys in Vim under Screen would insert characters instead of moving the cursor. A solution was harder to find than I thought it should, so I’m posting it here:

Problem: Log into your unix/linux/solaris/whatever account and bring up screen.  Launch Vim and in insert mode use the arrow keys to move your cursor. Up arrow inserts 0A or A, Down arrow inserts B, etc.

Solution: The best solution I found was this one which instructs you to use:

:set term=builtin_ansi

which I dropped into my .vimrc file. There are more solutions involving remapping keys, setting macros and tons of other over-the-top kind of stuff. Why its only problem in Putty using Screen (I’ve tested some other permutations) is beyond me.

While on the topic of Vim, if you’re using Windows you might want to check out intellisense for Vim, two of my favorite things.

 

**EDIT**

Ok, that doesn’t really solve the problem AND it disables syntax coloring. The problem, I’ve discovered, is that Vim is reading it’s terminal setting from Screen and using ’screen’ as it’s terminal type.  Instead you’ll want to set it to xterm. I recommend adding:

set term=xterm 

to your .vimrc

Google the Google

I was searching for an answer the other day at work so I went to my favorite search engine and typed in my query. Page after page after page of results came back and they all said: “Q: How do I solve this problem? A: Have you tried googling it?”

Several pages deep I found the solution to my problem and a very interesting comment that spurred me to this post. They predicted that the death of google would be google itself - trillions of pages indexed saying: “just google it.” I wish I could remember what the question was I was searching for or who the poster was, but I cannot. Whoever you are, astute commenter, I salute you!

i(m in)Touch

For my birthday last year my wonderful family gave me an iPod Touch.  Some feel its the red-headed step child of the iPhone family, but I think its wonderful. Its like having an iPhone without the phone bill. The first thing that I did, after marveling at the touch screen and its amazing interface is, was to jailbreak it. I wont go into details (use the google) but its essentially modifying the firmware on the device so that you can run 3rd party applications natively. Why would you want to do that? you might ask. Tons of reasons. Some of the great ones are:

SwapLibrary -Sync your device with multiple libraries (only two actually, but who needs more that that?)

NemusSync - Sync your calendar with your google calendar!

Games! - GemLogic, ParkingLot, Lexitron - enough goodies to fill a 45 minute commute

ruBooks - Use your touch like an ebook reader

I haven’t look into the legality of this but I’m sure its not 100% legit. This is why I’m a big fan of open source. I think the iPod Touch is great, but I’d really like a better ToDo list application. I could either(pre sdk) cross my fingers an hope that apple does something about it or take the law into my hands and jailbreak+write something myself.  If the iDevice operating system was open (like linux or BSD or etc…) I could joined the community of active developers, learned a lot of things about a really interesting project and give something back. Ah well, its a dream world where companies write open source software and still make money (or so I’m told).

Anyway, put that economic stimulus package to good use and go buy yourself an iPhone or iPod Touch.

Vim Error

I’ve been taking a computer architecture class where we’ve done some MIPS development and while there’s an IDE available (MIPster) I’ve preferred to do most of the my development in vim. As most of you know Vim is Vi Improved, a text editor that allows you to do all of your editing through keyboard shortcuts and the command line.

I recently ran into an error while using Vim on my university shell account:

E667 Fsync Failed

It turns out that the error was caused by Vim’s inability to write to disk. I had a core dump that was using up most of my disk quota which prevented vim from allocating space to save the file. Once I deleted the dump, freeing up some space, I was good to go.

Design Patterns in C#

At work I am part of a team that mostly uses C#. Because I’m new to it (and sorely inexperienced) a coworker loaned me a copy of C# Design Patterns by James Cooper. I’ve found the book to be quite informative, a little too remedial at points, but generally quite enjoyable. You can look forward to seeing some of my notes from it, namely summaries of the various design patterns.

Chat / Messaging Clients

At work we use an IRC channel to ask questions, post progress reports and, you know, link to funny You Tube videos. For awhile I’d been using Pidgin and flirted with Trillian for a bit but I wasn’t really happy with either of them. I wanted something that could use multiple protocols (AIM, Jabber, IRC) and have full support for them. And it would be great if there was an active community to provide plugins and documentation.

A little bit of searching around lead me to Miranda and I’ve been terribly pleased with it. Supports AIM, Gadu-Gadu, ICQ, IRC, Jabber, MSN and Yahoo messaging protocols as well as having a simple, easy to use interface and a ton of addons.

I had a little trouble getting used to it at first. For one thing, getting online less intuitive than I had expected. First you need to set up your network/login information in the options window and then select the online icon from the list of icons for your chosen network.

For setting up my connection with Gmail to use gTalk I found that the listed advice was incorrect. Instead of using ‘Manually specify connection host’ and setting it to talk.google.com all I needed to do was :

login: gmail user name

password: *********

Login Server: gmail.com

Port: 443

And, of course, use SSL.

These same settings work great with jGmail, a addon for Miranda that will also check your mail for you.

My History with Linux

I’ve been a Linux user for nearly 10 years now. It started back in college when my friend Nicola showed me RedHat 6.0. I was using a mac clone at the time and tried to install Yellow Dog on it, but the hardware support was non-existent and I couldn’t figure out what the buzz was all about. If I wanted to use the command line why didn’t I just log into one of the University’s Unix machines?

On and off through the years I’ve installed into, used it, uninstalled it. I see an operating system as a tool and, like any other tool, it works well when used for it’s specific purpose. From the command line its great for running services, managing users, configuring/tweaking/maintaining your OS for your needs. From the desktop I’ve found it to be a good development environment and for basic office tasks like web browsing, editing documents, basic graphic manipulation, its fine. But for getting the most out of your desktop experience I would recommend getting a Mac or Windows. I can hear the squeals of outrage from the Linux zealots already, but as I’ve said: The right tool for the right job. The hardware support for a casual user is outstanding in both on Windows and Macs. The interfaces are, for the most part, intuitive and user friendly. They support most of the latest standards and features offered by 3rd parties. And perhaps most importantly there is a very large corpus of applications for the Windows and Macintosh operating systems that are well supported and well documented.

Having said all of that let me also say: Any tool in the right hands is a hammer. And sometimes all you need is a hammer. And sometimes what you need is an operating system and it really doesn’t matter which one you use. Considering that, I’ve recently begun to revisit the idea of using Linux as my primary desktop. I was quite happy with it last time I used it, but there were small features that made it unbearable - lacking power management for my laptop, poor support for web standards, a clunky UI, insufficient application base - but that was four years ago and think have really moved since then.

I currently use Gentoo on the linux box that acts as my firewall/NAT/router. It has an amazing package management system and it is one of the best document linux distributions I’ve used. My beef with it is that everything has to be compiled. I guess its not such a bad thing, really, and I don’t mind once everything is set up and running, but if I were to set it up for a non-technical user I’d worry about having to support it for them.

What I’d like to do is find a distro that I can recommend to friends and family who have little to no interest in maintaining the operating system they use. They want it to work and they want to be able to do what they want to do. The news around the block is that the hot new distro for the casual user is Ubuntu Linux. A very slick gnome based interface, a very active user community with lots of documentation, lots of little helper applications and a dedicated team of developers.

In the next couple of weeks (perhaps I should wait till the end of the semester?) I hope to get Ubuntu installed and put it through its paces. There are already piles and piles of reviews available online, but sometimes you just need to get your hands dirty and find out for yourself.

I’ll let you know how it turns out.

VMWare SCSI driver error

Using VMWare server 1.0.4 (check it out, its free!) I recently tried to install Fedora Core 7. I ran into a problem with the SCSI driver. First, while installing I received a message saying that the device sda, sdaa, sdab, etc… could not be found. After clicking through the 52 or so error dialogs I was finally able to proceed. When I finished the installation and restarted the server I received a message:

Asking for cache data failed
Assuming drive cache: write through
rejecting I/O to offline device

for each possible sda device. After all the messages the server proceeded to boot. Needless to say, this took a very, very long time.

Apparently there’s an error with the SCSI driver that hasn’t been addressed yet. You can see more in this thread. My quick solution was to rebuild the VM using the LSI Logic instead of the Bus Logic.

Hope this helps someone.

Java Web Start

I’ve been working on an application for work that is to be distributed by Java Web Start (JWS) and I can see what all the fuss is about. I have really gotten into it yet, I hardly know anything actually, but I do know that it makes it incredible easy to distribute an app.

Basically, JWS is a technology that allows you to bundle up a Java app in jars and then bundle it on a web server so that it can be downloaded as needed. Once you’ve downloaded it you can run it locally, but if there is a change to the code on the server JWS will grab the new package and update your app. It combines the mobility of Java applets with a feature rich, locally run Java application.

With all of the convenience of distribution I had a few problems getting it up and running. I’ll qualify that statement with this: I didn’t spend a lot of time reading up on JWS or how to debug it and ultimately it wasn’t really JWS fault that I was having trouble (a logic disconnect between the chair and the keyboard). To solve the problem I enabled the Java console which can be found (in Windows) under Control Panels>Java>Advanced> Enable Console and Enable debugging. My main problem was that the app would download and launch and then hang giving me no errors or wouldn’t display anything. I turned out that there was a problem loading one of the libraries.

To get the full benefit out of JWS I should probably do a lot more reading. What I’ve come across so far has been pretty good, but I’m sure there’s tons more information out there. I’d recommend reading up on JWS over at Sun’s page, there’s Wikipedia of course and there’s a pretty good article over at JavaWorld which gives a good overview of the history and its uses.

Mongrel

Mongrel is a lightweight web server that is quite popular with the Ruby on Rails crowd. It’s apparently really great at serving dynamic pages and is often coupled with Apache which serves the static pages. Set up is extremely easy

gem install mongrel

and running it is much the same.

mongrel_rails start -d

There are some things that I found particularly annoying about it. Mostly you have to be in the document root of the rails app when you start the daemon for it to know where everything is.

Because mongrel runs one thread at a time it can only answer one request at a time. This can be problematic when you’ve got a busy site with many requests a second (I’ve heard a single mongrel instance can handle around 25 requests a second, but I couldn’t site my source). To overcome this limitation you can run mongrel behind Apache’s mod_proxy and mod_proxy_balancer which allows you to create some psuedo load balancing. This is all done through Apache’s httpd.conf file (or whatever imports you want to add to it). You’ll need to load the proxy modules, the balancer module and the rewrite module for things to work right. My configuration looks something like this:

<virtualhost *:80>
ServerName myserver.com
DocumentRoot "/path/to/doc/root"

<proxy balancer://mongrel_cluster>        #This is the name of the cluster group, can be anything
BalancerMember http://localhost:xxx0     # the location of your additional mongrel instances
BalancerMember http://localhost:xxx1
</proxy>

ProxyPass /images !                     # Don't let mongrel serve these pages - static content
ProxyPass /stylesheets !
ProxyPass /javascripts !

Alias /appName /full/path/to/your/app       #only needed if app resides somewhere other than docRoot
ProxyPass /appName balancer://mongrel_cluster
ProxyPassReverse /appName balancer://mongrel_cluster/

RewriteEngine On
ProxyRequests Off              #SysAdmins don't usually like open proxies

# Check for static index
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [QSA,L]

# Check for Cached pages
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)[^/]$ $1/ [QSA,L]

# Send all other requests to Mongrel to be dynamically generated
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

# Compress text files so they can be loaded more quickly
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml

As you can see its not overly complicated. The rewrite can be intimidating, but they’re recipes mostly you wouldn’t need to change them. There is some good documentation online, but not copious amounts of it. I’d recommend here and here for more resources, but you’re a smart kid, you can find your own answers using google.