Saturday, July 9, 2011

Create Shortcut to Executable using C#

I needed a C# method to create a shortcut to an executable and place it on the user's desktop in Windows.

I found a method to actually create the shortcut which utilizes the Windows Scripting Host object model. Most examples I found used a separate icon file for the shortcut, whereas I wanted to have the shortcut icon by default be the same one used by the executable itself.

First you must create a reference in Visual Studio to the Windows Script Host Object Model COM object as shown here:



Below is the modified method, where sLinkPathName is the path to the executable.

using IWshRuntimeLibrary

...

private void appShortcutToDesktop(string sLinkPathName)
{
     try
     {
          WshShellClass wsh = new WshShellClass();
          IWshRuntimeLibrary.IWshShortcut scShortcut;

          // Choose the path for the shortcut
          scShortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\shorcut.lnk") as IWshRuntimeLibrary.IWshShortcut;

          // Where the shortcut should point to
          scShortcut.TargetPath = txtFile.Text;

          // Description for the shortcut
          scShortcut.Description = "This is a shortcut.";

          // Location for the shortcut's icon
          scShortcut.IconLocation = sLinkPathName + ", 0";

          // Create the shortcut at the given path
          scShortcut.Save();
     }
     catch (Exception ex)
     {
          MessageBox.Show(ex.Message);
     }
} 

Line 22 sets the shortcut's IconLocation property such that it grabs the default icon for the executable, the same one that you'd expect to see if you created the shortcut manually.



Saturday, July 2, 2011

Google +1 Button: Instant SEO

Google's new +1 button is the information innovator's response to the fairly ubiquitous Facebook, StumbleUpon, and other icons that let you promote content you find useful. I noticed that Google incorporated this feature into my search results as well, so I decided to experiment.

A popular blog post of mine describing a DIY screen protector for the Viewsonic G Tablet appears at spot #9 among my Google search results as shown below:



Note the greyed out +1 button just to the right of the link title, which animates tantalizingly as you hover over the search result. I went ahead and clicked it, essentially voting my link up in the rankings. Here's the result:





From the #9 to the #5 spot with one click?? I'll take it! You also receive a notification just below and to the left indicating that you've +1'd a given link.

I don't know whether "+1'd" has as catchy a ring to it as "Liked", but if it brings more traffic to my site, then I'm all for it!


Tuesday, June 7, 2011

Viewsonic G Tablet DIY Screen Protector

I recently purchased the Viewsonic G Tablet. Once you dump the factory ROM, it's great, but unfortunately its glossy surface is a fingerprint magnet and the glare can be pretty bad in bright light.


  
There are some commercially available, custom fit, and relatively expensive screen protectors out there, but paying upwards of $20 for a transparent piece of floppy plastic is a bit overkill in my mind. Another quite effective and relatively inexpensive solution to protect the screen involves using frisket film, a clear, nearly transparent adhesive film used for tracing, stencils, and related tasks.

I opted for the cheaper route. Care to try it? 

Here's how.

First get some matte frisket film. The "low tack" variety works just fine; it adheres snugly, yet can be easily peeled away without leaving residue. You can print out this template as a guide. Use some paper clips to secure the roughly 9 x 12" frisket film to the template. Then, using a sharp razor or knife, carefully cut along the whitespace between the inner and outer black borders. After cutting, you can trim the corners of the film to accommodate the curves of the tablet, and also cut out a notch for its built-in camera.

