Tuesday, February 28, 2012

"The Dark Room" YouTube Walkthrough Spoiler Cheat Guide Thingy

"You awake to find yourself in a dark room."

Here's a map of The Dark Room.

Note that there are a number of false restarts, where it looks like you've restarted the game, but you're actually in an alternate version of the opening with different actions.

"Error" is the best fair ending, I think. There's another fine ending at the bottom of the map called "Alright Then."

But there's a trick to finding the "100% Good Ending." In "Turn Around Redux", which you can reach like this:
  1. Go North
  2. Find Light Switch
  3. I See
  4. Listen
  5. Kill Self
  6. Hold Breath
  7. Pass Time
  8. Dig
  9. Treasure
  10. Turn around
The sound is backwards. Reverse it using a program like Audacity to hear the coded message. (Note the comments; try making the last one big.)

Sunday, June 26, 2011

Style Safari Input Type=Submit Buttons

In my HTML forms, I like to allow users to submit the form by pressing the Enter key, without JavaScript. The easiest way to do that is to include an <input type=submit> button.
<form>
  <input name="x">
  <input type="submit">
</form>
But beware: on Safari (and other WebKit browsers?), <input type=submit> buttons resist CSS styling.
<form>
  <input name="x">
  <style>
  .button {
    font-weight: bolder; /* THIS LINE DOES NOTHING IN SAFARI :-( */
  }
  </style>
  <input class="button" type="submit">
</form>
TIL: if you want to force them to be styled, you can use a WebKit proprietary CSS property, -webkit-appearance: none.
<form>
  <input name="x">
  <style>
  .button {
    -webkit-appearance: none;
    font-weight: bolder;
  }
  </style>
  <input class="button" type="submit">
</form>
If you do that, your buttons will look pretty ugly at first, but with a little work, you can make really cool CSS buttons.

Sunday, March 06, 2011

Convert PS1 Font from Mac to Windows

It's not uncommon to receive a font from a designer that works fine on the Mac, but can't be opened on Windows.

This happened to me today. When I viewed the font in the Finder, the font had no filename extension, but Get Info said its Kind was "Postcript Type 1 outline font." Unfortunately, when I zipped the file and opened the zip file on Windows, the file was 0KB long; not very useful!

Here's how I fixed the problem.

To convert it, I used FontForge. FontForge is a Unix utility that kinda sorta works on OSX. They don't provide an installer for OSX, so the easiest way to install it is by using MacPorts. MacPorts comes with an installer, but you have to install Xcode in order to use it. Xcode can be found on your original OSX install DVDs, on DVD 2. If you can't find those, you can download Xcode for free from Apple, but you have to register as an Apple developer. It's a hassle.

Anyway, assuming you can find and install a copy of Xcode and MacPorts, you should be able to run "sudo port install fontforge" and wait an hour for macports to download a bunch of code from the Internet, compile it, and install it on your machine.

Finally, finally, you can run "fontforge" to open the program. Double-click on your font, and select the File / Generate Fonts ... menu. Select "TrueType" in the list of font types, and save it. It might give you some warnings; I ignored all warnings with no ill effects, but your mileage may vary. This created a .ttf font which worked great on my Windows machine.

Saturday, January 29, 2011

Play YouTube Videos at Double Speed

I enjoy watching video lectures on YouTube at double speed. (It saves a lot of time!)

Here's how. Download VLC and run it. Under the File menu, "Open Network ..." and paste in the YouTube URL. Then, under Playback, select Faster or Slower as needed.

Unfortunately, there's a catch: YouTube throttles download speeds. You can only download one second of video per second. So you'll have to wait for the video to finish downloading and then watch it. (Hey, at least you don't have to sit there and watch it download!)

Alternately, you can use VLC's Streaming/Exporting wizard to save the video to disk first.

Have fun!

Monday, August 16, 2010

Permanent Windows command-line aliases with doskey and AutoRun

On Unix, you can configure command line aliases, like this: "alias lls=ls -l". From then on, running "lls" will automatically run "ls -l", saving you a few keystrokes. The alias will go away whenever you open a command prompt; to make the alias permanent, you can save it in your .profile or .bashrc.

On Windows, you can do the same thing using the DOSKEY utility to create "macros" like this: "doskey ls=dir". Doskey macros are basically equivalent to Unix aliases (though they have different advanced features).

Automatically loading your Doskey macros is a bit more trouble, however. Doskey allows you to export a macro file, like this: "doskey /macros > my-favorite-macros.txt". You can then import your macro file like this: "doskey /macrofile=my-favorite-macros.txt".

Instead of your .profile, you'll need to configure your AutoRun registry value, in "HKEY_CURRENT_USER\Software\Microsoft\Command Processor". I have my AutoRun set to "c:\dev\autorun.bat" which runs a variety of helpful utilities.

I hope this helps!

Sunday, May 09, 2010

Customize Android Browser Scaling with target-densityDpi

It was hard to find this little gem, so I thought I'd share it with the world: the Android team has implemented a custom meta viewport property to allow you to customize browser scaling for high resolution (HDPI) screens, like the WVGA 480x854 Motorola Droid and 480x800 Nexus One. [This is as opposed to medium resolution (MDPI) HVGA 320x480 T-Mobile G1 or myTouch 3G.]

You can use it like this, for example: <meta name="viewport" content="width=device-width, target-densityDpi=device-dpi">

What's Browser Scaling?

Here, ppk explains why a pixel is not a pixel. The CSS "px" unit may differ from a device's actual pixels, as the browser "scales" images and fonts to a larger size than you requested. (The browser just naturally assumes you didn't really mean "pixels" when you said "px," and helpfully tries to resize your content to make it readable on high-resolution phone screens.)

