Charles Engelke's Blog

February 25, 2009

CodeWright Font Update

Filed under: How To — Charles Engelke @ 3:18 pm
Tags:

Many years ago I posted a note on a Windows XP registry fix for CodeWright’s ugly fonts.  Brijesh sent me a comment that he just tried it and it didn’t work for him.

Well, I haven’t used CodeWright in several years because it’s essentially an orphaned product.  I guess some Windows XP update changed things so the registry hack doesn’t work.  But some of my co-workers are using CodeWright 6.0, and they’ve fixed the ugly fonts from within CodeWright itself.

Select Tools/Customize/View Setup, then click on the Font tab.  Instead of the default font it already chose, select a font you want.  They’re using Consolas (available for download from Microsoft, but I won’t link to it because Microsoft constantly moves things).  Go to their download center and search for it.

Consolas is fantastic for programming because the comma and period (and hence the semi-colon and colon) are very visibly different.

Hope this helps.

Advertisements

July 31, 2008

AppEngine “Rewrite Rules”

Filed under: How To — Charles Engelke @ 8:43 pm
Tags: ,

Yesterday I showed how to get a basic static web site hosted on Google AppEngine.  But I need a little bit more than a purely static site.  My blog used to be hosted at engelke.com/blog and http://www.engelke.com/blog, but now it’s at blog.engelke.com.  So any existing links to my blog entries will break.  That is, they’ll break unless requests to engelke.com/blog/something get redirected to blog.engelke.com/something.

I did this with a rewrite rule when my site was being served with the Apache httpd server.  The specific rule I had was:

RewriteRule ^/blog(.*)$  http://blog.engelke.com$1  [R]

That says that a request that starts with /blog will be redirected to one at blog.engelke.com followed by whatever followed the word blog.  Which is actually kind of wrong; for example, this will redirect a request made to engelke.com/blogging to blog.engelke.comging, which is nonsense.  I really should have given two rules:

RewriteRule ^/blog/(.*)$  https://blog.engelke.com/$1 [R]
RewriteRule ^/blog$  https://blog.engelke.com/        [R]

The first rule says that anything starting with /blog/ will be redirected to blog.engelke.com/ followed by whatever was after blog/.  That handles everything but a request to engelke.com/blog just by itself.  The second rule handles that.

AppEngine’s url: mapping rules in app.yaml kind of look like rewrite rules.  For example, the mapping:

- url: (.*)/
  static_files: static\1/index.html

That says any request that ends with a slash should be served with the file at that relative directory followed by index.html.  But that’s not a redirect.  The browser still requests the URL ending with the slash; the server just returns the contents of a particular file.

No, if we want redirection similar to the rewrite rules I had, we’ll need to write an AppEngine script.  First we add two url: mappings to app.yaml.  These should be placed before the existing ones:

- url: /blog/.*
  script: redirector.py

- url: /blog
  script: redirector.py

These correspond to the first part of the old rewrite rules, but they don’t tell what the response should be.  Instead, they just tell AppEngine to run the redirector.py script and let it figure out what to do.

I started writing the redirector.py script with a standard skeleton from the AppEngine documentation:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

application = webapp.WSGIApplication(
            [
            # pattern to handler mapping pairs go here
            ])

def main():
   run_wsgi_app(application)

if __name__ == "__main__":
    main()

The “pattern to hander mapping pairs” are each a string that’s a regular expression to match and the name of a class to handle those request paths.  The following two lines match both patterns and invoke the BlogHandler class for them (the ‘r’ in front a string just tells Python it’s a “raw” string, so Python doesn’t interpret any characters in any special way):

     (r'^/blog/(.*)', BlogHandler),
     (r'^/blog$',     BlogHandler)

The BlogHandler class contains methods for each HTTP method to be handled.  We’ll just handle GET and HEAD requests, since those are the only kind our blog will respond to anyway.  The pattern matched inside the parentheses will be passed as a parameter to each of these methods (and self is always going to be passed as the first parameter in Python).  The second pattern doesn’t have any parentheses, so that matching string parameter will be missing; our handlers will have to accept that.

Here’s the code for the BlogHandler class:

class BlogHandler(webapp.RequestHandler):
    def get(self, tail = ''):
        self.redirect('https://blog.engelke.com/'+tail, permanent = True)
    def head(self, tail = ''):
        self.redirect('https://blog.engelke.com/'+tail, permanent = True)