Thoroughly clean the surface of the tablet with a damp, lint-free cloth to remove dust and hair. Then, put on a pair of powder-free surgical gloves (latex or non depending on whether you're allergic or not), remove the backing from the frisket film.

Carefully apply the film onto the tablet surface. It helps to have a straightedge handy for this process. Begin with one edge and even up the border of the film with that of the tablet, then carefully smooth the film onto the surface of the tablet, and with a very careful scraping action use the straightedge to apply the film.

Bubbles may form, but some of these you'll be able to work out by carefully "massaging" the film's surface. Over time, any remaining bubbles that are tiny (roughly the size of pinholes) should gradually fade away.

I did notice that the translucence of the film did detract, but only slightly, from the sharpness of the text, but the photo below doesn't do the film justice. The touch sensitivity is just as good as it was prior to applying the film, and over time I'm guessing the minute bubbles will fade away.



Given that each sheet of frisket film in a 12 pack ends up costing around $1.25 apiece, the future prospect of replacing a worn film is far better than the initial cost of an expensive precut film. In this case, a little work means a lot of savings, as well as reducing glare without compromising the sensitivity of the Viewsonic G Tablet touch screen.


Tuesday, May 31, 2011

Perfection vs Excellence

The love of my life once told me, strive for excellence, not perfection.

Why?

Perfection is unattainable, whereas excellence is achievable.

Oxford’s defines perfection as the condition, state, or quality of being free or as free as possible from all flaws or defects” while excellence is defined as “the quality of being outstanding or extremely good”.

Perfection and excellence both are human concepts, so naturally we use these as tools in our interface with the universe. Myriad examples of the application of either concept abound, so to narrow the focus to one, consider a sword made of diamond versus a sword made of Damascus steel.

The hypothetical diamond sword.
The diamond sword is perfect. It’s been crafted out of pure diamond, one of the hardest known substances on earth consisting of a crystal lattice of tetrahedrally bonded carbon atoms, and has a razor-sharp edge that can slice a piece of tissue paper falling across its blade cleanly in two with the help of gravity alone. Against an unarmored opponent, this sword would likely slice their flesh to ribbons in the hands of an adept duelist.

However, lurking within this flawless weapon is a fatal shortcoming. The carbon atoms of a diamond are bound in a relatively brittle lattice configuration, which many practitioners of diamond cutting will attest is easily fractured. Indeed, transforming uncut diamond into precious jewel-quality stones relies on this inherent crystalline structure.




In contrast, there is the sword crafted of fine Damascus steel. Although the physical shape of this sword is the same as its crystalline counterpart, its molecular structure is vastly more complex and variable.

Closeup of a Damascus steel blade.


Research on Damascus swords crafted in ancient times has revealed that impurities in the steel ingots used to craft these swords led to the formation of what we describe today as nanowires and carbon nanotubes, structures which lend unique variability and resilience to the metal at the molecular level. In addition, Damascus steel blades have been found to contain a variety of elements as impurities, including carbon, manganese, vanadium, calcium, lead, and others.

Now envision these two blades, each executing two basic techniques of sword combat, the slash, and the parry.

The slash involves using the sharpened edge of the blade to slice the flesh of an opponent.

Slash.

Given the sharpness of the flawless diamond sword’s blade in this example, as well as that of the Damascus steel blade, and the target, say a pork belly, it seems clear that both blades will perform this straightforward task well. Indeed, perhaps the diamond will edge out the Damascus steel to some extent, similar to the way obsidian, a similarly brittle but remarkably sharp material exceeds the sharpness of surgical steel, reducing the extent of scar tissue in flesh.

The parry, however, is a bit more interactive. Rather than simply connecting the leading edge of a blade against flesh, a parry may involve blocking or deflecting a strike using the flat of the blade.

Parry.

Whether the diamond blade is giving or receiving the parry, it’s highly likely that the blade will break. Given diamond’s relatively inflexible crystal lattice, the odds are very much in favor of any impact fracturing that lattice and causing the blade at best to crack in two, at worst to shatter into the proverbial million pieces.

What does this say about the efficacy of striving for excellence in favor of perfection?

Perfection has honed the diamond blade to razor sharpness, given it crystal clarity, and made it capable of slicing flesh with the greatest of ease. The focus, and utility, of the blade are as uniform as the pure carbon it’s composed of. For the specialized task of slashing, it is masterfully suited to this role.

Excellence has granted unique characteristics to the Damascus steel by virtue of the impurities infusing its molecular structure. It may result in an incision which under a microscope appears more jagged, but the relatively flexibility and resilience of the blade enable it more likely to withstand a powerful blow.

The diamond blade illustrates simultaneously the appeal and the danger of embracing perfection. Perfection is flawless, sublime, but inherently fragile, whereas excellence, though not flawless, may better endure the onslaughts of the unexpected by virtue of the very imperfections which define it.