The Nexus One and Motorola Droid (and any other WVGA devices) will scale pixels even if you use the <meta name="viewport"> tag to instruct it not to do this. Worse, they using a non-integer scaling factor (e.g. 1.5x zoom, to scale 320px to 480px) which makes images look really weird.

target-densityDpi to the rescue!

Use this new undocumented <meta name="viewport"> property: target-densityDpi. The only existing documentation is in the Android check-in comment:

Add dpi support for WebView.

In the "viewport" meta tag, you can specify "target-densityDpi".
If it is not specified, it uses the default, 160dpi as of today.
Then the 1.0 scale factor specified in the viewport tag means 100%
on G1 and 150% on Sholes. If you set "target-densityDpi" to
"device-dpi", then the 1.0 scale factor means 100% on both G1 and Sholes.

Implemented Safari's window.devicePixelRatio and css media query
device-pixel-ratio.

So if you use "device-dpi" and modify the css for font-size and image
src depending on window.devicePixelRatio, you can get a better page on
Sholes/Passion.

Here is a list of options for "target-densityDpi".

device-dpi:    Use the device's native dpi as target dpi.
low-dpi:       120dpi
medium-dpi:    160dpi, which is also the default as of today
high-dpi:      240dpi
<number>:      We take any number between 70 and 400 as a valid target dpi.

Fix http://b/issue?id=2071943

So how do I use it?

Like this, for example: <meta name="viewport" content="width=device-width, target-densityDpi=device-dpi">

You may also want to add the "user-scalable=no" property to prevent the user from zooming in/out and to guarantee that your images are exactly as you designed them. You can read more about other viewport properties in Apple's documentation which originally defines the

Wednesday, April 14, 2010

Choice of Broadsides now available on iPhone, Android, Web

Choice of Broadsides, our newest game, is now available on iPhone, Android and on the web.

"Choice of Broadsides" is a multiple-choice swashbuckling naval adventure, in the spirit of C. S. Forester's Hornblower or Patrick O'Brian’s Aubrey/Maturin books, with a dash of Jane Austen.

We hope you enjoy the app, and we hope that you tell all of your friends about it! Our initial download rate determines our App Store ranking. Basically, the more times you download in the first week, the better we'll rank.

Share and enjoy!

Tuesday, February 02, 2010

The Code Bomb, or: The Newbie with Big Ideas

Are you considering making your first big contribution to an open source project? If so, don't make this mistake.

I've been working on open source projects for a number of years now. Sometimes, we've received feedback from potential new developers, saying something like this: "Your project looks great, and I'd love to help out. BUT your code is a mess. I'll help, but only if we XXX."

In this case, "XXX" is an expensive wide-reaching enhancement to infrastructure, something like:

  • Replace the automated build scripts
  • Refactor the code in a huge way
  • Add/remove a significant library dependency
  • Rewrite the code in another language

These are very risky infrastructure enhancements: they have a known large up-front cost, an unknown cost in bugs introduced during the enhancement, and unclear benefit, because typically the goal of the enhancement is to do exactly what the code already does, but in a better or more maintainable way.

In many cases it's very tempting to indulge in infrastructure projects like these, and as a result, I'm guilty of implementing my fair share of them myself.

But we have to say "no" most of the time; we're here to build something great, not to shave yaks. Especially since, in most cases, people who say "I'd like to help, but..." don't really want to help anyway; they don't usually stick around long enough to fix the bugs in the new infrastructure they suggested.

UPDATE: Newbie developers tend to want to propose big refactors partly because it's harder to read code than to write it, but also because it's easy to get used to crappy code over time.

