Measuring on-screen pixels

January 30, 2014

There are times when measuring pixels on-screen may be useful. This is especially true when following redline specifications (just make sure your browser zoom is set to 100%). There exist many free tools to aid in this task, and this SuperUser thread lists many of them. Luckily for you, I’ve tested most of the utilities proposed in the thread and the winner is… Cropper !

Image

Even though it’s a screen capture utility, it works very well for pixel measuring. Some of its useful features (the full list appears on their site):

  • Always On Top
  • F8 Show the main form
  • Arrow keys Nudge the main form one pixel (hold Ctrl for 10 pixels)
  • Alt+Arrow keys Resize the main form one pixel (hold Ctrl for 10 pixels)

When you need that extreme precision, you can use it in conjunction with the Windows Magnifier:

  • Win + ‘+’ Magnify (will also open the magnifier if not already open)
  • Win + ‘-’ Reduce
  • Win + Esc Close Magnifier

An honorary mention goes to Meazure. It is an excellent choice if you prefer a more verbose, extremely detailed UI with many features.

Image

There are also various browser extensions that offer similar functionality, but a global tool is obviously better (I actually didn’t like any of the extensions I tried regardless).

Introducing TvGameLauncher

January 12, 2014

I recently blogged about Playing PC games on your HDMI-connected TV, and I mentioned a couple of programs you could use to get the job done, along with a couple of batch files you could whip up to ease the process.

Secretly though, I knew it wasn’t enough. So I wrote TvGameLauncher to take care of everything for you (including something I forgot – preventing computer sleep). Everything is now done automatically in one fell swoop. 

For example, in order to run ioquake3 on your TV, you could run a command such as TvGameLauncher.exe -t -h 2 -s 0 -e “F:\Games\ioquake3\ioquake3.x86.exe”

And in order to run Hotline Miami (through Steam): TvGameLauncher.exe -t -h 2 -s 0 -l steam://rungameid/219150 -e HotlineGL.exe

Again, thanks go to Dave Amenta and Michael Welter for their useful utilities that made this possible!

I have some ideas for improvements, but this should suffice for now. 

Enjoy!

Image

Playing PC games on your HDMI-connected TV

January 4, 2014

Many people have a TV connected to their computer via HDMI as their secondary monitor. It is very convenient for HTPC usages, but playing games on the TV can be nice as well (especially when you have a gamepad connected).

The trouble is, most games will only run on the primary monitor, and the only way to get them to run on the TV is to make it the primary monitor. Windows makes this rather easy, but still, doing it manually each and every time before playing can be cumbersome. Fortunately, Michael Welter comes to the rescue with W7ToggleDisplay, a simple command-line tool that does the switching (don’t worry about the name, it works on Windows 8.1 as well). Simply run w7toggledisplay.exe /primary to make the switch.

Another annoyance is in the audio department. Presumably, when you play a game on the TV, you want the audio to come out of it as well (be it through its speakers or through some audio system connected to it). Since HDMI can carry audio, the easiest thing to do is switch the default playback device to the HDMI audio device. Again, this is easy enough to do but a nuisance to do every time. Fortunately, Dave Amenta created AudioEndPointController, a command-line tool that switches playback devices (even though the post mentions Windows 7, I’ve used it on Windows 8.1 without a hitch). First run EndPointController.exe and note the number identifiers for your regular and HDMI audio devices (the X in Audio Device X:). Then Run EndPointController.exe X where X is the number of the device you want to switch to.

Putting it all together

Now that we have all the prerequisites, we can create the following batch file to switch primary monitors, switch to HDMI audio output, run the game, and finally when the game is over switch everything back:

EndPointController.exe X
w7toggledisplay.exe /primary
Game.exe
EndPointController.exe Y
w7toggledisplay.exe /primary

Where X is the ID of your HDMI audio device, Y is the ID of your regular audio device, and Game.exe is the executable of your game.

Steam

Unfortunately, the above won’t work for Steam games, since they are not launched directly via their executable. Instead, they are launched via a special protocol that looks like steam://rungameid/219150. You can replace Game.exe above with start steam://rungameid/X where X is the steam ID of your game (as it appears in the original shortcut). This will launch the game, but the trouble is it won’t wait for the game to quit, switching the audio and display immediately back (the /wait switch doesn’t help). I haven’t found a way around that (if anyone is aware of one I’d be happy to hear), so for Steam games I use two batch files. One to switch primary display and audio, and run the game:

EndPointController.exe IdOfHdmiAudioDevice
w7toggledisplay.exe /primary
start steam://rungameid/SteamId

And then another script to toggle everything back (I give it a shortcut so I don’t have to find the icon on the TV every time):

EndPointController.exe IdOfRegularAudioDevice
w7toggledisplay.exe /primary

Happy gaming !

