Saturday, December 13, 2008

Run Windows Apps Seamlessly Inside Linux


You love working inside your Linux desktop, but at the most inconvenient times you've got to reboot into Windows—whether to open a tricky Office file, try out a Windows application, or even just play a quick game. However, with some free tools and a Windows installation disk, you can have Windows apps running right on your Linux desktop and sharing the same desktop files. It's relatively painless, it takes only a little bit longer than a Windows XP install, and it works just like virtualizing Windows on a Mac with Parallels Coherence—except it's free. Here's how to set up Windows inside VirtualBox, and then get Windows apps running seamlessly inside your desktop.

Before getting started, make sure you have enough space on a hard drive for a Windows XP installation (meaning at least 5 GB) and enough memory to make two systems worthwhile.You can follow most of these steps if you want to try running Vista inside Linux, but your mileage might vary, of course (and check out this tip on making Vista's networking work).

If you're curious what the end result might look like, here's a screenshot from my quick installation. I would've loved to have gotten iTunes running, but I didn't have time to wait for all the post-XP-installation patches/upgrades to install to show you. (Click for larger image)

First off, we'll install VirtualBox. For most, that just involves heading to their package manager and installing all the virtualbox pacakges from the repositories; in Ubuntu 7.10 ("Gutsy Gibbon"), for example, you can use this terminal command

sudo aptitude install virtualbox-ose virtualbox-ose-modules-generic
If you don't see VirtualBox in your installation program, the app's downloads page has packages for just about every major distribution. After installing, give your username permissions to run VirtualBox (substituting "su" on some systems):
sudo usermod -G vboxusers -a [your username]

vbox_setup.jpgRestart your system for good measure, and now you should see "InnoTek VirtualBox" in your application menu—it was in "System Tools' in Gutsy. Get your XP CD ready and fire up VirtualBox. Choose "New" from the button menu, and then give your virtual system a name (WIndows XP usually works for me) and choose "Windows XP" from the bottom menu, then hit "Next." Decide how much RAM you'll dedicate to it in the next window, hit "Next," then, assuming you haven't done this before, hit "New" and follow the prompts to set up hard drive space for your virtual XP system. Make sure that partition is selected, hit "Next," then hit "Finish" to set up your new XP space.

xp_installing.jpgBack at VirtualBox's main screen, see if the "CD/DVD-ROM" menu is highlighted. If not, click it, and then check "Mount CD/DVD Drive," "Host CD/DVD Drive" (and make sure it points to your system's CD drive), and check yes for "Enable Passthrough." Hit OK, select your XP image from the left-hand column and hit "Start." You'll launch into the hopefully familiar XP installation routine; follow it through until you're at your Windows desktop.

vbox_drive.jpgNow you've got a working Windows inside a resizable box, but let's take this further. Remove your XP CD from the drive, head up to the "Devices" menu and choose "Unmount CD/DVD-ROM." In the same menu, choose "Install Guest Additions." VirtualBox should prompt you to download the Guest Additions ISO file, then select it to be mounted. This creates a virtual CD drive in XP, which you can get to through Start Menu->My Computer (it might take a moment to show up). Double-click the "CD drive" and follow the prompts to install the extra tools. Reboot once you're done for good measure, and restart the XP machine.

Once that's finished, you've got a "Seamless" option available in the "Machine" menu, or by holding down the "Host" key (Right Control by default) and hitting "L." Either way you run it, it drops the big window and deposits Windows' bottom taskbar on your Linux desktop. You can also ditch the main VirtualBox window at this point, if you'd prefer.

dual_taskbars.jpgThe Start panel's default bottom position can be a problem for GNOME-based systems, since you've already got an app-switching bar there. I recommend either moving your Start or GNOME menus to the left or right-hand sides, or setting your Start menu to double-height, which puts the Start button just above the GNOME bar. Either way, make sure you un-check the "Keep the taskbar on top of other windows" option on the Windows toolbar, or you might see a few graphical glitches. Otherwise, pretty neat, huh?

Now for the final piece: Synchronizing your Windows and Linux desktops. If you're running in Seamless mode, hold down the "Host" key and hit "Home" to bring back the virtual XP desktop. Select the "Device" menu and choose "Shared Folders." You'll be prompted to choose a folder from your Linux system; select your Desktop folder (usually found at /home/your username/Desktop). Head back to Windows, launch a command prompt (enter "cmd" into the "Run" dialog), and enter the following:

