torstai 23. elokuuta 2012

Enabling Windows 7 hibernation mode

The hibernation setting in the shut down menu
It always seems to be a bit of a pain for me to figure out how to enable the hibernation mode in Windows 7 desktops. Hibernation is a mode where the current computer status is saved to the hard disk and the computer is then basically turned off. Waking up from hibernation takes far less time than waking up when the computer has been shut down completely, so I use hibernation almost exclusively. There's a TLDR tutorial on how to enable it (if it's not already available in the shut down menu), but I'll just write the short steps here:
  1. In Start Menu, type powercfg.cpl and hit enter
  2. With your selected power plan, click "Change plan settings" and then "Change advanced power plan settings"
  3. Set SleepAllow hybrid sleepOff
  4. Close the prompts you opened by clicking OK and Save changes
  5. From the Start Menu, find All Programs → AccessoriesCommand Prompt and right-click it, then select "Run as administrator"
  6. Now type powercfg -h on and hit enter. The hibernate option should now be available!

lauantai 16. kesäkuuta 2012

Frozen Synapse

Frozen Synapse is a cool game where you control a squad of soldiers by giving them orders and then watching them execute the orders for five seconds at a time. Your opponent does the same, and if you anticipated their moves correctly, you should see your soldiers take down theirs. The orders are given as waypoints and they can be arbitrarily complex, such as "back away from the door keeping your sights towards it, then wait for 0.2 seconds before turning and running across the hallway ignoring any possible enemies in there, and then duck behind the cover while taking a particular enemy to your sights". You can finish a turn in five minutes or you can grind it for an hour.

The game has several different modes and a "Dark" and "Light" variant of each. In the Light versions you always see where the enemies are, whereas in the Dark versions you only see the enemies that are currently in the field of vision of your troops. Once you lose a sight to an enemy in a Dark game a "shadow" of the enemy stays at their last known location along with an info text like "Last seen 2.8 seconds ago".

A maneuver assigned to a machine gunner.
The most popular modes are probably Extermination and Disputed. In Extermination both teams try to exterminate the other, plain and simple. In Disputed, the teams also try to kill each other again, but they also try to hold as much ground as possible in order to extract boxes that appear on the map after the fourth turn. Then there's also a Hostage mode where the other player plays as a hostage taker and the other tries to free the hostages. The hostages need to get to the edges of the playing area and they are controlled by the rescuer, but they can only be given instructions once. The hostage taker then tries to prevent the hostages from getting away.

In all game modes you can simulate the end result of a turn in the planning phase. This means that you can also assign commands to the enemy troops and move them around when you try to anticipate what the enemy will actually do. Simulating is crucial. The game is deterministic, so if in your simulation a soldier gets shot, he will get shot the same way in the actual outcome -- provided that everything stayed the same compared to the simulation. A slightly differently placed unit may yield a completely different result.

Let's watch a game of Dark Disputed I just finished. (Unfortunately the replay doesn't show the actual fields of vision for the troops.) The replay doesn't include the planning phases, just the action, so it lasts only 30 seconds. Remember that there was a planning phase every five seconds. I was controlling the green team and my enemy was controlling the red team. I recommend opening the video in a separate window and watching it with the HD quality:

Initially, both players can see the starting positions of each other's troops. I determine that no contact is likely during the first turn and just make my troops spread around and advance. At the end of the first turn, at 00:05, the enemy sniper at the left sees my machine gunner at the bottom and vice versa. The turn ends there and a subsequent simulation reveals that my gunner has no chance against the enemy sniper, so I order him to proceed, ignoring the sniper. On the other hand I turn the guy with the shotgun around, as sniper rifles have a way longer range than shotguns and at this point it doesn't look like it's going to be a close combat situation.

At 00:06 my sniper at the right gets an enemy gunner to his sights and takes him down a couple of seconds later; that's the first casualty of the game. The turn ends a second later when my gunner and an enemy gunner have just opened fire at each other. The simulation reveals that the bullet that's on its way already is going to kill the enemy, so he cannot dodge it and gets shot right at the beginning of turn three. During turn two my other gunner also ran up across the enemy sniper's line of fire because the simulation revealed that the enemy wouldn't have the time to take the shot. From his new position my gunner also opens fire against an enemy gunner trying to run down across the map at 00:10.

Again when I simulate the situation in the planning phase it appears that the enemy running down may be able to escape from my gunner who just opened a fire against him, so I turn the gunner in the middle to face the doorway in case the enemy would try to flank him. Luckily he takes the enemy down himself at 00:14, so there are only two enemies left now. My gunner at the bottom was ready to greet the enemy had he ran downwards instead of just stupidly staying put in the middle.

