How to Scale a jQuery Mobile Site for iOS


Posted on 25th July 2011 by r2 in iOS |jQuery Mobile

I was recently working on a jQuery Mobile application and everything looked great on my 21” touch monitor on several browsers, but when I deployed to the server and then hit the page on my iPhone, I ran into a few issues that I needed to work through in order to make the site what I’d call usable.

The first issue was that the site wasn’t scaling properly when it first loaded and everything was so small that I could barely click on it with my finger.  Certainly, this is not what I’d call optimal for a mobile site.


I originally played around with increasing font-size for the body and a few other quick CSS tricks, but nothing really did the trick.  I finally came across a meta tag which seemed to fix this issue. 

  1. <meta content="width=device-width, initial-scale=1" name="viewport">

This is what it looked like after adding this meta tag.


However, this created a new issue.  This second issue was that when I rotated from Portrait to Landscape mode, the web page did not scale properly and my toolbar buttons were now cutoff on the right-hand side like this:


I found numerous references to this known issue with iOS scaling and even found a few javascript fixes available around the web.  However, after a bit of experimenting, I found that I could fix the issue with just a few tweaks to the meta tag above and using no javascript.  The final meta tag looks like this:

  1. <meta content="width=device-width, minimum-scale=1, maximum-scale=1" name="viewport">


This is what the site looks like now when it’s rotated.


How to Include and Deploy Data using a Visual Studio Database Project


Posted on 24th July 2011 by r2 in Data |Visual Studio 2010

I’m a big fan of Visual Studio’s Database Project and I’ve used them successfully in several client projects.  If you are not familiar with using the Database Project, I encourage you to give it a look.  It gives me a nice warm feeling to see that the database schema and even necessary seed data is maintained in source control in the solution right along with the other projects.  For developers that need to get up and running locally, the joy of simply right-clicking and choosing “Deploy” is hard to beat.  

Most any reasonably-sized application will have lookup lists and other data that need to be there for the application to function properly. To my knowledge, there’s not really an automated way in Visual Studio to tell the Database Project that you want to bring the data into the project and have it be part of your deployment. However, there is a way to tap into the scripts that Visual Studio creates when it creates a new Database Project.

This post specifically addresses including and deploying data and is not intended as a general overview of Database projects.  There is plenty of decent material available on doing that.  To follow along with this post, you can simply add a new project in Visual Studio and choose the Database | SQL Server project type and select the SQL Server 2008 Database Project.


If you take a look in the Database project, you’ll see a folder called Scripts and under Scripts there are folders for both Pre-Deployment and Post-Deployment.  As we are interested in inserting data into tables, we obviously need to insert code in the Post-Deployment step when the tables actually exist. If you open the Post-Deployment folder, you’ll note a file called Script.PostDeployment.sql.  This script is run automatically after the database is deployed by the Database project.  The scripts that are created here can contain any valid SQL.  


You could place all of your post deployment INSERT statements into this Script.PostDeployment.sql file directly, but that can get ugly quickly. Instead, I like to create separate files for each table for which I want to INSERT data.  I generally name the files Data.[TableName].sql.  You can simply right-click on the Post-Deployment folder and choose Add | Script.   For instance, here I have added a Data.State.sql file that will insert all of the States into my State table after the database is deployed.  


Rather than hand-type my INSERT statements, I use SQL Server Management Studio (hereafter, SSMS) and let it do the lifting for me.  In SSMS, right-click on the database name and choose Tasks | Generate Scripts.  This will launch the Generate and Publish Scripts Dialog,  Under Choose Objects, you can make the choice of which tables you want to export.  Below, I selected the State table and clicked Next which shows the Set Scripting Options page. 


In the Set Scripting Options page, you’ll want to select where you want to export the INSERT statements.  I usually just select Clipboard and then paste that into the appropriate file in Visual Studio.  The most important part of this page is the Advanced button.  You’ll need to click this and go into the Advanced Scripting Options.


The default behavior of the Generate and Publish Scripts Dialog is to only script the schema generation and no data.  To change this to data only, you change the Types of data to script setting to “Data only”.   You can then click OK and run the export. 


Once the Generate and Publish Scripts Dialog has completed the generation of your INSERT statements, you can paste these INSERT statements back into the sql file you created earlier in Visual Studio.  Here you see I’ve pasted these into the Data.States.sql file that I created above.


Now that you have the INSERT statements in your sql file, you need to tell Visual Studio to run your sql file after the deployment.  Recall that the Script.PostDeployment.sql file created by Visual Studio is automatically run after deployment.  However, custom sql files that you create are not.  If you open the default Script.PostDeployment.sql file, you’ll see comments that tell you that you can use SQLCMD syntax to include a file and even gives you an example.  Here is my Script.PostDeployment.sql file with my custom Data.State.sql file included. 


You’ll likely notice that there are squiggle lines and you’ll likely get a build error on the 
Script.PostDeployment.sql file.  To fix this, you’ll need to change the mode to SQLCMD.  You can do this by 
clicking the SQLCMD button in the T-SQL toolbar.  



You should now be able to click the Execute SQL button to test run your Script.PostDeployment.sql file.  When you are ready to deploy your schema and seed data to a new database, you can now simply right-click on your Database project and select Deploy.  Remember to update your Connection Strings as needed and you should be off and running. 

Admittedly, this is a bit more manual than I’d like but the initial creation of the scripts goes pretty fast and the fact that the seed data and data schema are part of source control makes up for it in my book. 

If anyone has a way that works better for them, I’d love to hear about it.  

Portable and Efficient Generic Parser for CSV


Posted on 11th July 2011 by r2 in General .NET |Third Party

I recently had some pretty ugly CSV files to parse and decided to have a quick look around to see if there were any libraries around that would handle the specifics of these particular CSV files without me having to write yet another CSV parsing class.  I found a couple that seemed to fit the bill on Code Project and I downloaded them both.  The two specific ones that I looked at were Sebastien Lorien’s Fast CSV Reader and Andrew Rissing’s Generic Parser.  The first one I tried was the Fast CSV Reader since it had some nice looking performance metrics on the Code Project page.  Unfortunately, it blew up on the first file and I decided to give the other parser a try rather than trying to debug why Fast CSV Reader choked. 

I next tried the Generic Parser and it handled the file and even managed to return me just my specific data and skipped all the miscellaneous comments and headers in the CSV files using just the default settings.  On a couple of the CSV files, I made a few tweaks to the default settings of Generic Parser to get the exact data values I needed.  So far, it has performed like a champ.   

There are many CSV parsers out there that are part of larger libraries of utilities and such, but for a quick solution to CSV parsing, I would definitely recommend having a look at Andrew Rissing’s Generic Parser.  I’d love to hear other’s experiences and recommendations for CSV parsing libraries. 

Atlanta Code Camp Demos


Posted on 7th July 2011 by r2 in Presentations |Silverlight

Another fantastic Atlanta Code Camp!   Big kudos go out to the crew that threw this together this year in record time and did a fantastic job.  I heard nothing but positive comments from everyone that I talked with.  Big thank you to the sponsors, volunteers, organizers, speakers, and attendees!

I gave two presentations this year: Intro to MEF for Silverlight and Intro to Jounce MVVM Framework for Silverlight. Thanks to the folks that made it out to the talks and especially those of you that stuck with me for both of them.

Here are the links to the slides and code:

Intro to MEF for Silverlight

Intro to Jounce MVVM Framework for Silverlight

(Note that these are zip files with 7z files embedded so you will need to unzip and then “un-7z” them. The files were huge as straight zips and the server wouldn’t let them through as 7z files. 7-Zip is free and will work on both zip/7z files).