Junk Drawer – A quick and finally simple way to import misc data into SQL

Dale Newman’s post on Junk Drawer caught my eye and I put it on my To Read list (basically one of my browser tabs, mocking me until I got to it). I finally took time to read it and boy am I glad I did.

This definitely goes into my Bat Utility Belt of dev/dba tools. 🙂

Frequently I need to throw some data into SQL to query against, join against production data, etc, for instance when someone from another department throws a spreadsheet of staff at me and asks if I can add their email addresses. A quick join against our export of Active Directory and away I go.

However, getting this data into SQL is usually a mind numbing dance using the SQL Import Wizard, fretting that I’ll get a truncation error or assigning a column as an Int when clearly there was a single row on line 1765 that happened to have a decimal point. Ugh.

Junk Drawer is a tool that any of us should have thought of, and probably did, but Dale actually created. The article was a real pleasure to read. Dale is a fun and true programmer in that “good” techniques like dependency injection just don’t always make it into one-off toolbox tools. It’s the perfect mix of humor and real-world practicality.

Thanks Dale! If you ever quickly import misc data into SQL you own it to your sanity to check this out. 🙂

How to Create Great Rounded Corners on Images with an Alpha Mask and Paint.Net

For a recent website I was working on I wanted to have some nice looking rounded borders for the main body of the page and some of the images.  Since I’m an avid jQuery user it was a no-brainer to use the jquery.corner plugin.  It looks great and works across multiple browsers.  It defaults to using more modern CSS styles for newer browsers but falls back on some neat tricks for older browsers.

Unfortunately the tricks don’t always come out perfect and some users with older browsers complained the image corners were “jaggy”. Rather than tell any users they need a newer browser I decided to make it look nice without the hack, by actually creating images with rounded corners. Yeah, we’re still in the early 2000’s sometimes. Smile

Paint.Net is a great tool that meets many of the needs for web developers.  Naturally this was my first stop.  There are several great tutorials for corners and even some nice plug-ins already created, however, none of them seemed simple or did what I wanted.

For instance, here’s a great tutorial from Micah Sewell on manually creating rounded corners but, unfortunately, it forces you to use the rounded rectangle tool, which has no options for changing the corner size or getting it positioned exactly, nor does the process described create antialiased corners, an absolute must.

Here’s a great plugin by Tim Mathais for creating rounded rectangles for things like buttons, but this doesn’t work on an image that already has a background.

What I would rather do is draw upon the power of alpha masks.  If you don’t know what these are take a look at this great Wikipedia article.  In essence you use a grayscale image to change portions of your desired image opaque or transparent.  If you have a grayscale gradient from the top to the bottom and apply it as an alpha mask to your image your image will go from opaque to transparent from the top to the bottom or vice-versa.

Using Tim’s plugin and the Alpha Mask Import Plugin we can get exactly what we want: user customizable rounded corners on images with antialiasing.  Tim’s plugin allows great control over your borders and the coloring used for the mask.  The Alpha Mask plugin allows great easy features like pulling in the mask from the clipboard rather than having to save it first, which is exactly what we’ll do.

To do this simply:

  1. Load the Rounded Rectangles and Alpha Mask Import plugins into Paint.Net.
  2. Open your desired image in Paint.Net.
    image
  3. Create a new layer and switch to that layer for drawing.
    image
  4. Using the Rounded Rectangle plugin create a new rectangle with your desires properties.  To make this an alpha mask it needs to be grayscale so make sure you don’t use color.
    image
    SNAGHTML3f215674
  5. This should place a rectangle with your desired settings on the second layer.  My rectangle is simply black with with a radius of 20 and antialiased.
    test mask2
  6. Select the entire layer and copy it to the clipboard.  Now that the mask is in memory you can either delete the mask layer or simply hide it.  I sometimes make mistakes and hate redoing work so I just hide mine until I am sure that I’ve got what I need.
  7. Now, on your original image simply use the Alpha Mask plugin and it will default to pulling the mask you copied into the clipboard.  You may need to check the Invert Mask option depending on how you created the mask:
    SNAGHTML3f1e0430
  8. Hit OK and you’re all set with great results!  This process only takes a few seconds once you get it down and it is very customizable. 
    test mask

Enjoy! Winking smile

Should SSMS be built into Visual Studio?

SQLServerCentral sends out a daily email and today had an interesting offer to take a survey from redgate.  They were asking questions of Visual Studio developers that heavily use/interact with databases.

If you fit into this crowd help out by taking their survey here.

Initially I really distrust the idea of having SSMS like functionality within VS.  I know it is already there but I just have really avoided them, though I try to use them from time to time just to give them the benefit of the doubt.