In the worst case of this I've ever experienced, a developer "John" (not his real name) required a major refactoring of the code before he'd work on the project, but volunteered to do the entire thing himself. He decided to go dark; he returned, months later, with huge changes to the code, touching almost every file in the system.

In the open source community, we call this a "code bomb." A code bomb is a patch that's so large that no one can review it. Here's Ben Collins-Sussman on code bombs:

One of the main community "anti-patterns" we’ve talked about is people writing "code bombs". That is, what do you do when somebody shows up to an open source project with a gigantic new feature that took months to write? Who has the time to review thousands of lines of code? What if there was a bad design decision made early in the process — does it even make sense to point it out? Dropping code-bombs on communities is rarely good for the project: the team is either forced to reject it outright, or accept it and deal with a giant opaque blob that is hard to understand, change, or maintain. It moves the project decidedly in one direction without much discussion or consensus.

When a developer (typically a newbie developer) drops a code bomb, it's perfectly fine to just say:

Sorry, we can't accept this patch because it's too large; it's a code bomb!

The onus is on the contributor to break it up into smaller reviewable patches, each of which fixes a clear bug.

In our case, we had to just reject "John's" patch, wholesale. Months of work were simply wasted! Don't let this happen to you!

UPDATE: Good commentary on reddit

Wednesday, January 06, 2010

Choice of the Dragon iPhone App Available

Available on the App Store

Choice of the Dragon is now available as an iPhone app! Please download and review it.

Coming soon: Facebook integration. Sign up for other mobile versions here.

Sunday, January 03, 2010

Choice of the Dragon Android app available

The Droid Choice of the Dragon is now available as an Android app! Please download and review it.