At the start of turn three my soldiers had caught a glimpse of an enemy gunner going into the room at the upper left corner. Since shotguns are very powerful at close range I decide to have my shotgunner clean the room and make an elaborate plan on how he would enter the room from the top door. I test my plan with the enemy soldier in every corner of the room until my shotgunner comes across as a winner in every scenario. The machine gunner and the sniper are his backup, and indeed the machine gunner engages in a firefight with the enemy right before the shotgunner enters the room and kills him at 00:19.

At 00:20 the fourth turn ends and the red boxes appear. My sniper is on the other side of the playing area and I decide that the three machine gunners are enough to take the final enemy sniper down, so the sniper goes to collect a couple of boxes. The shotgunner stays at the room he just cleaned and guards the windows in case the enemy sniper would run past them. Finally, it's the machine gunner that's ducked in the bottom room who kills the enemy at 00:23. The replay then plays for one more turn that I didn't actually play and you see my sniper exiting the area with the two boxes he had collected.

So, this hopefully gives you a fairly good picture of the game. Besides the multiplayer mode there's also a single player campaign and a possibility to play quick skirmish matches against the AI, but multiplayer is clearly the most interesting part of this game. The game is cross-platform so Windows, Linux & Mac versions exist. The game can also be bought from Steam, and there's an unofficial Frozen Synapse Wiki for you to use as a reference. Finally, it takes a little patience to really get into the game, but if you intend to play it you should probably also read this blog entry called How Not to Be Shot in Frozen Synapse. :)

torstai 17. toukokuuta 2012

Windows PowerShell

The Windows PowerShell
One advantage that Linux (and other Unix-like systems) has always had over Windows is the powerful command line interface. Linux systems provide the user with dozens of little programs that can be combined, or piped, together to do more complex things. For example, the ls ("list") command lists the files in the current directory. The wc ("word count") command counts the number of lines, words and/or bytes in the given input. Pipe these together, and you can get the number of files in the current directory: "ls | wc -l".

With the Windows Command Prompt these kind of operations have traditionally been way more difficult. Of course, I guess most people never use the Command Prompt, but those who do miss these powerful features from Unix-like systems. Nowadays, however, we have the Windows PowerShell.

The Windows PowerShell has been around for a few years already and I've been vaguely aware of its existence, but never really looked into it until now. It seems to be readily available on all Windows 7 installations, and most likely on Windows Vista as well. You can find it from the Start Menu.

Basics

When you start the PowerShell, you might want to see what commands are available. You can use the Get-Command command or its alias gcm for that. You'll see many lines of text that end with "...", i.e. they are truncated. Use Get-Command | Format-List  or the short form gcm | fl to see everything, or gcm Some-Specific-Command | fl to get info on some specific command only. And since the PowerShell commands aren't that short, you might only want to see the list of short commands, or aliases, available Get-Alias. The PowerShell commands are case-insensitive, so that would be the same as get-alias. And by the way, the default alias for get-alias is gal.

When you are accustomed to Unix shells the weird part in PowerShell is that it is object oriented. The pipes actually pass around typed objects rather than character streams. So when you "print out a list of files", you are actually rendering a collection object consisting of file objects. I won't go into this in detail but it is good to know this.

Replacements for Unix commands

So, what commands replace the most used Unix commands? Here are some of the most important ones in the format of Unix-command: Windows-command (alias):
grep: Select-String
cat: Get-Content (cat)
ls: Get-ChildItem (ls)
mv: Move-Item (mv)
cp: Copy-Item (cp)
wc: Measure-Object -line -word -character (measure)
cd: Set-Location (cd)
tail -n 15 : cat | select -last 15
tail -f cat -path -wait

Aliases

OK, so the PowerShell can do pretty much anything a Linux shell could, and often with the same command. However, there aren't ready made aliases for all the commands. Luckily, you can define more of these aliases by yourself. Let's create that grep alias: Set-Alias grep Select-String. There! However, there's still a problem: if you now exit the PowerShell, your brand new alias is deleted. Luckily, you can save these into your profile file. First, type $profile to see the location of your profile file. Chances are it doesn't exist so you need to create it. After you have done that you can add your set-alias commands into it. You can then easily edit the file by typing notepad $profile.

However, when PowerShell starts the next time it will give you a warning that "the execution of scripts is disabled on this system". The command get-help about_signing explains in detail what you can do about this, but the easiest way is to restart PowerShell with the administrator rights and to enter the command set-executionpolicy remotesigned. You can now close the admin shell and open it up again with your normal rights and presto, your aliases are available to you right from the start!

Functions

Unluckily, aliases can only be created for plain commands, not for commands with parameters or pipes. However, these cases can be dealt with by creating functions. Let's create a function called tail. Open your profile file and add these lines to it:
function tail($1, $2) {
    cat $2 | select -last $1
}
Then, in your PowerShell, reload your profile script: . $profile (notice the dot). Now, when you want to see the last 15 lines in the given file, you can just enter this command: tail 15 [filename]. Voilà!

