Monthly Archives: July 2012

Streaming spotify to DLNA device over network

From the moment Spotify came out I quickly became a premium user, and I use it daily to listen to my favorite bands. In the office I use Spotify for Windows and a headphone plugged in into my laptop, and in my car I use Spotify for iPad, which streams the music via a Bluetooth connection to the radio.

However, at home, I stream Spotify on my Windows 7 laptop to my Yamaha receiver or Panasonic television via the network. Because as a Telenet customer (a Belgian internet provider) it took me a while to figure out how to configure this, I will show you how I did it.

My setup is: Telenet modem is connected to:

  • a switch, which is connected to two laptops
  • a switch, which is connected to the Telenet digicorder; the Panasonic Vierra television and the Yamaha receiver

First install Jamcast, which is basically a media server for music:

Imagine having your entire digital music collection in your pocket wherever you go — no syncing, no ongoing subscription fees, and no storage limits. Take control of your music, and then take it with you everywhere!

It’s not free (but not very expensive if you decide to buy it), but you can download and install a trial to test it. You need it because if you play music with Spotify, it can capture the audio of the sound card and stream it to a DLNA device.

So after installation, start Jamcast and in network / options, enter the port number you want it to use:

dlna3

Before you continue, be sure to click the ‘Apply’ button, so that the server restarts itself!

Then, in network / remote access, click the Test button to see if communication works:

dlna4

Note: normally, all devices and laptops are in the same internal network in range 192.168.0.*. If this isn’t the case, ports might be blocked and you probably have to configure port forwarding on the Telenet modem/router. To do that, go to ‘my telenet’, click on ‘wireless settings’, then on ‘advanced’ and go to ‘port forwarding’ tab. There, add the port 55000 (or whatever port you are using for Jamcast) as follows:

dlna2

If the port test succeeds, continue configuring Jamcast. In Content / Virtual Soundcard, select the correct sound card:

dlna9

So now your server is running, and the Jamcast server should be visible on your DLNA device, for example the television:

dlna5

dlna6

dlna7

dlna8

On your laptop, play your favorite songs in Spotify; and after a few seconds (time needed to buffer the audio) the music will also start to play on your DLNA device. You can mute the sound on your laptop, the music will keep playing on your DLNA device.

Nice to know: Jamcast also has a .NET API that enables developers to build content provider plugins. More info here – they also have sample projects listed there, also related to Spotify integration!

Advertisements

Running visual studio as administrator

Running visual studio as administrator is often required, especially if you use IIS as a host for your web site. Therefore, I like it to be started as an administrator by default. So instead of right clicking it and selecting ‘run as administrator’, you can hack it a little bit so that it always starts as administrator, no matter how you start it.

Step 1: change ‘devenv.exe’ compatibility

First go to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE, right click on ‘devenv.exe’ and select properties, click ‘compatibility tab’, check ‘Run this program as an administrator’, and click ‘OK’:

runasadmin

Step 2: hack VSLauncher.exe

You have to hack VSLauncher.exe a little, because changing its compatibility settings won’t work with visual studio 2010:

  1. Backup C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VSLauncher.exe
  2. From within a Visual Studio 2010 Tools prompt (run as admin), extract the manifest from VSLauncher.exe:
    mt -inputresource:"VSLauncher.exe" -out:VSLauncher.exe.manifest
  3. Alter the VSLauncher.exe.manifest file:

    <requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false">
    </requestedExecutionLevel>
    </requestedPrivileges>
  4. Write back the manifest into VSLauncher.exe:
    mt -outputresource:VSLauncher.exe -manifest VSLauncher.exe.manifest

If you now start visual studio by its shortcut or by opening a solution file, it will start as an administrator.

Formatting strings

As a developer, we are constantly working with strings. I mean it, check your code, string operations are all around! And – I can’t help it – each time I see something like this:

var text = year + "/" + month + "/" + day + " " 
+ hour + ":" + minutes + " - "
+ "Completed in " + duration + "seconds.";

I have the irresistible urge to rewrite this to:

var test = string.Format("{0}/{1}/{2} {3}:{4} - Completed in {5} seconds.", 
year, month, day, hour, minutes, duration);

But is it a good idea to do that?

I personally use String.Format almost all of the time for a number of reasons.

First, (re)arranging/maintaining a string is a lot easier than having to (re)arrange/maintain a bunch of variables. Second, you can pass an IFormatProvider, so that you can easily specify formatting options for a specific culture. Third, it’s easier to spot errors. Fourth, consistency.

Now, you probably say: but what about performance?

Indeed, there are alternatives that are ‘faster’. StringBuilder, for one, is probably the most optimized. But really, does this even matter? We’re talking about microseconds here, and micro-optimization is in most cases something you should not think about – remember: premature optimization is the root of all evil:

“The First Rule of Program Optimization: Don’t do it. The Second Rule of Program Optimization (for experts only!): Don’t do it yet.” (Michael A. Jackson)

So unless you are working in a critical high-sensitive real-time system where microseconds are a matter of life and death; or you are messing around with thousands of string operations in a double loop or something; or hundreds of users are executing your string intensive code in parallel – maintainability and readability should be your prime concern.

If eventually performance is bad and should be improved, you can start thinking about measuring and optimizing it; but I hardly think that string concatenation would be your biggest concern in that case.

Productivity tools

During development, using the right tools can really boost productivity! So in this post I will list the tools I find valuable. If I find other useful tools, I will keep adding them to this list. If you have other suggestions, let me know!

Resharper

“ReSharper is a renowned productivity tool that makes Microsoft Visual Studio a much better IDE. Thousands of .NET developers worldwide wonder how they’ve ever lived without ReSharper’s code inspections, automated refactorings, blazing fast navigation, and coding assistance.”

I think Resharper is the number 1 productivity tool, that simply makes visual studio better. A must have. It’s not free, but worth the money.

Notepad++

“Notepad++ is a free source code editor and Notepad replacement that supports several languages.”

To me Notepad++ is not a replacement for notepad, it’s much much more!

Fiddler

“Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and “fiddle” with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.”

Fiddler is a free tool that saved me multiple times. It helps you analyzing the traffic so that you can identify quickly what is sent over the wire without the need of debugging your application.

LinqPad

“LINQPad lets you interactively query databases in a modern query language: LINQ.  Kiss goodbye to SQL Management Studio! And LINQPad is more than a LINQ tool: it’s an ergonomic C#/VB/F# scratchpad that instantly executes any expression, statement block or program with rich output formatting – the ultimate in dynamic development. Put an end to those hundreds of Visual Studio Console projects cluttering your source folder!”

Linqpad is a free tool that can save you a lot of time if you want to quickly test pieces of code. If you pay for it, you even get intellisense.

Productivity Power Tools

“A set of extensions to Visual Studio Professional (and above) which improves developer productivity.”

If you install Productivity Power Tools, visual studio becomes even more powerful. I especially like the improved tabs, but there’s more to discover!

Web.config Transformation Tester

“This is a simple tool that lets you test Web.config transformations.”

This is an online tool where you can test how a configuration would look like after a transformation.

.NET Reflector

“Reflector allows you to understand and troubleshoot .NET code where you don’t have the source. It helps you find bugs, fix bugs, and support development with libraries, components and new technologies.”

Reflector is not free, but can be a lifesaver if you need to find out how a third party assembly works under the hood.

ILSpy

“ILSpy is the open-source .NET assembly browser and decompiler.”

If you are looking for a freeware assembly browser, this one is probably the best!

GhostDoc

“GhostDoc is a Visual Studio extension that automatically generates XML documentation comments for methods and properties based on their type, parameters, name, and other contextual information.”

Writing code documentation is a tedious but important job. GhostDoc makes this job a little easier by generating documentation for you, but be aware that you still need to make sure your documentation is actually useful. There’s also a free version available.

Sysinternals suite

The Sysinternals Suite contains a large collection of individually executable PC troubleshooting utilities.“