net use x: \\vboxsvr\Desktop
If it worked, you should see an X: network drive mounted in your "My Computer" window.

regedit_cropped.jpgNow for the final touch: Synchronizing the two desktops. In XP, hit the "Run" dialog and type in "regedit." Make a backup first (File->Export), and then navigate to HKEY_CURRENT_USER -> Software -> Microsoft -> Windows -> CurrentVersion -> Explorer -> User Shell Folders. Double-click to open the properties on the "Desktop" key you'll find there, and enter a new value of (without the quotes) "x:". You should see the change immediately—everything you put on your Linux desktop is shown in Windows and vice versa—handy for storing downloads grabbed in Windows.

If you'd rather do without the Start menu/panel integration and just want a few custom apps to open in their own windows, check out a helpful guide at Linux.com to getting this set up with some free tools and VMWare Server, which, while not quite as user-friendly as VirtualBox, is still a pretty nice package.

Got your own Windows-inside-Linux set-ups (besides Wine, which is another thing entirely) you feel like sharing? Have any suggestions/tweaks to this step-by-step? Share it in the comments and help two disparate operating systems find some harmony.

Hack Your Wii for Homebrew Apps and DVD Playback


Despite the fact that it ships with a DVD drive, for whatever godforsaken reason, the Nintendo Wii doesn't support DVD playback—until last week, that is, when a homebrew hacker released a tool that enables DVD playback on your Wii. The best part? You don't have to crack open your Wii or disturb your hardware in any way to install it. Let's take a detailed look at how to softmod your Wii with the Twilight hack to run homebrew apps. Then I'll show you how to install the Wii port of the open source media player, mplayer, to turn your Wii into a DVD (or should I say WiiVD?) player.

What You'll Need

Since we're going to be doing a softmod of your Wii (i.e., we're not modifying any hardware), you don't really need much to accomplish this hack.

twilight-princess.png

NOTE: I'm doing this all on a Windows PC, but you can manually install the Twilight Hack if you don't have access to a Windows PC.

The secret sauce lies in the Twilight Princess game. Essentially, we're going to load a fake game into Twilight Princess that exploits a buffer overflow and allows you install homebrew software on your Wii.

Sound complicated? Figuring it out may have been, but the excellent Wii hackers have made exploiting the Twilight hack a cinch.

Hacking Your Wii for Homebrew

00-format-disk.pngTo get started, plug your SD card into your computer. It needs to be formatted as a FAT16 filesystem, so find the SD card in My Computer and format it by right-clicking, selecting Format, and setting FAT as your file system. (If you have trouble formatting your SD card this way, try out the SD Card Formatter.)


Now it's time to prepare the SD card with the Twilight Hack. If you haven't already, download the Wii Brew SD Installer. When you've got it, make sure your SD card is plugged in and run the installer. The installer is fairly self-explanatory, but I'll walk you through it.

Choose Your Install Location


This should match the location of the SD card you just formatted above.

Select the Homebrew Features and Twilight Hack


Now you need to select the packages you want to install on your SD card (and, eventually, your Wii). I'd suggest selecting the Homebrew Channel (in fact, you need to if you want this to work), the Homebrew Browser, and DVDX (you'll need this last one for DVD playback). Make sure to select the Twilight Hack that matches your region. Hit Next and the Wii SD Installer will copy all the necessary files to your SD card.

Take Note of Your Twilight Princess Disc


If you're in the U.S., your copy of Twilight Princess is one of three different versions. One of the versions of the disc requires that you use a different save slot when we load the game later on, so just take note of the text on the inner circle of the bottom of the Twilight Princess game disc. (I needed TwilightHack2, for example.)

Perform the Twilight Hack on Your Wii

sd-card-in.pngBy this point, your SD card is officially prepared for your Wii. Unplug it from your computer and move over to your Wii. Plug it in and power up your Wii. At this point, you'll need to erase your current Twilight Princess saved game, copy the Twilight hack to your Wii, and execute it in Twilight Princess. (If you haven't played the game and created a save slot, you should do that before proceeding.) The video below from the WiiBrew folks details exactly how to do this.

NOTE: If the installation froze after you loaded the saved game and talked to the man, chances are you need to use the other saved game.