Mapping network resources to local files using Fiddler

December 9, 2013

In web development, it is sometimes useful to alter files locally on the client (browser) side and test their behavior.

For example, let’s say I’m the developer of Microsoft.com and I want to test mobile compatibility. One of the scripts participating in this mechanism, at the time of writing, is apparently http://www.microsoft.com/global/en-us/home/renderingAssets/wt_capi.js.

Now, say I want to make some changes to this file and test them out, but I want to make them locally on my computer. Maybe I don’t have access to the server right now. Maybe I don’t have a convenient testing environment. Maybe I want to test my changes on the production environment without affecting everyone.

Whatever the reason may be, Fiddler makes the process very simple.

  1. In the right pane, click the AutoResponder tab and check Enable automatic responses and Unmatched requests pass through
  2. Find the network resource you wish to replace in the Web Sessions list (in our case, http://www.microsoft.com/global/en-us/home/renderingAssets/wt_capi.jsand drag it to the AutoResponder rule
  3. Make sure the newly created rule is selected and in the Rule Editor at the bottom write the path of the local file you want to respond with, for example C:\wt_capi.js (you can also click the drop-down arrow and select Find a file…)
  4. Click Save in the bottom right corner.
Fiddler AutoResponder

Fiddler AutoResponder

All done. Whenever the browser asks for http://www.microsoft.com/global/en-us/home/renderingAssets/wt_capi.js, Fiddler will intercept that request and respond with C:\wt_capi.js (Fiddler will indicate this by highlighting the corresponding session in the Web Sessions list).

HTTPS

In order for the above to work with HTTPS, Fiddler’s certificate must be installed. This is highly not recommended to do on any machine in which you care about security, and ideally should only be done in a dedicated test-only VM. See the following article for instructions:

http://fiddler2.com/documentation/Configure-Fiddler/Tasks/DecryptHTTPS

Note that FireFox requires special handling:

http://fiddler2.com/blog/blog/2013/04/01/configuring-firefox-for-fiddler

For further information on Fiddler’s AutoResponder see:

http://fiddler2.com/documentation/KnowledgeBase/AutoResponder

A note on Chrome

Mapping is also supported in Chrome both natively and via extensions:

  1. Dev tools workspaces
  2. Tincr (extension)
  3. Devtools Autosave (extension)

However, I was not able to get any of the above to work as reliably as Fiddler.

Programmatically launching Visual Studio with parameters

July 21, 2013

In the group where I work, we don’t open Visual Studio (VS) solutions by double-clicking on them in Windows explorer, rather we have a special command-line launcher that takes care of that. The reasons why are unimportant, what I want to focus on in this post is the programmatic launching of Visual Studio when you want to pass it parameters beyond the file name.

Suppose you have the path of an SLN file in your hands, and you want to launch it in VS. Assuming VS is registered as the default application for SLN files (a reasonable assumption), the solution is pretty simple: Process.Start("foo.sln"). But what happens if you want to run it with a switch, say /Build debug? The previous approach won’t work. Instead, there are two things you need to do:

1. Find out the full path of the application registered to open SLN files - remember, you want this tool to work on any computer, regardless of where VS is installed (and which version is installed). Note that this application actually won’t be devenv.exe (VS’s executable), rather it will be VSLauncher.exe which analyzes the SLN file and decides which VS version to open. Finding its path is done by examining the registry, and I posted a function on StackOverflow that does exactly that.

2. Start VSLauncher.exe with the desired command-line:
Process.Start(vsLauncherPath, string.Format("\"{0}\" /Build \"debug\"", solutionPath));
(note the escaped quotes (“\) – they are necessary due to the way VSLauncher passes parameters to devenv)

Another usage example is elevating VS’s process priority on startup. As professional .NET developer, we spend most of our working days in VS, and we want it to be as fast as possible. Of course, setting its process priority as “High” manually every time is easy enough, but that’s easy to forget. Enter devenv.exe’s /Command switch, which allows you to run any VS command on startup. A command in VS can be many thing, but we’ll use it to run a macro (VS 2012 dropped macro support so this method won’t work for it).

  1. Open Visual Studio (tested on 2010 but should work in earlier versions).
  2. Hit Alt+F11 to get to the macros window.
  3. In the left pane, expand “Samples” -> “Utilities” and add a new function named RaisePriority with the following implementation:
    For Each proc As System.Diagnostics.Process In System.Diagnostics.Process.GetProcessesByName("devenv")
    proc.PriorityClass = ProcessPriorityClass.High
    Next
  4. Save

Now you can use the following code to automatically launch VS with high priority:
Process.Start(vsLauncherPath, string.Format("\"{0}\" /Command \"Macros.Samples.Utilities.RaisePriority\"", solutionFile))
(again,note the escaped quotes – they are necessary!)

MCE Launcher – Configure which programs are launched when MCE buttons are pressed

June 17, 2013

I’ve been using XBMC for some time as my HTPC driver. Having an MCE remote though, its buttons are configured to run Windows Media Center. I ran into the following blog post that offers a way to change this, but I didn’t like the implementation:

  1. It replaces the wrong file (ehshell.exe instead of  ehtray.exe) which caused me some issues
  2. It uses hard-coded locations and is specific to XBMC
  3. The code is not green in Resharper :)