For some reason Microsoft tends to like to dumb down anything in VS that’s not strictly developer oriented.  This is a huge separation from their current “give the power to the programmer” mentality when it comes to features like VS Add-Ins, NuGet, T4 templates, EF4 Code First, etc.  For some reason DBA tools have fallen into this “black magic, we’ll hide it for you” dark side of VS.  So, since VS 2003 and probably a little before, any database interaction was kept at a very high level.  You simply couldn’t dive right into necessary tools like T-SQL easily.

Consequently I’ve always developed with VS and SSMS side by side.  So, I’m in that old school stick in the mud crowd waiving my cane in the air shouting, “I’ll give you my SSMS when you pry it from my cold, dead hands!” Call me old fashioned.

As SSMS just continues to improve (throw SSMS Tools and other indispensible add-ons in the mix) I have had no desire to even attempt DBA functions within VS.  Honestly, SSMS is becoming so nice to use it is pretty much on par with my respect of VS 2010 as the developers IDE.  SSMS is the DBA’s tool of choice for me and quite happily so.

If they literally took SSMS and put it into VS I think I’d still avoid it.  The need to Alt-Tab between the two really creates a mental context switch in my head that helps my productivity.  Read my post on Alt-Tab Aids My Mental Context-Switching for more info on this, but it is a real productivity asset to think about.

If switching between SSMS and VS tools (literally and mentally) all inside the IDE were any more complicated than a simple Alt-Tab I would not be inclined to switch. 

It would need to offer enough extra "can’t live without" features to overcome the current simplicity of Alt-Tabbing between VS and SSMS.  For instance, I would love the idea of being able to code against a dev database and having the IDE help generate a change script, all which would be kept in source control.  The entire database design should be kept in my source control as well, so that when I add a column or an index the change script and create script are entered on the next commit.

Alt-Tab Aids My Mental Context Switching

A recent blog post about combining the functionality of SQL Server Management Studio within the Visual Studio IDE got me really thinking.

Any any given moment I have at least 6-8 applications running, usually quite a bit more.  When developing an app I usually have a work environment consisting of VS 2010, SSMS, Firefox (with at least 6 tabs open), Outlook, Word, etc.  Each application is only an Alt-Tab away.

I initially rebel at putting SSMS DBA features into VS2010 (yes, I know they are already there, I just don’t use them).  Much of this has to do with the fact that historically these tools have lacked functionality, but I now realize a large part is the mental context switching that Alt-Tab provides.

If someone walks into my office or a phone call grabs my attention I can easily Alt-Tab to another app, or simply Ctrl-T to open a new tab in Firefox (which starts at Google) ready to handle that particular request.  It doesn’t matter what I was doing before.  For some reason Alt-Tab simply puts my current mental state on the stack (forgive the metaphor Winking smile) ready to be called up when I Alt-Tab back sometime in the future.

Switching between different duties using Alt-Tab seems to really trigger a context switch in my head.  All this happens in the .2 seconds it takes to press Alt-Tab.

While DBA duties are really integrated into my development process (in my work I am the developer and DBA) I love the clean separation of concerns when I Alt-Tab between VS and SSMS.  Even if SSMS were completely duplicated within VS I don’t think I’d care for it.  There is just such a satisfaction with mentally putting on my DBA hat for SSMS work, even if it is simply for 20 seconds while I add a column to a table.  It just seems cleaner.  Unless the integration of the two tools really provides support that each tool individually couldn’t accomplish I actually see less value in combining these.  Additional features, such as integrating source control over my database assets and generating data migration scripts, would prepare me to mentally believe these two tools really should be combined.

Now I guess I need to start to evaluating add-ons and other tools based on how easily I can task-switch the context in my head when I need to use them.

Visual Studio JavaScript & CSS Outlining

Sometimes it’s the little tools that really make your day.

 

I finally got fed up with my growing JavaScript files and thought it would be great if Visual Studio allowed me to collapse functions just like it does with c# and other source files.  So I did a Google search.

 

Well, Velio Ivanov created a great little Add on that does just this and for CSS too!  Thanks Velio!!!

 

Check it out: http://jsoutlining.codeplex.com/

Adding a group of computers to an AD Group using PowerShell

PowerShell is a lot of fun but I don’t always get to play with it.  Anytime I have to do large tasks that move a lot of simple data or AD type tasks then I’ll sometimes pull it out.

Recently we installed Windows 7 across our district.  During that process we renamed all the computers because our old naming convention wasn’t always followed and it created a lot of confusion and inconsistency.

All our library staff computers have a special application that allows them to download barcodes that are read using a handheld barcode scanner for inventories.  This previously was pushed out by a group policy.  Since the computers were erased during the Win7 install and the computer names had changed we had about 25 computers that needed to be added to the group again.

Sounds like a perfect chore for PowerShell.

First of all, I forgot the name of the group that they needed to be added to, but I knew it had “dolphin” in the name, since that is the name of the software.  Active Directory Users and Computers (ADUC) won’t let you search on a portion of the name, just the beginning or the end.  Not much help there.