You'll need to accept a disclaimer and go through a few other screens to finish the installation (just use the 1 button on your Wiimote to accept). When it completes, head back to the Wii menu. The glorious new Wii Homebrew Channel awaits.

Turn Your Wii into a DVD Player


Now that you've got the Homebrew Channel installed, setting up DVD support is a breeze. Fire up your the Homebrew Channel from the main Wii menu and you should see the DVDx installer and Homebrew Browser. Click on the DVDx installer and run through the prompt. Hit A to select Normal install unless you've installed a modchip in your Wii. (If you're following this guide, chances are you don't have a modchip.) You've finished the first step.

Now you need to shut off your Wii and plug the SD card back into your computer, because it's time to install mplayer, the app that will play back DVDs on your Wii. You can download it from the HackMii web site at the bottom of this post. (Mplayer appears to be available in the Homebrew Browser, but it's not the version that supports DVD playback, so make sure you download it manually.)

After you've downloaded it, copy the entire mplayer folder to the apps folder on your SD card. Now just take the SD card back to your Wii, plug it in, and run the Homebrew Channel again. This time you should see mplayer next to your other installed apps, like below.


To play back a DVD, just fire up mplayer, insert a DVD, and select the Play DVD option in the mplayer menu. You'll notice two Play DVD menu items, the second of which reads Play DVD (libdvdnav). The libdvdnav attempts to use the built-in DVD menu, while the other just plays the first title. Unfortunately libdvdnav doesn't really work correctly with the Wiimote yet, but it looks to be on its way.

It takes a few seconds for mplayer to start playing the DVD, but once it does it plays without a hitch (or at least it has in all my experience). Thanks to YouTube, here's what it looks like:

The Wiimote/Gamecube controller playback shortcuts work as follows:

A - Pause
B - OSD
1/X - Toggle on screen menu
RIGHT - Seek 10s forward
LEFT - Seek 10s backward
UP - Seek 60s forward
DOWN - Seek 60s backward
+/R - Seek to the next chapter
-/L - Seek to the previous chapter
HOME/Z - Quit

What Else?

Once you've got your Wii opened up to homebrew apps, you've unlocked all kinds of potential, including emulators for old-school gaming consoles, different media players, and other utilities. If you've already got the Homebrew channel running on your Wii, let's hear what homebrew apps you've been using and loving in the comments. If the very idea of hacking your Wii sends shivers down your spine but you'd still like to squeeze out more functionality, check out how to use your Wii as a media center.

Turn Your $60 Router into a User-Friendly Super-Router with Tomato

A year-and-a-half ago, we showed you how to turn your $60 router into a highly configurable $600 router with DD-WRT, a free, open source firmware. Since then there's been a lot of development of open source firmwares, and today we're taking a look at my new favorite, a firmware called Tomato. Tomato does almost everything DD-WRT does—from Wi-Fi signal boosting to Quality of Service bandwidth allocation—in addition to offering a simplified interface chock-full of fancy charts and graphs. Sound good? Let's get started.

Check If Your Router's Supported

wrt54gl.pngBefore you go upgrading your firmware willy-nilly, be sure to check Tomato's list of supported devices. The router I'll be using is the very same router I used for the original DD-WRT guide, this Linksys WRT54GL router. Several of the Linksys WRT54G series routers are supported, but they aren't all, so make sure you check your model number. In addition to the pervasive Linksys router, Tomato will also install on some Buffalo, ASUS, and Microsoft routers.

Upgrade Your Router to the Tomato Firmware