(And if you haven't played the web version yet, well, what are you waiting for?)

iPhone and other smartphone versions are coming soon. Sign up for other mobile versions

Sunday, December 20, 2009

Announcing: Choice of the Dragon

I've been working on this game for the past few months:

Choice of the Dragon

Play as a fire-breathing dragon who sleeps on gold and kidnaps princesses for fun.
In the course of developing the game, I designed a programming language called "ChoiceScript" specifically for multiple choice games; I also wrote a bunch of text for the game, along with my friend Adam (with help from Kevin). Please share this with friends!

Saturday, August 22, 2009

StumbleUpon Doesn't Honor Permanent Redirects

The folks at StumbleUpon just gave me the worst website advice that I have ever heard.

When you change your domain name, StumbleUpon refuses to follow the permanent redirect to your new site. They recommend leaving the old website up with a "please click here" message instead!

Wait, really?

StumbleUpon provides a browser toolbar with a "Stumble!" button. When you click the button, it sends you to a random web page, and lets you rate it. If lots of people like your page, StumbleUpon will send more people there.

I've been running an online game from my personal website for about eight years. It eventually got pretty popular, averaging ~2 million pageviews a month. The load became too much for my home DSL connection, so about a month ago, I decided to move the game to Google AppEngine, on a separate domain. I diligently set up a permanent (301) redirect from the old website to the new website, and notified Google of my address change using Google Webmaster Tools.

For a while, everything was fine, but then, all of a sudden, I noticed my traffic had dropped by 50%. Puzzled, I checked my logs.

It turns out that about 50% of my traffic came from StumbleUpon; they were sending me hundreds of new visitors a day, some of whom would play the game for hours at a time. The game is a lot of fun, so it got hundreds of positive reviews. Eventually, StumbleUpon grew to represent a huge fraction of my inbound traffic. Now, all of it is gone.

StumbleUpon now says, "We are showing this site as unavailable. Should we check again?"

UPDATE (Jan 5 2010): StumbleUpon has removed this warning message from their site, but they're still not sending traffic to the redirected URL.

I emailed StumbleUpon about this, and they gave me this advice:

Hello Dan,

Thanks for your feedback,

Unfortunately, once you've redirected a site, you
are losing all reviews and traffic from the
original URL. There is nothing we can do about
this, as each unique URL in our community has it's
own unique review page.

If we allowed transfer of reviews and traffic
counts, we would facilitate gaming of our system.
You may however do a different type of redirect:
keep the homepage of the old URL alive and insert
a link that users must click to reach the new URL.
That way, the review page for the old URL will
still be accessible and the site will still regain
it's viral momentum and get stumbled around. While
doing this, you can slowly build reviews and
traffic for the new URL.

I hope this helped.

Regards,
Monica
xxxx@stumbleupon.com

This is horrible advice; nobody should ever do this.

If you follow Monica's advice, search engines like Google and Bing will continue to send searchers to the old website instead of the new website. Both Google and Bing rank websites by how many people link to them. Since the old website has more links, it will rank higher in the search results than the new website. Eventually, hopefully, you'll have two websites in Google and Bing, each performing only half as well as they should.

This is bad for my users and bad for searchers. Nobody wants to see duplicate content in their search results.

Gaming the system?

Monica says that if StumbleUpon honored redirects, it could be used to "game" their system. After all, what if I one day replaced my website with a redirect to a spam website? Then StumbleUpon might send users to some spam site.

But that's silly. Anyone who could redirect my website to spam could just as easily put spam right on my website! Redirecting doesn't help me game their system at all.

On the contrary, instead they're asking me to turn my old site into a pointless "doorway" page, forcing their users to click on an extra link just to get to the fun stuff. How is that good for their users?

If you don't believe me, then maybe you'll believe Google. StumbleUpon may claim to be worried about spam, but Google eats far more spam than StumbleUpon. People try to spam Google all the time, often by setting up useful sites and then replacing them with spam sites. If redirects made it easier to "game the system", then Google would stop honoring them.

Instead, Google gives clear and explicit directions explaining how to change your domain name. They recommend setting up a permanent 301 redirect, and notifying Google of the change of ownership using Google Webmaster Tools.

StumbleUpon should learn a lesson from Google and honor permanent redirects. It's the right thing to do for my users, Google's users, and their users.

Sunday, April 26, 2009

Tipjoy is Insecure; Don't Use It

Tipjoy is a cool new site that lets you exchange micropayments over the Internet. Unfortunately, on their "createAccount" page, they prompt you to give them your password without encryption!

http://tipjoy.com/createAccount/

That URL should be HTTPS-only, not HTTP. If you enter your password on that page, any "man in the middle" can read it and use it to impersonate you on Tipjoy.

By capturing your password, the attacker can spend money that belongs to you, transfer money stored in your Tipjoy account into the attacker's account, etc.

Bizarrely, tipjoy.com does support HTTPS... they just choose not to use it on most of their webpages, including the /createAccount page and the /settings/account/ page where you go to change your password. (The /login page is HTTPS by default.)

You can even opt-in to transmit your password securely, by modifying the URL to use SSL: https://tipjoy.com/createAccount/. That may be an acceptable workaround until tipjoy fixes their site.

But, even knowing that workaround, you STILL shouldn't use Tipjoy to put a button on your site until they fix this issue. If you put a Tipjoy button on your site, your users (the people who like you and generously want to give you a small tip) will probably NOT notice the problem; they will just create an account using the default /createAccount link, exposing their passwords to a man-in-the-middle attack.

Hopefully Tipjoy will get the message and fix this soon. Frankly, as a payment exchange system, their ENTIRE SITE should be behind HTTPS, not just key login pages. This is how paypal.com works; it's also how most bank websites work. When money is on the line, you really can't accept anything less.

Saturday, November 01, 2008

SPOILER: Unlock Blue Frog "Cheat" Mode and Battle Mode in Quest For Glory 2 (QFG2) VGA Remake

What is Blue Frog Mode?

The original Sierra "Quest for Glory 2: Trial by Fire" EGA game had a "cheat" mode. If you typed "suck blue frog," you could use secret key codes to give you unlimited money, raise your stats, create any item, teleport to any room in the game, etc. Officially it's a debug mode, used by developers to test the game without playing through the entire game. Unofficially, most people use it to cheat.

The AGDI have released a VGA remake for Quest for Glory 2; it has a similar "debug" / "cheat" mode called "Blue Frog Mode." Finding it is hard, but unlocking it is easy.

Blue Frog Mode Menu

Unlocking the easy way

Just download this file (Qfg2vga.025) put it in your "Quest for Glory II" installation directory, which is probably in "C:\Program Files\AGD Interactive\Quest for Glory II." You'll need to replace the Qfg2vga.025 file that already exists in that directory.

Then just start the game from the beginning (or import a character from the previous game, "Quest for Glory I" aka Qfg1 aka "Hero's Quest"). Press F10 to activate Blue Frog Mode.

Unlocking the normal way

It's a little more work to unlock Blue Frog Mode yourself without "cheating." You have to find and capture the blue frog, and beat the game with maximum puzzle points.

First, you'll need the bellows from Issur, the weaponsmaster. Go to the Dervish; there's a lilypad in Dervish's oasis. Repeatedly exit/enter the oasis. Every time you enter the oasis there's a small chance that a tiny blue frog will be sitting on the lilypad. Use the bellows on the frog; you'll take the frog and keep it in your inventory.

Dervish Oasis with Blue Frog

Note that the bellows must be empty to find and capture the blue frog. Later in the game you have to use the bellows to capture the Air Elemental; once you've captured the Air Elemental, you can't get the blue frog.

Once you have the blue frog, you must finish the game with maximum puzzle points to unlock Blue Frog Mode. For non-Paladins, you need 500 puzzle points out of a maximum of 500; for Paladins, you need 550 puzzle points out of a maximum of 550. (If you're short a few Paladin points at the end of the game, you can choose to "decline" becoming a Paladin to lower the maximum to 500 points.)

Note that on the AGDI forums, some people have suggested that you also need to max out all of your character statistics (strength, agility, etc. need to be 200) to unlock Blue Frog Mode. You definitely do not need max stats. I was able to unlock Blue Frog Mode as a Thief imported from Qfg1 with Communications of 185 and Honor of 107. Admittedly, all of my other stats were at or above 200, so there may be some requirement around stats, but I doubt it.

Instructions on how to get the bellows and find the Dervish are available in CyricZ's excellent GameFAQs walkthrough for the VGA remake; no doubt it will be updated soon to include information on how to unlock Blue Frog Mode. If you're having trouble finishing the game with maximum puzzle points, CyricZ also includes a "Point List" in section 10C, which lists all of the possible ways to earn points. In some cases, you may need to restore your game or even start your game over from scratch to get maximum points.

Item/Room List

Here's a list of item numbers for Blue Frog Mode; here's a list of room numbers for Blue Frog Mode. Note that most room numbers just cause the game to crash with an error message.

Battle Mode

There is a second "debug" mode available called "Battle Mode." Battle Mode and Blue Frog Mode must be unlocked separately.

Battle Mode has five features:

  • Combat Tests: Battle any specific monster in "test" mode. In test mode, you won't die if you lose, but you also won't gain stats during the fight. (Not that you care because you've also got Blue Frog Mode, right?)
  • Damage Meter: See the exact amount of damage dealt in combat.
  • Summon Monsters: In the desert, cause a specific monster to appear.
  • Enable/Disable Random Encounters in the desert.
  • Set Battle Speed: Press Ctrl-Z during combat to slow down or speed up the fight.
  • Enable/Disable Auto-Critical Mode: All of your attacks become critical hits.

The easy way to unlock Battle Mode is to install this file (Qfg2vga.026) in your Qfg2 installation directory. Start a new game and press F4 to access the Battle Mode menu.

The hard way to unlock Battle Mode is to find, defeat and capture the secret Pizza Elemental, then beat the game with maximum puzzle points.

To capture the Pizza Elemental, you'll need an empty pizza box. You can find one outside the entrance to the Eternal Order of Fighters. In the simplified street system it's at the end of Saif Darb; in the classic street system it's at the end of Askari Darb, which branches off of Saif Darb.


Simplified

Classic

You can't find the Pizza Elemental until after you've defeated the Fire Elemental, on Day 5 or later. When you're ready, go four (4) screens South of Shapier, then about forty (40) screens West. Eventually you'll find the Pizza Elemental.

Defeating the Pizza Elemental is a lot of work, even at the easiest combat difficulty setting. I recommend unlocking Blue Frog Mode first, and using it to raise your Luck, Dodge and Weapon Use skill to 250 before challenging him. (You can raise your other stats to 250 as well, but if you start the fight with more than 200 HP or 200 SP, you'll be reduced to 200 HP/SP at the start of the fight.)

CyricZ's walkthrough includes some tips on how to defeat the Pizza Elemental. There's also a YouTube clip demonstrating how to beat him.

Basically, you have to step back and duck a lot (avoid jumping, it wastes stamina). Be sure to attack the elemental when he eats you or tries to eat a pizza. Eventually you'll run out of stamina; just patiently dodge the falling pizzas to recover stamina until you're ready to fight again. It requires quick reflexes and a lot of patience.

Once you've beaten the Pizza Elemental, use your pizza box to capture him. Then beat the game with maximum puzzle points (again, maximum stats are not required) to unlock Battle Mode.

Despite what you may have read elsewhere, you do not have to defeat Sweeping Sir James to unlock Battle Mode, or complete the Warrior's Diary. (See CyricZ's walkthrough for details on these optional missions.)

Monday, March 10, 2008

Java annotation parameters can't default to null

I don't update here often enough, but here's a tidbit I wish I'd found on Google earlier.

Suppose you want to write a Java annotation that has a parameter value, but you want its default value to be null. Well, too bad. It is illegal to write this annotation:

public @interface Optional {
   public String value() default null;
}

It's a compile time error. javac says "attribute value must be constant;" Eclipse says "The value for annotation attribute Optional.value must be a constant expression." In fact, it's not that surprising, because even if you didn't set a default value, writing this would also be illegal (same error):

@Optional(null)

What the error is saying is that you can't set a Java annotation parameter to null.

Why is this? The specifications are opaque. JSR-175, which defined annotations for Java 5, just says "If member type is a primitive type or String, the ConditionalExpression must be a constant expression (JLS 15.28)." JLS 15.28, in turn, says that constant expressions can be, for example, any of these:

true
(short)(1*2*3*4*5*6)
Integer.MAX_VALUE / 2
2.0 * Math.PI
"The integer " + Long.MAX_VALUE + " is mighty big."

Notice anything missing? That's right, null. You can never pass null as a Java annotation parameter value, because, uh, null isn't a ConstantExpression.

Why? We may never know. The only thing you can do is workaround it, like this:

public @interface Optional {
   public String value() default NULL;
   public static final NULL = "THIS IS A SPECIAL NULL VALUE - DO NOT USE";
}

... and then make your code carefully treat Optional.NULL as if it were really null.

LAME!

Friday, January 11, 2008

BART Tracker

BART Tracker reports on arriving San Francisco area BART trains in real time, using a system tray icon.

It uses BART's new "Estimated Arrivals" or "BART System Status" feature, that reports on the current up-to-the-minute status of arriving trains at every BART station.

Thursday, October 18, 2007

Hudsuckr: Advanced Windows proxy configuration from the command line

Windows stores proxy configuration settings in the registry, in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings. However, the settings there like "ProxyServer" "ProxyEnable" can be somewhat misleading, and certain advanced settings (like the setting to "Automatically detect settings" using WPAD) aren't available as separate registry keys.

In IE4, proxy settings were stored in the "Internet Settings" key as simple strings (REG_SZ) and ints (REG_DWORD), but since IE5 it has been possible to set proxy configurations separately for each Internet connection. For example, you could set up your computer to use a proxy when you're using a VPN, use WPAD when you're on dial-up, and to go directly to the Internet when you're corrected directly using the LAN. These "per connections" settings are stored in the "Internet Settings\Connections" key; unfortunately, they're stored there in REG_BINARY blobs that are not meant to be edited directly. (When you use the "Internet Options" Control Panel, it automatically updates both the REG_BINARY blobs and the regular registry settings in "Internet Settings" automatically.)

That makes it difficult to configure "per connection" settings (like WPAD) using command line tools, including proxycfg.exe and others. We needed to be able to automatically enable/disable WPAD in Selenium RC, so I've coded up a simple command-line executable called "hudsuckr" that lets you do it. (It's named after the classic 1994 Coen brothers movie The Hudsucker Proxy. "Hudsuckr" contains no "e" because that makes it easier to Google and because it makes it more Web 2.0. ;-)

Here's the usage documentation that you get when you run "hudsuckr --help" from the command line:

    Hudsuckr Windows Proxy Configuration Tool: "You know, for kids!"
    
    Windows manages Internet proxy connection information in the registry;
    each Internet "connection" can have its own separate proxy
    configuration.  These settings correspond to settings in the "Internet
    Options" Control Panel, under the "Connections" tab.
    
    Run "hudsuckr" without arguments to print out the current proxy
    configuration details.  We print out the name of the current active
    connection, the four connection flags (DIRECT, PROXY, AUTO_PROXY_URL,
    AUTO_DETECT), and three strings: PROXY_SERVER, PROXY_BYPASS, and
    AUTOCONFIG_URL. The seven settings are described in MS documentation
    available here: http://msdn2.microsoft.com/en-us/library/aa385145.aspx
    
    Run "hudsuckr" with exactly eight arguments to set the proxy
    configuration, like this:
      hudsuckr (null) true true true true "localhost:4444" "" "file://c:/proxy.pac"
    
    Specify the name of the connection first (or use the LAN settings by
    specifying "(null)"), then set the four flags using "true" and
    "false", then the proxy server (with a colon to specify the port), the
    list of servers to bypass delimited by semi-colons (with "" as
    a special string that bypasses local addresses), and finally the URL
    to a proxy PAC autoconfiguration file.  Use "" or "(null)" to leave
    string settings blank/empty.
    
    If you're still confused about the flags, look at the proxy settings
    in the "Internet Options" Control Panel. See how you can check those
    checkboxes independently of one another? The flags correspond to those
    checkboxes.  If AUTO_DETECT is true, IE will try to use WPAD; if
    successful, WPAD will override the specified AUTOCONFIG_URL. If an
    AUTOCONFIG_URL is detected (by AUTO_DETECT) or specified directly
    (AUTO_PROXY_URL is enabled), IE will use the autoconfig script as a
    proxy PAC file.  If no AUTOCONFIG_URL was specified or detected, IE
    will attempt to use the server specified in PROXY_SERVER if the PROXY
    flag is enabled; it will bypass the proxy for the list of servers
    specified in PROXY_BYPASS. Finally, if PROXY, AUTO_DETECT and
    AUTO_PROXY_URL are all set to false, IE will attempt to contact the
    web server directly.  Note that the DIRECT flag always appears to be
    true, even if the PROXY flag is true; we recommend you leave it that
    way, too.

Here's what you might see if you run hudsuckr without command line arguments:

    > hudsuckr.exe
    ACTIVE_CONNECTION=(null)
    PROXY_TYPE_DIRECT=true
    PROXY_TYPE_PROXY=false
    PROXY_TYPE_AUTO_PROXY_URL=false
    PROXY_TYPE_AUTO_DETECT=false
    INTERNET_PER_CONN_PROXY_SERVER=(null)
    INTERNET_PER_CONN_PROXY_BYPASS=(null)
    INTERNET_PER_CONN_AUTOCONFIG_URL=(null)

Or, after you've configured lots of proxy settings:

    > hudsuckr.exe (null) true true true true "localhost:4444" "" "file://c:/proxy.pac"
    ACTIVE_CONNECTION=(null)
    PROXY_TYPE_DIRECT=true
    PROXY_TYPE_PROXY=true
    PROXY_TYPE_AUTO_PROXY_URL=true
    PROXY_TYPE_AUTO_DETECT=true
    INTERNET_PER_CONN_PROXY_SERVER=localhost:4444
    INTERNET_PER_CONN_PROXY_BYPASS=
    INTERNET_PER_CONN_AUTOCONFIG_URL=file://c:/proxy.pac

To turn off all proxies for the LAN connection, you might run a command like this:

    > hudsuckr (null) true false false false (null) (null) (null)
    ACTIVE_CONNECTION=(null)
    PROXY_TYPE_DIRECT=true
    PROXY_TYPE_PROXY=false
    PROXY_TYPE_AUTO_PROXY_URL=false
    PROXY_TYPE_AUTO_DETECT=false
    INTERNET_PER_CONN_PROXY_SERVER=(null)
    INTERNET_PER_CONN_PROXY_BYPASS=(null)
    INTERNET_PER_CONN_AUTOCONFIG_URL=(null)

Download hudsuckr.exe
Hudsuckr source code

Friday, September 07, 2007

Windows, killableprocess, and the Case of the Suicidal Parent (or: How to kill a process and all of its subprocesses reliably on Windows)

The two major browsers available on the market today (Firefox and IE) are sometimes "suicidal parents" when launched from the command line. That is, they occasionally have to re-launch themselves, by spawning a new copy of their executable (firefox.exe or iexplore.exe) and killing the currently running process. In these cases, the orphaned child process lives on to become the GUI that you actually see on the screen.

Firefox commits suicide when it sees that it needs to make significant adjustments to its user profile directory, e.g. when it has detected new versions of your extensions/add-ons. IE commits suicide on Vista when running in Vista's new "Protected" mode. When you launch iexplore.exe from the command line on Vista in Protected mode, your iexplore.exe process spawns a copy of "ieuser.exe" (if one isn't running already) and allows THAT process to launch a new copy of iexplore.exe.

This suicidal behavior is invisible to normal end users, but it can be very difficult for people who want to automatically launch and kill browsers for automated testing, like I do. For example, if you spawn a suicidal parent in Java and then try to .destroy it, you'll run straight into Java bug 4770092 (Process.destroy does not kill multiple child processes).

Benjamin Smedberg posted an interesting blog entry about a way to use Python to handle child processes: killableprocess.py. On Windows, killableprocess.py handles child processes by launching them inside of a Windows "Job" object. Processes within a Job may be assigned special security privileges or restrictions, and, by default, whenever any process in a Job creates a subprocess, the subprocess becomes a member of the same Job. (Job objects were introduced in Windows 2000.) It's easy and convenient to terminate an entire Job at once, killing all processes within it, even if the processes are orphans of suicidal parents.

Using Jobs to manage a process tree is a great idea, but not everybody in the world has the Python runtime installed, so I decided to code up something like it in C++.

The compiled executable (killableprocess.exe) can be used to launch any other process you like, assigning that process to a new unnamed Job. killableprocess.exe will automatically terminate if every process in the Job has died. It's also designed to handle shutdown signals (Ctrl-C and Ctrl-Break), to terminate the Job as killableprocess.exe is being shutdown. As a fallback, it additionally registers a "job limit" with the operating system to automatically kill the Job if killableprocess.exe is forcibly terminated. (Beware... the job limit doesn't work if you use Process Explorer.)