This code is pretty simple and should be self-explanatory.  If no second parameter is given, the methods act as if an empty string was passed.  The optional “permanent = True” parameter makes the redirect an HTTP status 301 Moved Permanently so that client programs can know to never bother to look at the old address.

Complete code

The new app.yaml file is:

application: engelkeweb
version: 1
runtime: python
api_version: 1

handlers:
- url: /blog/.*
  script: redirector.py

- url: /blog
  script: redirector.py

- url: (.*)/
  static_files: static\1/index.html
  upload: static/index.html

- url: /
  static_dir: static

The redirector.py script is:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class BlogHandler(webapp.RequestHandler):
    def get(self, tail = ''):
        self.redirect('https://blog.engelke.com/'+tail, permanent = True)
    def head(self, tail = ''):
        self.redirect('https://blog.engelke.com/'+tail, permanent = True)

application = webapp.WSGIApplication(
            [
                (r'^/blog/(.*)', BlogHandler),
                (r'^/blog$',     BlogHandler)
            ])

def main():
   run_wsgi_app(application)

if __name__ == "__main__":
    main()

And that’s my AppEngine hosted web site.  The one problem left is that requests that should have a trailing slash, but don’t, won’t work (other than /blog, handled above).  But there are only two such possible pages on my site, and I’ve never posted links without the trailing slashes.  So I don’t need to deal with them.

Though I did.  I just added mappings for those two raw names (/xhtmlref and /charles/TPC5) to the redirector.py script, and added a class to redirect those requests to the right URL with the trailing slash.  But that doesn’t show any new ideas, so I’m not going to put the additional code here.

July 30, 2008

Google AppEngine for web hosting

Filed under: How To — Charles Engelke @ 10:45 pm
Tags: ,

Shortly after I first got my own domain I decided to run all the services myself.  It was a good experience but eventually got old, so I’ve been migrating everything to hosted services.  Free hosted services if possible.

DNS went first.  When I first registered my domain the registrar would only register my nameservers, which I then had to manage.  But now they (and apparently all registrars) will manage my nameservers for me through a simple web dashboard.  Step one was done and it was free as part of my domain registration.

Next came e-mail.  Before I ran my own mail servers I had a mail hosting provider, which cost $25 per month back then.  But now I can get mail hosting for free from Google Apps.  It’s easy to use and works great.  If you don’t have your own domain name, you can also register one through them for just $10 per year.

I’d been running my own Movable Type installation for my blog.  I considered moving to hosted TypePad, but I’d heard good things about WordPressWordPress.com now hosts my blog, also for free, but I decided to pay $10 per year to have it at my own domain name.  I love their service.

And now I’d migrated everything but my core web site, which is very minimal.  All I’ve got is a home page and a small number of other pages, because I’d already migrated my photos to Picasa web albums and my presentation files to Google Docs (which is also available as part of Google Apps), all for free.  There is one hitch, though: when I moved to a hosted blog all my old URLs changed, so my main web site has to redirect requests for the old URLs to the correct new ones.  But still, I didn’t want to pay for full web hosting for what is essentially just a starting point.

Google AppEngine to the rescue.  It’s a neat platform for a fancy web application, but it can also be a minimal web server.  It’s hosting my site now, and here’s what’s involved in doing it.

First, register an application name for AppEngine.  You’ll need a regular Google Mail account for this, but that’s easy to get.  It doesn’t matter what you call it; mine was engelkeweb.

Next, create a local folder on your machine to hold your application.  Put a folder inside that containing all your web pages.  It can be called anything, but the AppEngine examples always call it static, so that’s what I’ll do.  If your application folder is at C:\MyAppEngine then this folder will be C:\MyAppEngine\static, and the main home page would probably be C:\MyAppEngine\static\index.html.

Now create a text file called app.yaml in the main folder (in this example, at C:\MyAppEngine\app.yaml) with the following contents (change the engelkeweb entry to the name you registered):

application: engelkeweb
version: 1
runtime: python
api_version: 1

handlers:
- url: (.*)/
  static_files: static\1/index.html
  upload: static/index.html

- url: /
  static_dir: static

Now upload your application (actually, just the static pages and the app.yaml file) using the command:

appcfg.py update C:\MyAppEngine