So I took the code and generalized it to a small program that lets you configure exactly which program will be launched by which MCE button. The result: MCE Launcher (see the Readme file for installation and configuration).

 

 

Google Calendar ICS import error: “Failed to import events: Could not upload your events because you do not have sufficient access on the target calendar”

June 16, 2013

A couple of days ago I ran into the above error when I tried importing my ICS file into Google Calendar. A quick Bing search turned up a few results, and after some digging I found the root cause – UID collision (thanks Nick VE!).  Basically you need to delete all UIDs from the file and let Google assign new ones. There are many ways to do this, but Nick suggests a nice simple approach:

  1. Install Notepad++
  2. Hit Ctrl+O and open the ICS file
  3. Hit Ctrl+F and click the Mark tab
  4. In the Find what field write UID
  5. Tick Bookmark line
  6. Press Mark All
  7. Menu Bar -> Search -> Bookmark -> Remove Bookmarked Lines
  8. Save the file and try importing again

Of course, this is only temporary until I move my calendar to Outlook.com.

Tagger# – command-line media tagger based on TagLib#

October 1, 2012

Like I mentioned a couple of times, I like listening to and recording internet radio. Sometimes the radio shows I record are streamed in WMA format. Using Streamrecorder.NET, I’ve scheduled a weekly recording and so I have a folder filled with them. Now, the file names are timestamped, which means I can easily tell the date of each show. However, this radio station (and I suspect many others) has the nasty habit of changing the Title and Artist tags to the station’s name. This means that when I open this folder in my favorite audio player, all the files display as Some station – Some station which is pretty annoying. The solution appeared simple enough, just strip the WMA tag information from the file, right? Sure, but the only problem is that to the best of my knowledge, for around 10 years there hasn’t been a single windows command-line tool that is able to edit (or even display) WMA metadata. I haven’t seen anything for Linux and Mac as well, though I was less thorough in my search there. In any case, there is one now:

https://sourceforge.net/projects/taggersharp/

It’s basically a command-line wrapper over TagLib#, supporting most of its cross-format tagging options. To use it as a post processor in Streamrecorder.NET for the purpose I mentioned above, enter {in} -e in its arguments field. Check it out !

TaggerSharp

Recording internet radio

September 30, 2012

I’ve previously blogged about StreamRecorder.NET, which is useful for recording internet radio shows. However, sometimes you want to actually listen to the radio while you’re recording. You’d might also want to record tracks to separate files. Since StreamRecorder.NET is a front-end for other utilities, you could conceivably find a constellation that works for these cases as well. However, existing programs provide better alternatives. Screamer Radio is very nice, as is RadioSure. However, my favorite would be a far less known program: XMPlay. It is very minimalistic and does everything I want (I especially like its global shortcuts). Funny story, before I was aware of it I started writing a radio player of my own, based on the same library XMPlay is based on (BASS). You can see the result here. Suffice to say, I’ll be sticking with XMPlay for now :)

Working with the new SourceForge svn+ssh protocol in Windows

September 30, 2012

I’ve been using TortoiseSVN and AnkhSVN for quite some time with SourceForge. Both have been working flawlessly. However, SF recently updated their SVN system to use SVN over SSH (svn+ssh) for read/write access. For TortoiseSVN, this meant entering the password on every commit. AnkhSVN simply stopped working (something about not being able to open a tunnel to the repository). The recommended, secure fix for these problems appeared to be SSH keys. However, setting up my keys did not yield consistent results. TortoiseSVN worked, but most of the time it still asked for my password, which was annoying. AnkhSVN still didn’t work (it started plink which appeared to be stuck). I also didn’t like having Pageant running in the background all the time. Luckily, I’ve found another way. It may not be as secure, since you’re storing your password in plain text, but it’s good enough for me:

  1. Download plink.exe from http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe
  2. Place the plink.exe in your windows installation directory (%windir%)
  3. Open the following file using Notepad %APPDATA%\Subversion\config
  4. Add or Replace the following line in the [tunnels] section (replace login and pwd with your sourceforge login and password) ssh = c:\\windows\\plink.exe -batch -l <LOGIN> -pw <PWD> (note the double backslash)
  5. Save and close the file

Note that in step 4 I wasn’t able to use environment variables, even though the comments suggested it was possible. YMMV.

 


Follow

Get every new post delivered to your Inbox.