This suite is a bunch of Sysinternals system utilities that you might feel useful, like process explorer which is probably the most well known.

TeraCopy

“One of the most common complaints about newer versions of Windows is the slow copying speed, especially when transferring lots of files over the network. If you want to speed up your copying or if you regularly transfer large amounts of data and have to stop the process to perform some other disk-intensive task, this program may be just what you need.”

TeraCopy is a compact program designed to copy and move files at the maximum possible speed.

TortoiseSVN

“TortoiseSVN is an easy-to-use SCM / source control software for Microsoft Windows and possibly the best standalone Apache™ Subversion® client there is. It is implemented as a Windows shell extension, which makes it integrate seamlessly into the Windows explorer. Since it’s not an integration for a specific IDE you can use it with whatever development tools you like.”

As a developer, this subversion client is simply mandatory, at least, if you use subversion.

Snagit

“Use Snagit to take a photo of your computer screen, including long webpages; create quick demo videos to share with anyone; enhance images with stamps, text, and effects; organize your screen captures with easy auto-storing and tagging features; share your images and videos to presentations, social media sites, and more.”

Snagit was actually one of the first tools I bought. And I use it daily!

WoVS Default Browser Switcher

“Enables quick and easy changing of VS default browser.”

If you’re working on a web site, often you want to test it in different browsers. This extension allows you to quickly select the browser of your choice.

Indent Guides

“Adds vertical lines at each indent level.”

This extension makes it easier to identify the start and end of blocks of code.

WcfStorm

“WcfStorm was built specifically for testing WCF services”

A handy tool that allows you to dynamically invoke and test WCF service operations (and more).

Terminals

Terminals is a secure, multi tab terminal services/remote desktop client.

This open source tool allows you to manage your remote machines.

Foxit Phantom PDF

“We all need to create professional looking PDF documents and forms for tasks such as developing personal documents, implementing workgroup collaboration, designing company forms, producing company collateral, finalizing agreements, applying digital signatures, or document archiving. Award winning Foxit PhantomPDF™ provides the right features at the right price, allowing you to produce great looking PDF document and forms quickly, affordably, and securely.”

This is not a free tool, but I bought it because I needed to create and modify PDF files (adding links etc.), and convert scanned documents using its OCR functionality. But you can do much more with it.

BitDefender Total Security 2012

“BitDefender Total Security 2012 is a very comprehensive security suite: strong antivirus, an accurate spam filter, configurable firewall, browsing protection, and multiple layers of real-time protection to catch malware before it’s able to cause any damage.”

My favorite all-in virus and malware protection software.

CoreTemp

“Core Temp is a compact, no fuss, small footprint, yet powerful program to monitor processor temperature and other vital information.”

My previous laptop had real issues with CPU temperature, and with this free tool I could analyze temperature evolution and decide it was time to buy another laptop Smile

DropBox

“Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!”

I use this tool to share my documents across multiple devices. Put one document in a folder on one computer and it is immediately available on all other devices you have. No need for using USB flash drives or external hard disks! There’s also a version for the iPad. I still use the free version that has 5.8 Gb of space.

KeePass

“KeePass is a free open source password manager, which helps you to manage your passwords in a secure way. You can put all your passwords in one database, which is locked with one master key or a key file. So you only have to remember one single master password or select the key file to unlock the whole database. The databases are encrypted using the best and most secure encryption algorithms currently known (AES and Twofish).”

Sometimes it’s hard to remember a password. This free tool let’s you manager all of your passwords in a secure way.

Virtual Clone Drive

“Virtual CloneDrive works and behaves just like a physical CD/DVD drive, however it exists only virtually. Image files generated with CloneDVD or CloneCD can be mounted onto a virtual drive from your hard-disk or from a network drive and used in the same manner as inserting them into a normal CD/DVD drive.”

If you have an ISO file, this free tool let’s you double click it as it was a real virtual drive!

RoundHouse

“RoundhousE (RH) is a database migrations engine that uses plain old SQL Scripts to transition a database from one version to another. RoundhousE currently works with Oracle, SQL Server (2000/2005/2008/Express), Access, MySQL, SQLite and PostgreSQL.”