Voila!  You’ve got a simple static web site.  The second handler specification (for url: /, handled by static_dir: static) means that AppEngine will serve the page static\folder\xyz.ext whenever a user requests http://engelkeweb.appspot.com/folder/xyz.ext.  That’s 95% of a static web site. And the first handler specification (for url: (.*)/) says that any request to a URL ending with a slash should return the index.html page in that folder.  So a request to http://engelkeweb.appspot.com/folder/ would return the file static\folder\index.html.

Note that the order of the handler specifications matter, since the first one matched is what is returned.

You can use your Google Apps settings page to make this site available at your domain’s normal address, too (so in my case, that same page is returned for http://www.engelke.com/folder/xyz.ext and http://engelke.com/folder/xyz.ext).  You have to set up some DNS entries for that, but the Google Apps pages give clear explanations of what to do.

That’s how I’m now serving up engelke.com.  But what about the redirection for my blog pages?  Every URL of the form http://engelke.com/blog/something should now be redirected to https://blog.engelke.com/something.  Doing that requires actually writing a very simple Python handler for the site, just 20 lines long, and adding another handler specification in the app.yaml file.  I’ll cover that in my next post.

June 29, 2008

SlickEdit Selection Fix – and Book Recommendation

Filed under: How To,Notes — Charles Engelke @ 2:31 pm
Tags:

I’m trying out SlickEdit to see if I’ll be happy with it.  I really, really want an editor with good Brief emulation.  I used CodeWright at work; it’s good, but expensive and effectively orphaned, so I didn’t want to buy a copy for my personal machine.  Jed says it emulates Brief and it’s free; I tried it, couldn’t get it to behave like Brief, and found its documentation unhelpful.  I found Zeus: it’s inexpensive and mostly does a good job, so I bought it and use it, but it has some annoying minor glitches.  (Really minor; I’ve been using it for a year as my main editor.)

SlickEdit gets great press and has extensive documentation, so I’m giving it a try.  (For the third free trial; I never got deep enough into it to work on configuring it just right in the first two.)  One of the best things about SlickEdit is that it is nearly infinitely configurable.  One of the worst things about SlickEdit is that it is nearly infinitely configurable.  I don’t like investing all that startup time tweaking it to get it right.

But I’m still looking for an editor, so this time I’m really making the effort.  Just selecting Brief emulation made it work pretty well, but I read through the User Guide and changed a few settings.  And I got quite happy with it, except for one infuriating behavior: if I typed over selected text, what I typed was appended to the text instead of replacing it.

I figured that there had to be a way to change this, but I couldn’t find it in the User Guide.  Google didn’t turn anything up, either.  There’s a book just about SlickEdit, though; maybe it would help?  I don’t want to have to buy it to find out, though; I haven’t yet committed to this editor.  I checked for it on Safari, but it’s not there.

It is on Amazon, though.  And “Search Inside this Book” is available for it.  I searched for “typing replaces selection” and immediately found what I needed!  Right there on page 382, I saw some SlickEdit macro code commented with:

// CUA Style: typing replaces basic (not locked) selection

The code changed the value of a variable named def_persistent_select to a D.  I wasn’t about to learn how to write code to do this, but the SlickEdit User Guide did show how to change these variables through the menus.  I changed it (it was set to N in my installation), and now the editor works the way I want!

Needless to say I’m not going to remember how I did this, nor how I found this information, hence this post to remind me.  Here’s how to do it:

  1. Select the Macro menu, then Set Macro Variable…
  2. There’s a drop-down list named Variable.  Scroll through it to select def_persistent_select.
  3. Enter a D in the Value text box, and click OK.

I’m pretty sure this change is persistent.  If not, I’ll figure out how to save it later.

This greatly increases the chance that I’ll decide to buy a $300 copy of SlickEdit.  If I do I’ll also buy the $50 book (only $36.49 on Amazon).  Both in gratitude and because it’s likely to have a lot of other useful stuff.  My main qualm right now is that SlickEdit is much more complex than I want or need.  Doesn’t anybody just make a plain editor any more?

So why don’t I use Brief itself?  Because I didn’t know it existed!  I Googled it to see if there would be a good link about Brief I could put in this post, and found this.  It’s not the same Brief of old, but it’s trying to be just like it.  I’ll try it out, but it may emulate a console-mode editor too well for me today.

April 13, 2007

Installing Perl Modules without root

Filed under: How To — Charles Engelke @ 2:00 am

I just got this working, and I know I’m going to want to know how to do this a year or two down the road, and I’ll have forgotten by then. Hence, this blog entry.

You install prebuilt Perl modules in Windows using ActiveState’s Perl Package Manager (ppm). If you’ve got a full build environment, you can use the CPAN module instead.

Under Unix/Linux, you just use CPAN, because you generally have a full build environment. But Unix/Linux is a multi-user, secure environment, and unless you are the superuser, you can’t install modules normally with CPAN. That’s because they need to get installed to system directories and you can’t write to them.

But you can create your own personal libraries, and configure CPAN to use them.

1 – Create subdirectories under your home directory for the libraries. I think you can just create the main directory you need, but I created several others to be sure:

$ mkdir ~/myperl
$ mkdir ~/myperl/lib
$ mkdir ~/myperl/man
$ mkdir ~/myperl/man/man1
$ mkdir ~/myperl/man/man3

2 – Configure CPAN to install to your local directories:

$ cpan
cpan> o conf makepl_args PREFIX=”~/myperl”
cpan> o conf commit
cpan> quit

3 – Set the PERL5LIB environment variable to point to the library directory you are using:

$ PERL5LIB=~/myperl/lib
$ export PERL5LIB

Now you can use CPAN as a normal user (but it will only install modules for you to use). Remember that the CPAN settings are saved, but you’ll have to set the PERL5LIB variable each time you log in, or else save it in your .bash_profile or .bashrc initialization file. I don’t use bash much, so I’ll probably have to look this up if I want to do it.

Updated: Laurie tried this, and found some issues. I fixed the main one above.

This is just about right, but the first line of the configuration in step 2 should be:

o conf makepl_arg "PREFIX=~/myperl"

And this still didn’t work for me, so I had to use the longer version:

o conf makepl_arg "LIB=~/myperl/lib \
INSTALLMAN1DIR=~/myperl/man/man1 \
INSTALLMAN3DIR=~/myperl/man/man3"

August 27, 2005

CodeWright and ugly fonts

Filed under: How To — Charles Engelke @ 1:56 pm

I used to use Brief way back when, and when my project team decided to use CodeWright (which can emulate Brief) I was looking forward to it. But I had a really serious problem with CodeWright: all fonts looked ugly in it.

Google newgroups to the rescue. I created a new registry DWORD value (HKEY_CURRENT_USER\Software\Borland\CodeWright\Customize\FontQuality) and set it to 0.

Now fonts in CodeWright look beautiful (at least in Windows XP using ClearType).

June 2, 2005

Bluetooth to the Internet

Filed under: How To — Charles Engelke @ 4:18 pm

When I’m traveling, especially when in airports, I often want to
quickly check my e-mail or find something on the web. Actually
dialing up for this has become impossible, as data-port enabled
phones are pretty much gone from public spaces, and Wi-Fi is usually
either not available, or outrageously expensive.

(more…)

March 30, 2005

Time to Switch

Filed under: How To — Charles Engelke @ 12:09 pm

If you aren’t already using Firefox
instead of Internet Explorer, it’s time to start. We’ve had some
problems with Spyware here, and we know for sure that
most of it came in through vulnerabilities in IE. If you’re using
Windows XP with automatic updates on, your copy of IE isn’t as
vulnerable as it used to be, but (in my opinion) it’s still not
nearly as safe a browser to use as Firefox.

(more…)

March 26, 2005

Planview Remarks in Firefox

Filed under: How To — Charles Engelke @ 8:34 pm

Are you sick and tired of having to run Internet Explorer just to
enter your timesheet, because the remarks page
seems to freeze in Firefox? Well, I think I’ve figured out how
to make that page work right in Firefox, thanks in large part to a
great new book called
FireFox Hacks
(which you can probably get at almost any bookstore, or online at
Amazon
or Barnes & Noble).

(more…)

December 17, 2004

Oracle Web Conferencing with Windows XP SP 2

Filed under: How To — Charles Engelke @ 6:00 pm

Service Pack 2 is a security must-have for Windows XP users. But
it breaks a lot of things. In many cases, this breakage is just
a very conservative approach to functionality that could possibly
be misused. But if you need that functionality, and know you won’t
misuse it, you can still get it… with some additional work.

(more…)

Create a free website or blog at WordPress.com.