Further resources

I read quite a few web pages when learning the basics of PowerShell and you will probably find them useful as well. First, Microsoft, of course, has an Owner's manual as well as a large collection of useful PowerShell tips. Second, Stack Overflow has thousands of questions about PowerShell answered. Third, a Windows PowerShell blog has a more detailed list of those Unix equivalents in PowerShell. Finally, as usual, Google is your friend!

perjantai 11. toukokuuta 2012

More good Android apps

It's been a few months since my previous post on good Android apps and since then I've discovered more great apps.

First, WhatsApp. WhatsApp is an instant messenger that feels just like sending free SMS messages. It's a cross-platform software, so you can communicate with your friends even if they are using iPhones or Windows Phones. You register to WhatsApp using your phone number, and the software finds everyone else who is using WhatsApp based on the numbers in your phone book. In addition to text messages you can also send images and videos. WhatsApp is free for the first year, then it's $0.99 per year.

Then, Pocket -- formerly known as Read It Later. The former title actually tells you what this app is about: it's about saving articles from the web to be read later. Sounds simple, and it is, but Pocket does it really well. Once you register to the service, you can start adding articles (or videos, or anything else) to your Pocket. There are bookmarklets you can install to your browser for saving any page with just one click. In Android, Pocket registers itself as something that shows up when you select "Share" from any application. Pocket strips ads, menus and side bars from the web pages and only shows you the article main content in a really clean way. Pocket even handles seamlessly those multi-page articles where you'd normally need to click "Next" every few paragraphs. You can also adjust the text size, screen brightness and such features easily when reading the text.

Finally, BaconReader for Reddit. Reddit is a "social news site" to where users submit links and the best links get voted up and show up at the main page. By default, the main page consists of links that mark the lowest common denominator between all Internet users, i.e. 75% of the links direct to funny images. But Reddit contains hundreds of sub categories, or subreddits, for every imaginable topic. Whether it's astrology, programming, bicycling or cooking, there's a subreddit for it. The TrueReddit subreddit contains long, serious articles, whereas the lolcats subreddit contains cute pictures of cats. With BaconReader you can choose which subreddits to follow and always get the newest links to your Android device easily.

tiistai 10. huhtikuuta 2012

Instagram

The popular photography app Instagram was recently released for Android. Previously it had only been available for iPhone, so I decided to give it a try.

Instagram is similar to another highly popular app called Hipstamatic. The idea is that you take a photo, crop it into square format and apply a filter that makes the photo look "vintage" or "retro". The analog-world counterpart of these apps is often called Lomography, after the cheap Soviet Russian camera Lomo LC-A. Why would anyone want to have their photos artificially aged? Others have discussed this elsewhere, so see, for example, this study or this essay.

Instagram is very intuitive to use: snap a photo, select a filter, write a caption, upload. You apparently cannot save any photos to your device: if you want to keep a photo you must upload it into the service. So Instagram is not only an app but also a service that hosts your photos. You can also find you friends there and subscribe to their feeds to get their latest photos on the main screen of the app. Or you can just browse the most interesting photos from all users.

There's something in Instagram that appeals to me. It sort of fills a need that I didn't know was there. To Flickr, I only try to upload my best and technically flawless photos. To Facebook I upload photos of events with my friends. But to Instagram I can upload any random photos. It couldn't be easier and you always have the camera (your smartphone) with you. Some people are into taking a photo every day, and I think Instagram is quite perfect for this kind of a project. In fact, I'm going to try it! Instagram doesn't have its own web interface for browsing the photos but an external service called Webstagram fills that void; see my photostream here.

Coincidentally, about five hours ago (as of writing this post) Facebook announced that it is going to buy Instagram for 1 billion USD. The figure is ridiculously large and I believe Facebook is never going to get their money back from that purchase, but hey, if they happened to have an extra billion lying around then why not buy Instagram with it. Molly Wood from CNET also questions the price tag, and some people believe that Facebook will now ruin Instagram, although Mashable's Chris Taylor says Facebook could actually improve Instagram. What happens, remains to be seen, but I'm not too concerned.

tiistai 3. huhtikuuta 2012

URL shorteners

Have you ever had to share a long link to some website with someone? Perhaps something like this: http://maps.google.com/?ll=60.169145,24.952417&spn=95.287566,270.527344&vector=1&hnear=Helsinki,+Suomi&t=w&z=3&layer=c&panoid=-fKxq5ulDCh5MjWvf2lsqw&cbll=60.169145,24.952417&cbp=13,-9.198922634831321,,0,-3.4772653749464837&source=gplus-ogsb? You can be sure that if you send a link like that over the email it gets cut at some point and breaks. So, what to do? Enter URL shorteners.