PowerShell makes this trivial:

Get-ADGroup -filter {name -like "*dolph*"}

This returned the following:

DistinguishedName : CN=g-InstallLibraryDolphin,OU=Computer,OU=Software Install,DC=valverde,DC=edu
GroupCategory     : Security
GroupScope        : Global
Name              : g-InstallLibraryDolphin
ObjectClass       : group
ObjectGUID        : 0909537b-ddcc-41c1-bd37-667fdb943a95
SamAccountName    : g-InstallLibraryDolphin
SID               : S-1-5-21-1659004503-746137067-682003330-69446

That’s the one!

Our naming convention for or library computers is wXX-Library, where XX is the two character code for the school the computer is at.  However, simply filtering on this wouldn’t help, because we name all our library student computers as follows: wXX-LibrarySYY, where YY is simply a number stating at 01 and goes up for however many student computers are in the library.

So, here is the PowerShell command that stores all our library staff computers into a $libcomps variable, excluding the student machines:

$libcomps = Get-ADComputer -filter {name -like "*library*" -and name -notlike "*libraryS*"}

Since you cannot pipe computer objects straight into the Add-ADGroupMember commandlet (why, I have no idea but it doesn’t make sense to me) you have to iterate over the $libcomps collection and add them one by one:

foreach ($c in $libcomps) {Add-ADGroupMember g-InstallLibraryDolphin -Members $c}

The command ran for about .25 seconds and did all the work for me.  I think researching the right commands to use took about 2 minutes, which is still faster than had I had to move them all over one by one. 

Heck, this post took longer than the entire task all together. Smile

Extending Your jQuery Application with Amplify.js

This was a pretty amazing article about how to extend your jQuery code even further using Amplify.js.  Elijah has a great writing style with very organized and clear examples. 

He first starts out with what I think is a pretty nice and clean example app.  Then he proceeds to discuss various improvements he makes using Amplify.js and refactoring to various patterns that really start to bring out the flexibility of the app.

Definitely take a look!

http://msdn.microsoft.com/en-us/scriptjunkie/hh147623.aspx

Microsoft Surface 2 with PixelSense

This is just amazing stuff.  When Microsoft Surface first came out you knew this was opening the door to the future.  All the flashy futuristic movies where video screens are interactive and everywhere, tables, walls, etc are now coming to reality.

With Surface 2 they have really taken a huge leap forward.  Now they are using LCD screens with what they call PixelSense technology.  Along with R, G and B pixels there is now a fourth pixel that can detect in the infrared range.  The LCD screen actually can detect the objects on the table.

What this does is change the older hardware with complex projectors, cameras and sensors into a sleek tabletop design.

Just to give you an idea here is what the original Surface typically looked like:

The large enclosed portion below the glass is actually hiding the set of projectors and cameras along with the computer hardware.

Now, with most of the complex sensing technology actually built into the LCD they can now produce tables that look like this:

I’ve seen Microsoft Surface products built into the wall at fancy hotels or casinos in Las Vegas.  Now we’ll start seeing a lot more of these pop up everywhere.

It’s an amazing time to be alive! Smile

Making F1 Do Something Useful in Visual Studio

Have you ever wished that hitting the F1 key in Visual Studio actually returned good search results in a quick manner? 

Personally I think the F1 key returns decent results, but there certainly are a lot out there who don’t.  I mostly work in .Net so I’m in the camp of users that F1 works well for.

The think I really don’t like though is the 30 seconds or so it takes to launch the help window.  Once you’re there navigation is pretty painful.

For the last several years I’ve all but abandoned F1 and just search Google with “msdn” and my search term.  95% of the time this returns exactly what I want in the first hit.

Wouldn’t it be nice if we could make Visual Studio do this for us?  Well, we can, and have been able to for years!

Check out OriginalGriff’s solution on Code Project.  He clearly outlines the steps and I have to say his solution is quite nice and tidy.

However, I had two very minor criticism, purely for my own tastes.  This solution opens the webpage inside of Visual Studio’s web browser inside the IDE.  This works, but I really like using my own default browser (currently Chrome).  This allows me to open up various hits in several tabs and bookmark interesting solutions.  I can’t do that in the VS browser window.

Second is it grabs the selected text and performs the search on this.  If you don’t select anything it just opens up a search for “msdn”.  The original F1 functionality use to search whatever word your text cursor was on, nothing had to be selected.  I’m lazy and I like this ability.

Last, but not least, as I was writing this blog post and stated above that 95% of the time my search term came up in the first result it hit me. OMG If I think that what I want will be my first hit, why not just return Google’s first result; the equivalent of hitting the older I’m Feeling Lucky button on Google’s home page. If you look at Griff’s solution you will see below it that I proposed an alternate solution that adds these three features.  Now, when I hit F1 or Shift+F1 I, respectively, get the Google search or the first hit directly.

Enjoy!