You can use killableprocess.exe as a wrapper around other processes that you expect to be suicidal parents.

Download killableprocess.exe
Source code for killableprocess.exe

Tuesday, May 08, 2007

"Buildable" JDK doesn't build on Windows: missing t2k.lib

What a mess.

This morning at JavaOne, Rich Green announced that you could at long last build a working JDK/JRE from GPL'd source... mostly. A few key libraries remained non-GPL'd (encumbered) so they had to be shipped as binary plugs. That's fine... we can work on that. If we can build the code, that is.

But if you go to openjdk.java.net right now, and go download openjdk-7-ea-src-b12-06_may_2007.zip and jdk-7-ea-plug-b12-windows-i586-06_may_2007.jar, you'll find that the JDK won't build correctly on Windows. Instead, you'll get this error message when you run "make sanity":

ERROR: Can't locate t2k import library.
       Please check your access to
           /c/devtools/jdk-7-binary-plugs/jre/bin/t2k.lib
       and/or check your value of ALT_CLOSED_LIB_DIR.

That file is indeed missing from the Windows binary plugs. We have a t2k.dll, t2k.pdb, and t2k.map, but no t2k.lib. At JavaOne today Dmitri Trembovetski confirmed that this was a real issue, and that t2k.lib is a core part of the graphics rasterizer, one of the key encumbered components of the binary plugs.