So you've either ensured that you're current router is supported or you've ordered a new cheap one off the internet? Then it's time to upgrade that router to Tomato. First, go download the latest Tomato firmware (as of this writing, that's version 1.13). You'll download a 7zip archive, so use your favorite unarchiver (may I suggest 7-Zip), and extract the contents to an easy-to-find folder on your desktop.

Now you'll need to log into your current router to upgrade. This process may vary slightly depending on what router you're using and the firmware it's running, but for the most part it's very simple. You can go through the old DD-WRT step-by-step here if you're using a Linksys router with the default firmware (just replace DD-WRT with Tomato and quit after step 2). Below I'll describe the simple update process from DD-WRT to Tomato (which is virtually the same as it would be for any other router with one small difference).

First, point your browser to 192.168.1.1/, the default admin page for your router. If your router has a username/password set, you'll need to enter it to continue. Next you need to navigate to the firmware upgrade section of your router's admin panel. In both DD-WRT and the default Linksys firmware, you'll click the Administration tab followed by the Firmware Upgrade tab. Now just click the Browse button and direct your router to the appropriate firmware file for your router in the folder you unzipped earlier.

See the README file included in the Tomato_1_13 folder to determine which version you'll need to choose at this point. If you're using the same WRT54GL router as I am, pick the file named WRT54G_WRT54GL.bin. Now just click the upgrade button and wait. Be sure not to turn off your router during this upgrade.

reset-router-button.pngWhen it's finished, you're ready to start using Tomato. (Pretty simple, right?) Point your browser back to 192.168.1.1/ and log with "admin" (without quotes) as both your username and password. If you upgraded from DD-WRT, this may not be working for you. If the login isn't working off the bat, you've got one more thing to do: Perform a hard reset on your router. To do so, just find the little Reset button on the back of your router, then press and hold it for a few seconds. When your router comes back online, the "admin" username and password should work.

Boost Your Wi-Fi Signal

There's a lot you can do now that you're running Tomato on your router, but let's go straight to one of the sexiest tweaks supported by Tomato: Wi-Fi signal boosting. Just click on Advanced -> Wireless in the Tomato sidebar and find the entry labeled Transmit Power. The default transmit power is 42mW, but it's capable of transmitting at up to 251mW.

Tomato is a little low on documentation on this subject (okay, so it's low on documentation all-around), but the DD-WRT documentation suggests that an increase of up to 70mW would be "suitable for most users." A boost much above that could cause heat issues and considerably decrease the life of your router.

I can't attest to the certainty of damage beyond what the DD-WRT documentation says, but here is what I can tell you: I've been running my router with DD-WRT for over a year transmitting at 70mW, haven't seen any hiccups in performance and so far have seen no smoke. Even better, my Wi-Fi signal easily reaches to every corner of my apartment.

Track Your Bandwidth Usage, Set Quality of Service Rules, and More

From this point on, if there's something you want to do with your router, chances are Tomato can do it for you. In particular the bandwidth logging is both attractive and handy, allowing you to track bandwidth usage in real-time, over the last 24 hours, or with daily, weekly, or monthly reports. Real-Time Bandwidth Monitoring.png

A few weeks back I showed you how to set up Quality of Service rules on your DD-WRT router to ensure you don't drop Skype calls, lag on Xbox Live, and generally get your bandwidth when and where you need it. Tomato does all the same while providing even more granular control over how much bandwidth goes where... and, like the bandwidth reports, it graphs it all.

If you've assigned a domain name to your home server (like adam-lh.homeip.net), Tomato can send alerts to the service if you've got a dynamic IP address so that the domain will always point to your computer—even if your external IP address changes.

For a few other worthwhile uses, check out these videos for setting up Tomato's Access Restriction rules (allows you to set up rules to block browsing of certain topics at certain times, for example), using the Bandwidth Monitor, and putting your router into Wireless Client mode.

As I said above, documentation on Tomato is slim, but this Tomato wiki is a good place to start if you want to figure out a feature.

So Which Is Better, Tomato or DD-WRT?

After reading this, you may have noticed that Tomato shares a lot of features with DD-WRT; if you did, you're probably wondering which is better. Honestly, the two firmwares are both excellent—you won't go wrong running either. DD-WRT has a slightly more robust feature set and a bit more polish in the layout of the admin, but most features that you'll find in DD-WRT that are not in Tomato are features most home users will never use. Both do Quality of Service (in fact, we've already gone step-by-step through how to set up QoS in DD-WRT), though Tomato seems to do it a bit better; both can boost your Wi-Fi signal; and both will transform your router into something much better than it was before you started. At the moment I prefer Tomato for the simplicity of its layout, the excellent bandwidth monitoring tools, and of course, its attractive charts. If you're a DD-WRT or Tomato fan, let's hear which you prefer and why in the comments.

Adam Pash is a senior editor for Lifehacker who can't get enough of a good router. His special feature Hack Attack appears weekly on Lifehacker. Subscribe to the Hack Attack RSS feed to get new installments in your newsreader.

Thursday, December 11, 2008

Battle of the Hardware-Boosting Hacks

When like-minded hackers come together to unleash the true power of seemingly simple gear, it's truly a beautiful thing. We've featured a good number of how-tos and hacks over the years that make expensive upgrades unnecessary and unleash seriously cool features in your gear, and 2008 was no exception. In the last year, our iPhones and iPod touches got jailbroken all over again, our wireless routers were graced with a new super-charged firmware, our Canon digi-cams gained pro-level powers, and we learned that our Nintendo Wiis were even neater than we'd thought. Today, however, we wanted to take a long view on the best hacks that unlock the best features in our standard hardware, and ask our readers: What's the best one you've seen so far? Take a look at our gallery of gear-boosters, and vote on a champion, below.

Jailbreak tools for iPhones/iPod touch

When the iPhone 3G and its 2.0 software was released, some of us thought that might be the end of jailbreaking, or opening up your device to third-party, non-approved applications (and, in some cases, mobile carriers). We thought wrong, as there were many apps worth jailbreaking for, and the process got much simpler with the Mac-based Pwnagetool and Winpwn for Windows. The greater issue is that Apple's been roundly criticized for rejecting any software that "replicates" its own apps, and is somewhat secretive about just why it kills and delays other apps, so jailbreaking will likely always have a home on Apple's multi-touch devices.

Canon Hacker's Development Kit

If you've ever been intrigued by time-lapse photography, motion-sensing shutters that can capture lightning, or being able to shoot videos of any serious length, you might not need to shell out for a semi-serious DSLR model—if you've got a Canon, that is. The CHDK lets you do all that and more, including record your photos in the very work-able RAW format, get way more on-screen information about your shots and their settings, and, as Adam put it, generally turn your point-and-shoot into a super-camera. The possibilities are vast, given the number of user-created scripts the CHDK can run. And, in true hacker fashion, you can even play a game or two on your LCD screen (while you pretend to be setting up that staged photo mom and dad want, perhaps).

Homemade Wi-Fi extenders

Sure, you could give Linksys (or Buffalo, or D-Link, or Apple, et al.) the extra cash for an extended, wider-range router than the standard box you've tucked away in the living room or office. But if you don't mind doing just a few minutes of DIY work, you can also create your own higher-powered antennas. We've covered a few ways of doing so, including tinfoil and paper parabolas, internal wiring replacements, and, for that steampunk feel, cooking strainer extenders. If you want to actually boost the power your router gives up, well, we're covering that farther down, but these are all relatively safe and damage-free ways to ensure a solid connection throughout your house.

XBOX Media Center (and its variants)

Ever since our boss bought a "classic," first-generation XBOX off eBay and turned it into a media center with the open-source XBOX Media Center, she's been using to organize all the media that makes it to her television, stereo, and other screens. In the meantime, XBMC has spawned a number of intriguing remixes and spin-offs, including Boxee, and now works on pretty much any platform that's got video cards and a hard drive—Windows, Mac, Linux, XBOX models, and even Apple TVs. If buying another whole system just to watch your downloaded videos and stream MP3s across the house sounds like overkill, use what you've got with XBMC.

The Hackintosh

A good number of folks are impressed with Apple's OS X operating system, yet can't bring themselves to pay the hefty premium for the hardware that Apple says is required for it. But since Steve Jobs & Co. made the switch to Intel processors, a community of hackers has been working to make Tiger/Leopard/et. al. run on gear you can assemble yourself, and, as Adam showed us, there's now a command-line-free way to install OS X on a "Hackintosh" PC. Checking out the benchmarks, you'll see there's not a lot, if any, performance loss in using unlicensed hardware, and the best part is you can have the case and your peripherals look however you want, and cost whatever you can afford.

Super-Router upgrades — DD-WRT and Tomato

As mentioned above, some home network routers just can't reach around all the walls in your house. And if you want to set up specific bandwidth rules—giving you, say, lots of room for World of Warcraft at night, but throttling your BitTorrents while you're actually working—you're usually out of luck. Unless, that is, you've loaded DD-WRT or Tomato on your router. We've walked through installations of both systems and toured a bit of what they can do. Plus, as many have attested, they can make a router more stable, freeing you from frequent oh-crap-hope-that-page-saves runs to re-plug your misbehaved little guy.

Homebrew Wii

It's hard to say, exactly, why Nintendo didn't include DVD playback capabilities on its Wii game system, given that its games are, well, DVDs. So it was only a matter of time before a few clever folks came up with a way of getting homebrew apps and DVD playback on the Wii, without anyone having to bust out a screwdriver or soldering iron. You can add a lot more to that Homebrew Wii channel, and, if you're cool with Nintendo absolutely disliking your doing so, play backed-up Wii games on it. While you're feeling geeky, you can put your Wiimotes to use in reverse by controlling your computer with them.

Rescue old hardware with Linux

Okay, so it's not really doing anything to your hardware that a Windows installation doesn't do. But saving an older, lower-powered computer from e-cycling (or a long, slow twilight in the garage) is one of the main reasons Lifehacker readers switched to, or tried out, Linux. Seriously dated gear can often work just fine in a modern world with Puppy Linux or Damn Small Linux, and your mid-range systems—like, say, the last Dell you bought before this one—can be spun into a slick, webapp-focused system with gOS.

Rockbox and iPod Linux

Update: Added after the initial post, due to popular demand/outcry. No intentional slight intended!
In case you needed an example of Linux completely transforming seemingly outdated hardware into the new hotness, music monster Rockbox, and its games-focused counterpart iPod Linux. Rockbox is the glitzier of the pair, adding customized themes, CoverFlow-like shuffling and other current-generation features to your seemingly out-paced iPod, but iPod Linux gives you some serious freedom inside your tiny computer, and has a pretty nice roster of games. For a look around Rockbox, check out Adam's tour of the latest release.

Thursday, December 4, 2008

Dealing with Command Line Options in Python

I just wrote a bit of Python to generate some reports from the contents of a database. The one program that was more than just "display the data" was the one to print the transaction log. It included some sub-totals for various fields and paginated output.

The one task remaining was to give it some options. That is, to pass it some criteria that would modify the report. Specifically, I wanted a start and end date and the ability to change the sort order from the default which was transaction date.

Before just jumping into the brute force way of dealing with the command line I decided to see if there was anything interesting in the Python libraries that might turn this into something a bit more pleasant. Well, I found good news in the form of the optparse module. From O'Reilly's Python in a Nutshell, I found the following description:

The optparse module offers rich, powerful ways to parse the command-line options that the user passed upon starting your programs.

Sounds good. My next check was on python.org with equally positive information. So, I decided to give it a try. Here is the short story (followed by a bit of code).

  • First you instantiate the class OptionParser.
  • For each option you want to use, you use the add_option method where you can specify the options (both short and long ones are supported) and tell optparse what to do.
  • Once you are all set up, you use the parse_args method to do all the dirtywork. You then can just check for the existence of the options by checking for an attribute.
opts = OptionParser()
opts.add_option("--start", "-s", help="in format yyyy-mm-dd")
opts.add_option("--end", "-e", help="in format yyyy-mm-dd")
opts.add_option("--order", "-o", type="choice", choices=["tdate", "cname_id",
"account_id", "project_id", "id"], help="tdate|cname_id|account_id|project_id|id")
options, arguments = opts.parse_args()

if options.start:
...
if options.order:
...

That should be enough code. Each of the opts.add_option( lines adds an option to the list. For example, the first one says that it matches either --start or -s. The implied action is to store the argument associated with it. The help argument is used to specify a help message that is printed out either in case of an error calling the command or if the command is invoked with the -h option.

The third opts.add_option( line is a bit different. It defines the type of option as a choice and then includes a list of valid values. Entering anything other than one of these values results in an error message including the usage display.

The call to opts.parse_args() does the dirtywork for you. For example, if I had invoked the program with -s 2008-11-11 then options.start would be set to 2008-11-11.

All in all, I found optparse easy to understand and enjoyed separating all the error checking from using the arguments. There are lots more things it can do for you but this should get you started. It is now in my list of "Python tricks". __________________________

Phil Hughes

Vim as typewriting tutor

Vim is an advanced text editor, used by many free software fanatics. It is highly configurable, beside the default features it has a way to be enhanced using the built-in interpreter.

Who is this article intended for?

This article is intended for all people familiar with Vim, but also those who don’t know this marvellous tool. The main goal is to show that this editor is an advanced, fully featured program. We will show this by modifying its default behavior into a keyboard training program. The way it is performed might also be useful for translators - it only needs a few configuration tweaks and enabling the Aspell support.

Vim jako program do ćwiczenia szybkiego czytania (1)
Pic 1. Typewriting tutor (1)

What do we want to do?

Our goal is to convert the standard editor into a keyboard trainer program. Let’s make it so that every time it opens a *.keymaster file the program will open two windows, where the upper one shows the text to be typed, and the lower one will serve the training purpose, accepting the type-in.

Vim jako program do ćwiczenia szybkiego czytania (2)
Pic 2. Typewriting tutor (2)

Additionally, we need speed meters - a simple status line like “Typing time : 12s” might be enough for starters. This information will be cleared every time we enter the insert mode. It will be nice to see the typing time while key pressing.

The programming possibilities

Vim has an embedded interpreter that has astonishing features, especially considering that the program is a text editor. Making use of the interpreter we can almost indefinitely enhance Vim’s features.
To define a local variable, we need to use the ‘let’ keyword. Vim lets you create global, local and function-local variables.
A global variable is visible in all files Vim loads. Affects macros, plug-ins, configuration files.
A local variable is visible in the file they were declared at.
A function-local variable is visible only within one function, e.g.:


function NewNumberOneFunction()
let a:function_variable = "value"
endfunction

A global variable declaration would look e.g. this way:


function NewNumberOneFunction()
let a:function_variable = "value"
let g:global_variable = "global value"
endfunction

And the local variables look like :


let s:local = 333

The editor allows you to add new commands and use the automatically executed event handlers with ‘autocmd’. The commands can be grouped together, for example:


augroup group_name
autocmd {event name} {file extension} [{ command(s) }]
augroup END

The Vim features quite a lot of events to use in one’s scripts. The full list is available in the manuals.

How it will all work

First of all, we need to establish, what do we need, that is which functions and variables will we need.

We will need a variable that stores the starting moment of typing. It should be initialized right after entering the insert mode, so we will need to use the InsertEnter event. When the user finishes typing, by pressing escape (ESC) the typing time information should show up. Here we will need the InsertLeave event, which is executed when we leave the ‘insert mode’.

Vim jako program do ćwiczenia szybkiego czytania (3)
Pic 3. Typewriting tutor (3)

So, here is some clarification on the above outline: when we enter the insert mode, we store the starting time (in seconds) and when we leave, we calculate the difference between the start and the finish moment.

The following function, fetching the number of seconds and setting the keymaster_session to 1, might come handy:

function SessionStart()
let g:start_writing_time = reltime()[0]
let g:keymaster_session = 1
endfunction

But this is not all we need. It might be also handy to have two windows open: one will display the ready text, the other will accept data - doesn’t have to be the same text ;)

function GuiStart()
execute ":wincmd n"
execute ":wincmd r"
execute ":windo :set scrollbind"
execute ":syncbind"
execute ":resize -1"
endfunction

The GuiStart function is responsible for opening another window, executing ’scrollbind’ on all of them, setting the scrolling synchronization and adjusting the text entering window.

‘Scrollbind’ lets us scroll many windows at a time. Our script uses two basic windows that are to be scrolled together. The ’syncbind’ command enables the synchronization.

A function returning the current number of seconds since insert mode was entered would help too:

function CurSessionTime()
if !exists("g:keymaster_session")
let g:keymaster_session = 0
endif
let a:rs = 0
if g:keymaster_session == 1
let a:rs = reltime()[0] - g:start_writing_time
endif
return “[Typing time : " . a:rs . "s]”
endfunction

The Vim’s ‘exists’ function checks if the given variable exists. The global ‘keymaster_session’ variable tells us if the session is active : that is, have we started typing already or not ?

All’s well that ends well, so we need the last function : one that stops the current session:

function SessionStop()
let a:sec = reltime()[0] - g:start_writing_time
let g:keymaster_session = 0
execute “:echo \”[Typing time: \" . (a:sec) . \"s]]\”"
endfunction

All we need has been shown. The functions are executed with “:call FunctionName()”. Unfortunately, putting all the code above into configuration file is not going to work, so we need to “bind” the functions to given events:

augroup session
autocmd!
autocmd VimEnter *.keymaster call GuiStart()
autocmd InsertEnter * call SessionStart()
autocmd InsertLeave * call SessionStop()
augroup END

Such a system of functions lets us enable our ‘magic’ interface only when we open a *.keymaster file. Say, we contain the training text there.

Additionally, the following line will show the typing time in the status line:

set statusline=%<%f%<%{CurSessionTime()}%<%h%m%r%=%-20.(%3l:%02c%V:%L%)\%h%m%r%=-10(\#%n%Y%)\%P

All this, we insert in the .vimrc file or another .vim type file, loaded with a “source” command within .vimrc.

While training, we would like to know how many errors we have committed and where. Vim is able to provide such a functionality, it is enough to execute a “:set diff” command on all windows, or quicker : “:windo :set diff”, and if we want to disable the differences showing, we use “:windo :set nodiff”. Of course, one can also create a new mapping, like this:


map :windo :set diff
map :windo :set nodiff

If you like, you can use key mapping like this, to have the F2 key turn the diffing on, and F3 to turn it off:


map :windo :set diff
map :windo :set nodiff

Now, when F2 key is pressed we turn the buffer comparison on all available windows on, and with F3 we turn it off. It is possible to work while the diff option is enabled. To compare the windows we’ve been working on (to show differences) we type “:diff”.

Closing all windows with one command or key-press is not a problem :

:windo :q!

or

:windo :q

The first case will ignore the text we typed in, the second will not. It is noticeable, that the two-window interface with bound scrolling, only shows when we open a file with ‘.keymaster’ extension - and the typing time will show every time we open Vim. This can of course be adjusted to your needs.

Vim jako program do ćwiczenia szybkiego czytania (4)
Pic 4. Typewriting tutor (4)

Monday, December 1, 2008

How to Unlock/Jailbreak Your 2.2.0 2G iPhone Using QuickPwn (Windows)

These are instructions on how to unlock/jailbreak your 2G iPhone to the 2.2 iPhone firmware using QuickPwn for Windows. Before beginning make sure you have updated to iTunes 8.0.2.

Step One
Create a folder called Pwnage on your desktop.

Download the following files and place them in the Pwnage folder you just created:
- QuickPwn 2.2
- BL 3.9
- BL 4.6
- 2.2.0 (2G): iPhone1,1_2.2_5G77_Restore.ipsw

Extract the QuickPwn22.zip file to the Pwnage folder.


Step Two
Connect your iPhone to the computer and launch iTunes.


Select your iPhone from the list of devices on the left. Now hold down shift and click the Restore button. Restore is preferred as it won't create any wasted space on your iPhone.


Navigate to the Pwnage folder on your desktop and select the 2.2 firmware ipsw. Click the Open button to continue.


Step Three
Once iTunes has finished updating your iPhone to the 2.2 firmware you may launch QuickPwn.exe from the Pwnage folder on your desktop.


Step Four
Make sure you iPhone is connected to the computer and click the blue arrow to continue.


Step Five
Click the Browse button to locate your iPhone firmware.


Step Six
Select the 2.2 firmware ipsw from the Pwnage folder on your desktop then click the Open button.


Step Seven
QuickPwn will check to make sure the ipsw is valid. Click the blue arrow button to continue.


Step Eight
You can now select whether to Add Cydia, Add Installer, Replace Boot Logos, and Unlock Phone. Select the ones you would like to perform then click the clue arrow button


Step Nine
You will now be asked to select your bootloader files. Click the Browse button and select the 3.9 bootloader from the Pwnage folder on your desktop. Likewise do the same thing for the 4.6 bootloader file. Then click the blue arrow button to continue.



Step Ten
QuickPwn will now ask you to confirm your iPhone is connected via USB before continuing. Click the blue arrow button to proceed.


Step Eleven
QuickPwn will now automatically put your iPhone into recovery mode. Once its in recovery mode you will be prompted to: Hold the Home button for 5 seconds, Hold the Home and Power buttons for 10 seconds, then release the Power button and continuing holding the Home button until your iPhone is in DFU mode.


Watch the prompts carefully and follow along.

Step Twelve
Once QuickPwn detects your iPhone in DFU mode it will begin the jailbreak process.


Step Thirteen
Once jailbreaking is complete QuickPwn will inform you that it was successfull. Your iPhone will then proceed to run BootNeuter. This process will take about 5 minutes. Please be patient. Your iPhone will reboot when it has completed the process successfully!