URL shorteners take a long URL and create a short alias for it. One of the oldest ones, if not the oldest, is TinyURL. The user interface is simple: you take your long link, paste it into the box on the site and click the button. The long link above then becomes a much more manageable "http://tinyurl.com/cs92l4u". On the site you can, in theory, also choose a custom name for your URL, instead of the randomly assigned string "cs92l4u". However, TinyURL is so old and popular that most good short names are already taken. If you want to know where a TinyURL link leads to, you need to add "preview." in front of the domain name like this: http://preview.tinyurl.com/cs92l4u.

TinyURL links are short and good for email and newsgroups, but they could be shorter. bitly is a good alternative for many reasons. First, the domain name they use by default is "bit.ly", i.e. just six characters instead of the 11 in "tinyurl.com". If you create an account to bit.ly you also get an access to the shortest possible short domain address "j.mp", which is just four characters. Second, bitly provides extensive tracking for the links shortened with it. Shortening the long link above gets me this: http://j.mp/H5Go2J. Now, when I want to see the statistics of any bitly or j.mp link I'll just add a "+" sign at the end of the URL: http://j.mp/H5Go2J+. Tadah! On that page you can also see a QR code for the URL, to be read with the camera of your smartphone. Unfortunately, bitly does not allow you to choose the name for your link: it's always a random string of characters. bitly does, however, allow you to create collections of links, i.e. bookmark lists. See, for example, my list of the most interesting TED talks.

Yet another URL shortener is is.gd, pronounced "is good". You can choose to have it log statistics and it also creates a QR code for your URL, but there's no registration or login required. The example link shortened to http://is.gd/yitefe with the "lower case pronounceable" option selected. The preview page is the URL with a minus sign added, and from that page you can also access the statistics (if you chose them to be logged) and the QR code: http://is.gd/yitefe-. is.gd is also newer and less popular than TinyURL so you actually have a chance of getting some meaningful short name assigned to your link -- for example, the http://is.gd/bookofjobs address now leads to my post about the biography of Steve Jobs.

The next URL shortener is called Tiny Arrows. The URLs created with it look really special: they actually have tiny arrows in them! Tiny Arrows never assigns a random string to your URL so you are forced to think of a name for your link, which is not bad. I shortened the example URL to this: http://➡.ws/senatesquare. What's also special about this shortener is that it doesn't take you to the target right away but actually shows a short countdown during which you see the actual URL of the page you are about to enter. You can also bypass this countdown by clicking a link or disable it altogether from ever appearing to you again.

Next, t.co. It's not a link here because it doesn't really have an user interface: it is integrated to Twitter. So when you post any link to Twitter, it gets shortened using t.co. They rolled this service out in 2010 when they decided that they want to track the links and that their users shouldn't need to use third-party services for posting long links to Twitter. Not much to say about this one besides that, but it's good to know about it. It doesn't give the tracking information to you, so if you want to track the clicks, you still need to use, say, bitly.

So, is that all? Nope, there are still some services worth mentioning, like the mcaf.ee shortener by the computer security company McAfee. Because they are a reputable computer security company, they have a pretty good idea on which web sites are safe and which ones may try to infect you with viruses. So, the mcaf.ee links are safe to click. They also display a frame at the top of the page telling you security information about it. The example URL to Google Maps that I've been using in this post is a bad example in this case because it breaks out of the frame, but take the Steve Jobs post again: http://mcaf.ee/mgj7b. You'll see the "This site is Safe" text at the top of the page, along with a link to a detailed site report (which, in the case of this blog, tells you almost nothing, but anyway..).

ShadyURL is the opposite of mcaf.ee: it creates links that look really, really suspicious: something along the lines of http://5z8.info/best-russian-sites-for-bootleg-everything_r7c1lr_b00bs for example. It's more of a satire of an URL shortener than an actual URL shortener. :) And finally, if all those links were too short for you, then HugeURL is your service: it expands any URL into a ridiculously long one!

OK, we are almost in the end. There are many utility services also built around the concept of URL shorteners. For example, there are various browser plugins. For Chrome, the bitly plugin creates and copies short URLs to clipboard with one click. There are also services that show you the expanded links, possibly as tooltips over the shortened URLs. For Chrome, there's View Thru for that. For Firefox there are URL Shrink Easy and Long URL Please for the same purposes.

Finally, a word of warning: like any other website, a URL shortener site may stop working. At that point all of your short links will also stop working. This is called link rot. So keep your important links in the full form and only use shorteners if you figure that no damage will be done in case the link would stop working in a week or in a year. You can lower the risk of your links rotting by only using reputable shorteners, such as TinyURL and bitly, even though there are actually dozens of URL shorteners available.