This free tool makes it easy to manage and version your databases; so that you can easily create and update databases with scripts you create.

7 Sticky Notes

“7 Sticky Notes is a good 100% free desktop notes software that creates Sticky Notes directly on your Desktop. It has a really good-looking realistic sticky note appearance for ultimate user experience and it offers amazing and cool features that makes 7 Sticky Notes at the same time powerful, simple to use, reliable, and light!”

This little free tool allows you to put sticky notes on you desktop. Quite handy sometimes!

VirtualBox

“VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only isVirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL) version 2.”

I have different virtualized development machines for every customer, and VirtualBox is my favorite free software for that because it just works out of the box!

TweetDeck

“TweetDeck is a social media dashboard application for management of Twitter and Facebook accounts.”

My favorite twitter application!

BareTail

“A free real-time log file monitoring tool.”

I often have a lot of components running during development, each writing to their own log files. This tool allows you to monitor these log files in real time, and you can highlight specific entries with colors so that you can easily see them.

Evernote

“Evernote makes it easy to remember things big and small from your everyday life using your computer, phone, tablet and the web.”

I use this wonderful tool to keep track of all kinds of documents, so that I can easily search them on any platform, and also have a backup of them.

VSColorOutput

VSColorOutput can change the color of a line emitted to the output window based on specified rules. The rules consist of regular expressions. Rules map to classifications which in turn map to colors.”

This Visual Studio extension adds colors to the output window based on a regular expression. This way you can differentiate better between information, warnings, and error messages.

Sando Code Search

“Search your C, C++, and C# Solutions using the latest advances in code search research. Sando provides a great replacement for Find in Files and even the Open Type Dialog. It leverages Lucene.NET to allow users perform a Google-like search over their source code.”

This extension gives you lightning fast searching capability in Visual Studio!

See Through Windows

“Press a hotkey to make the current window transparent, allowing you to see through it! Press hotkeys to minimize/maximize the current window, or to send it to another monitor”

This small app allows you to make the current window partially transparent, so that you can see through it. I use it to see my mails in Outlook but also see my wallpaper at the same time.

Toad for Oracle freeware

“Toad® for Oracle is unrivaled for ensuring the greatest possible productivity in development and administration of Oracle databases.”

This is the FREEWARE edition of Toad™ for Oracle.

Iteration or recursion?

An interesting question came up… if you have to calculate the factorial of a number, how would you do it? As you know, the formula is simple:

rec1

My first thought was a recursive function:

public static int CalculateFactorialRecursive(int number)
{
if (number <= 1) return 1;
return number* CalculateFactorialRecursive (number - 1);
}

And an alternative would be a for loop:

public static int CalculateFactorialForLoop(int number)
{
var product = 1;
for (var counter = number; counter > 1; counter--)
{
product *= counter;
}
return product;
}

The question is: what method do you prefer?

Obviously the version that uses iteration is a lot easier to understand; and because I like simplicity it would probably be the best candidate. But what about performance? Doesn’t recursion also imply more overhead?

I created a small test that calculates the factorial of 1000 one million times; and the average duration for the recursive method was around 7300 ms:

rec2

The same test but this time using the iteration method was clearly faster:

rec3

So recursion is next to being hard to read also much slower. The reason is that each function call has to pop return value from the stack and push arguments on the stack, and also creates a stack frame (with information about the stack). All these operations take time. Also, you risk a stack overflow exception if too many stack frames are created (it is limited in size). And finally, because each call is accessing different parts of the memory, it hurts cache locality, which also means another slowdown.

Sure, if you only calculate one factorial, performance is not an issue. But in general, a more complex recursive function has more impact and performance may become a bottleneck.

Conclusion: only use recursion if it’s a natural solution for your problem and if performance doesn’t get hurt. In our example, we know in advance the number of iterations so we don’t need to use recursion; instead we can use a simple iteration that is much clearer to read and gives best performance.