Dmitri also suggested a workaround, which I'm not too excited about but which would probably work: you could, if you wanted, go get the JRL JDK 7, accept the JRL, and build a t2k.lib from that source. I'm concerned about my contaminating the new GPL'd Java by doing that, so I think I don't want to do that. Instead, someone at Sun should probably release another version of the binary plugs archive with the necessary file(s) included.

Dmitri and Tom Marble suggested that I file a bug on bugs.sun.com, but bugs filed there aren't immediately visible via the web. I was not even assigned a bug number, so I can't reference it here. And, unfortunately, even though bugs.sun.com HAS a "build" category for J2SE bugs, ordinary users can't file bugs against it. I had to file the bug against "installation" instead.

Friday, December 22, 2006

JavaScript Support in Java 6 is WORSE than old Rhino 1.6

Java 6 is out, and with it, it includes built-in support for the Rhino JavaScript interpreter, warts and all. I've had a lot of problems with the Rhino JS interpreter, but astoundingly, the Rhino built-in to Java 6 is actually worse than the Rhino you can download from mozilla.org.

How, you ask?

Exceptions don't work

Well, first, it's got all of the problems you'll find in standard Rhino. The most annoying problem you'll encounter is that exceptions don't work. Here, eval this (in either Rhino 1.6R5 or Java 6):

