Recently I was trying to use a Regular Expression in .NET. I was working with small blobs of text. I was trying to extract some code snippets out of some wiki markup.

The code snippets looked like:

{code:csharp|title=C#}
//C# Code
{code}
{code:vbnet|title=vb.net}
//VB.NET Code
{code}

For testing purposes I was using the simplest Regex I could think of {code:(.+?){code}. After playing around it became obvious that it was not matching over multiple lines. This makes sense because the ‘ .’ character  matches every character except /n/r

Well it turns out you want to enable SingleLineMode not MultiMode.  I know I know makes a ton of sense.

Lesson learned. Read the documentation.

Extra Bonus: If you want to quickly test .NET regular expressions with all these options. I found I like http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx

This method is a modified version of Mike Borozdin method which I happen to enjoy very much. The biggest changes I made where to add using statements around the disposable objects such as the Bitmap and the Graphics object to avoid memory leaks, as well as a few minor changes.

//Image Resize Helper Method
private static Bitmap ResizeImage(String filename, int maxWidth, int maxHeight)
{
    using (Image originalImage = Image.FromFile(filename))
    {
        //Caluate new Size
        int newWidth = originalImage.Width;
        int newHeight = originalImage.Height;
        double aspectRatio = (double)originalImage.Width / (double)originalImage.Height;

        if (aspectRatio <= 1 && originalImage.Width > maxWidth)
        {
            newWidth = maxWidth;
            newHeight = (int)Math.Round(newWidth / aspectRatio);
        }
        else if (aspectRatio > 1 && originalImage.Height > maxHeight)
        {
            newHeight = maxHeight;
            newWidth = (int)Math.Round(newHeight * aspectRatio);
        }

        Bitmap newImage = new Bitmap(newWidth, newHeight);

        using (Graphics g = Graphics.FromImage(newImage))
        {
            //--Quality Settings Adjust to fit your application
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height);
            return newImage;
        }
    }
}

Download:

Click here to download Pandora Keys from:https://samuelhaddad.com/downloads/pandorakeys/

Source Code:

https://github.com/SamPlusPlus/Pandora-Keys

Features:

  • Media Key support
  • Customizable keyboard shortcuts
  • Control Pandora from any application.
  • Auto updater for new features

Screenshots:

Desktop Application for Pandora.com

Requirements:

  • .NET 4.0
  • A Pandora.com account
  • Enjoy listening to music

Why Did I make this?:

I am a big fan of both Pandora, Jango, and streaming music in general.  I think they are great. However, I also feel that being a web-based application they lack features that exist in a desktop media player. For example, keyboard shortcuts and notifications are features I cannot live without.  After creating a desktop wrapper for Jango.com called Jango Desktop. I set out to create one for Pandora. There were already a few on the market, but I found they did not do what I wanted or were no longer being developed. My favorite used to be Open Pandora however it no longer seemed to be supported and many of the features no longer work. My code is based on the Open Pandora project but has the functionality that I was looking for.

Contribute:

Pandora Keys is open source. Please check out the project and jump right in. Programmers, graphic designers, or just your ideas, whatever your skills may be you are welcome to join the fun.

Donate:

coffee_128x128Do you like my work? How about buying me a coffee?

Disclaimer:

Pandora Keys is in no way affiliated with www.pandora.com. By downloading Pandora Keys you claim full responsibility for the use of this application.

When I was working as a Desktop Support Technician in college, I wrote a .NET C# Dell service tag finder because I dealt with well, many Dell computers. I decided to write a little program that I could carry on my flash drive with me and all my other technical applications. What I like most about this application is the ability to quickly get to the Dell Warranty and driver information. I hope that someone else finds this useful as well, if you do let me know.

DellServiceTagFinder

Download Dell Service Tag Finder: Source | Executable

This is was possible using Windows Management Instrumentation and if you are interested in pulling other information from your computer I recommend you read up on it. For this example, I used the Win32_BIOS Class, but you can find all the WMI Classes here.

Preview of Source:

        String dellServiceTag;

        private void Form1_Load(object sender, EventArgs e)
        {
            //Load Service Tag
            ManagementClass wmi = new ManagementClass("Win32_Bios");
            foreach (ManagementObject bios in wmi.GetInstances())
            {
                dellServiceTag = bios.Properties["Serialnumber"].Value.ToString().Trim();
            }
            Display.Text = dellServiceTag;
        }

Notes:

This application requires the .NET Framework or you may receive application errors.

The service tag is pulled from the BIOS so if you ever had your motherboard replaced and the service tag was not reset it will be blank.

The service tag is really the Serial of the machine, so other models such as HP will display the Serial, but the express code will be wrong. I will look into this when I have multiple machines to test on.

Music is everywhere with today’s high speed internet is most home it is no wonder that music is even moving to the World Wide Web. Many radio stations allow you to stream their stations over the internet. Many websites have been developed around music, like www.jango.com, www.pandora.com, and www.last.fm. I recently released my second version of Jango Desktop and one of the features I implemented was the ability to look up lyrics. Before I started I was thinking about all the ways I could parse the lyrics out of an existing lyric’s websites database. During my searching I stumbled upon http://lyricwiki.org/. Here is a small description of LyricWiki from the website:

LyricWiki is a free site which is a source where anyone can go to get reliable lyrics for any song, from any artist, without being hammered by invasive ads.

At this point you are probably thinking to yourself the same thing I did “Great, but where do I start?” So today I am writing a step by step tutorial on how to use Lyric wiki in your .NET program.

Creating a simple lyric demo program:

Step 1 Create the Form

Step 1: Create the Form

Open visual studio and setup your form to look similar to mine.

Adding the web service:

Because LyricWiki offers a web service, you will want to add it to your program as a web reference. Right click on your solution and select add a web reference, or in .net 3.5 add a service reference -> then go to advance and add a web reference. The service’s URL is http://lyricwiki.org/server.php?wsdl you will want to add it like below if you press go you should see the available methods.

Adding a Web Reference

Adding a Web Reference

Writing the code:

Double click on your button on the form and let’s right some code to handle the lookup.

Add this to the top of your code:


using LyricsLookup.org.lyricwiki;

Then add this to the button clicked method:


private void LyricsButton_Click(object sender, EventArgs e)

{

LyricWiki wiki = new LyricWiki();

LyricsResult result;

string artist = artistTextBox.Text;

string song =   SongTextBox.Text;

if(wiki.checkSongExists(artist,song))

{

result = wiki.getSong(artist, song);

Encoding iso8859 = Encoding.GetEncoding("ISO-8859-1");

LyricsRichTextBox.Text = Encoding.UTF8.GetString(iso8859.GetBytes(result.lyrics));

}else{

StatusLabel.Text = "Lyrics not found in database";

}

}

Then run and test.

Download the full solution of LyricsLookup