try { throw new Error("urk"); } catch (e) { throw e; }

To eval this in Rhino, put this text in a file called "bug.js", run Rhino with "java -jar js.jar" and type "load('bug.js')".

"bug.js", line 4: exception from uncaught JavaScript throw: [object Error]

There's two things very wrong with this, one more serious than the other. The first thing wrong with it is that it's reporting the error on the wrong line number. The error was thrown from line 2, but rethrown in line 4. The stacktrace should show the source of the original throw (line 2), not the source of the rethrow (line 4). You'll find this as bug 363543 in Rhino's bugzilla. (I'd suggest that you vote for it, but you can't vote for bugs in Rhino!)

But the second problem is actually way more serious: it's missing the error message of the exception ("urk")! That's bug 351664 (recently patched, but not yet released in any official Rhino release). Since the JS interpreter didn't get the line numbers right either, you now know nothing about the cause of the exception!

Unfortunately, bug 351664 doesn't just apply to rethrown exceptions... it applies to regular old thrown exceptions, too. Here, eval this:

throw new Error("oh no!");

All you get is "[object Error]"... no hint of the error message.

Java 6 won't compile JS into .class files

The coolest feature of Rhino, IMO, was its tight integration with Java classes; you could compile JS directly to .class files that you could run directly in the JVM. (The IKVM guys used this trick to run JS on Mono.)

While Java 6 provides new support for a Compiler API, it doesn't even provide built-in support for compiling a string (you have to roll your own classes for that little convenience), and absolutely no integration with any other compiler, including the Rhino compiler. That means no JS files as classes.

Java 6 has no JavaScript debugger

But aside from inheriting all of the problems in the Rhino implementation, you'll soon find that Java 6 is lacking a critical feature present in Rhino. Rhino includes a JavaScript debugger, allowing you to set breakpoints, step in, step over and step return throughout your code, as well as set up watch expressions, observe the state of local variables, and so on.

But the new JSR 223 scripting API includes no debugger support. There's no way to stop on line 2330 of a long JavaScript file, set breakpoints, observe script-level variables, etc. The Java 6 scripting engine is just a black box with an eval function.