# chris barr

## Photo/Dev/Design

### A New Life in Georgia & a Wedding Website

Life Update
In less than a month now I’ll be getting married – it almost seems surreal.  I’ve been looking forward to this for a long time, mostly since I proposed to Kirstin about a year ago, but it’s so close I can hardly believe it.  I’ve lived in pensacola, Florida for the past 5+ years and Kirstin has lived Rome, Georgia for a little over 4 years now.  We had a long distance relationship for the entirety of our 2 years of dating, but in the past few weeks I’ve actually taken the plunge and moved up to Georgia.  We figured it was probably a good idea to at least live in the same state if we were going to be getting married.

It all actually worked out quite well.  The company I work for, AppRiver, recently opened an office in Midtown Atlanta.  The office is about 1.5 hours from where Kirstin works in Rome, so we decided to live somewhere in the middle and then we each commute to our workplaces.  The drives are fairly long, but  we think it’s worth it because we finally get to see each other on a regular basis and we both get to keep the jobs we love.

A Wedding Website!

Soon after we were engaged, the wedding planning began.  One task on the list was to get a wedding website.  I thought “I got this!” since I do something similar for a living, so I made one.  I might have gone a bit overboard with the site, but it covers 100% of our needs, we love it, and we’ve gotten nothing but compliments about it.  I’ve made it in a fairly modular way, so I hope that others might be able to make use of it as well.  I’ve decided to put all the code on GitHub because… well why not.

Check out the site: http://ChrisAndKirstin.com
Get the code: https://github.com/chrismbarr/Wedding-Website

### Lyric Converter V2!

If you just want to go use it: LyricConverter.com

But first…

### The Backstory…

A few years ago my church used some lyric presentation software called SongShowPlus, and it worked… but we didn’t love it.  It only ran on Windows, it had some UI issues that made it hard to use and add/change songs before services. We wanted to get a Mac and run ProPresenter instead.  Friends in the same industry were telling us how they had switched and how much they loved it.  ProPresenter had a lot going for it, especially in the ease-of-use department and scalability for things we wanted to do in the future.

We were hesitant to make the change because there was no way to move all of our song files over. Neither program had a decent way to import or export song files, and there was certainly no way to convert between formats. A good friend of mine at a different church told me they were in the same position; they wanted to move from SongShowPlus to ProPresenter but they were holding off due to the inability to convert their songs. Honestly  I’m still surprised that to this day neither program provides a standard import/export for other file types.

The day finally came when our Windows machine died. We either had to buy a new one, or just go ahead and get a Mac with ProPresenter. We chose the latter option and manually converted the few songs we needed each week, or just downloaded them from a service called SongSelect. In the end this process wasn’t the best, but we got through it.  However, everything would have been much easier and less intimidating if there was just a simple way to import and export songs.

### Version 1

This is the point when I decided to take a crack at it. I put our entire SongShowPlus library on my thumb drive and opened up the files in a text editor to see if it would be possible to get the text out.  The SongShowPlus file format is crazy, it appears to be a binary file with lots and lots of invisible control characters, but there is plain readable lyrics in there as well. Overall it seemed possible. Ok, so what about ProPresenter? Luckily the ProPresenter file format is a nicely formatted XML data, very easy to read and write from.  No problem!

At the time I was pretty comfortable programming in PHP, and I knew it’s file read/write capabilities so I decided to start there. I wrote a few complicated regular expressions to get the raw lyrics into an array, and it pretty much worked for most song files (with some tweaking)! This process took quite a while to get right because understanding the SongSHowPlus file format was fairly difficult. After that it wasn’t too much work to get it to generate the proper XML needed for a ProPresenter file. All that needed to be made now was a web UI for people to upload and download the songs! I put something together and I was pretty happy with it, and a few people used it. Yay! I even found out that the support staff at Renewed Vision (the company that makes ProPresenter) was actually recommending my site to customers making the switch, and that was pretty exciting news!

Oh and the name, LyricConverter… it just seemed obvious. (Also the domain was available.)

### Problems

While what I wrote worked, it was a bit of a pain to use. If someone tried to upload too many songs at once the website would choke due to PHP’s upload file-size limit. Sure I could increase that, but someone could always upload more.  To solve this I had to impose restrictions of no more than 30 files at a time. This solved the problem, but if you had several hundred files to convert you were going to be here all day.

Another big problem was downloading the converted files. Each file was converted individually and stored on my server, but that meant after conversion you had to click on each file to download it.  So again, if you had several hundred files you were going to be here all day. That combined with the upload limit of 30 made this quite a pain to use. My eventual goal was to be able to have it produce a single .zip file with all the converted files in it, but that seemed a daunting task for PHP at the time.

One more problem I had, that was compounded by the above problems, was the amount of disk space and bandwidth used up on my server each month! I wrote a cron job that should have run once a day and deleted any files left on the server that were more than 12 hours old, but I found out that this did not run reliably on schedule and I often had to trigger it manually after I would get a “disk space exceeded” email form my hosting company. I also kept having to increase my monthly bandwidth because I was getting “bandwidth limit exceeded” emails. It was not uncommon for the site to blow through 1 or 2 Gigs of bandwidth in a month… and that’s for text files! (Although, it was a few hundred of them all transferred up once and then again back down)

### Version 2

In my day job I’m a front-end web developer/designer, so I try to keep up with what the current browser technology supports and I’m quite honestly stunned at how many amazing things can be done all in the browser now.  Once I learned that there was a way to generate files in-browser with JavaScript to save to your desktop, I began to think about how re-writing LyricConverter could be a 100% in-browser process would solve all of the current problems I had.

Reading files dragged onto the browser was no problem, I was already doing that in the previous version.  Now I just had to take some of the regular expressions I had written in PHP and re-use or find a better way to achieve the same outcome in JavaScript. After some trial and error, I finally got this working how I wanted.  It will read SongShowPlus files and ProPresenter files, the output from either of those can be made to display in-browser as slides, convert to plain text files, or convert to ProPresenter files. Yes, you can convert ProPresenter files to ProPresenter files. Why? Well, why not. I doubt this is needed, but this does prove how flexible it is.

Since this is all in-browser there are no more “upload” limits, and there are no bandwidth restrictions. The only bandwidth used is just initially serving the page up to the browser. In fact since it’s all JavaScript now, it’s just being hosted on GitHub for free and none of my server resources are even needed any more.

Since files could be auto-downloaded (thanks to a library called FileSaver.js), that was great and it solved a huge problem of having to click individual links. A user could drag 1000 files into the browser, and then immediately click a button to download 1000 converted files… that is if you want 1000 files on your desktop… hmmm, that’s not appealing.  After some quick searching around I was amazed to find that someone has written a JavaScript library called jsZip that can actually generate .zip files with JavaScript! This was my ultimate goal, and it was to each to achieve with this library. Now when you convert songs you have the option to download all N number of files individually, or just download a .zip file containing them all.

I’m also extremely happy with how the code is structured now. Previously it was a huge mess and half of that was due to my unfamiliarity with PHP. Now it’s all written in JavaScript and it’s very modular. It should be easy to add on new file types that it could read from or output to.  It’s also all on GitHub, so anyone can feel free to improve the existing code or add new functionality like new input/output formats!

### Use It & Improve It!

Like I said, all the code is on GitHub and I would just absolutely love it if people would contribute to this project to make it better.  Right now it works, but it certainly could be made better.  Occasionally I do get some strange conversion errors or random incorrect characters that slip through into the converted files.  I’d love to squash these bugs, but they aren’t deal-breakers at the moment.

So, please use it, let me know how it could be made better, and please contribute if you can.

### CSS Pixels

Several weeks ago I made this presentation for work after doing a bit of research and becoming interested in how pixels on our screens are actually calculated.  It’s not at all what I expected at first, but find out for yourself and check out the presentation below.

View on SlideShare or Google Docs.

(Apologies for the audio not syncing up with the sides.  I’ve set it to do so, but SlideShare seems to refuse to work with me here)

### Console2 Integration With Visual Studio 2012

Do you need any kind of command line access for your Visual Studio projects? If so, that built in CMD in Windows works… but it could be a lot better.  In comes Console2 – all hail the power!  Go ahead and download it on SourceForge, although it hasn’t been updated since 2010.  If you’re new to Console2, I highly recommend first using Scott Hanselman’s recommended default setup for it. It looks much better and makes more sense after you do this.

#### Setting Up Console2

At work, we have several command line utilities that we need to run occasionally. Sometimes it’s a cleanup script, sometimes it starts a listening service for other projects we need to run.  After a while it got to be a real pain to always have to manually type in the commands and memorize the long file paths.  We soon found out that Console2 has support for custom tabs!

Here’s a screenshot of how this can look in the end.

To add these custom tabs, open the Console2 settings, and go to “Tabs”.  Add a new tab for each .bat script you want to run. Now, you just have to fill in two fields minimum like this:

Shell: %comspec% /k C:\path\to\your\folder\FILE.bat
Startup dir: C:\path\to\your\folder\

You can also do some other cool stuff like color code the backgound of each custom tab! That’s it, Console2 now has some helpful customized tabs.

#### Setting Up Visual Studio

Now in Visual Studio, you can add a button to launch Console2 to the current solution directory, sounds good right?

Go to the Tools > External Tools menu and add an entry for Console2. Point the Command to the executable for Console2, and make sure that Initial Directory is set to \$(SolutionDir).. to ensure that Visual Studio passes the argument to Console2 for it to initially start in the current solution directory.

Remember the order in which this entry appears! We will need to use this number later. In this case, let’s save it as the first tool, so it’s #1 in the list.

Now the tool exists, we just have to add a button for it.  Find a toolbar you want to add the button to, click the flyout menu and and select customize…

In the next window, press Add Command and then select the Tools category.  Depending on the order of the external tool we made earlier, select that external tool.  In this case it was the first item in the external tools list, so I will select the first external command.

Now it will appear in your toolbar as “External Tool 1” which you will probably want to rename to something that makes more sense.

Now when you click your newly added button, Console2 will be launched and it will automatically start at your current solution directory! Pretty handy.

### Easy Bundles for .NET MVC4

You’ve heard about bundles in .NET 4.5, right? If not you should read up on them, but the basics are that you can include multiple uncompressed JavaScript and CSS files in your project when in debug mode. When the project is deployed to production it will combine and minify the files for quicker downloads & fewer requests. Pretty handy!  At work we’ve recently begun using bundles in our MVC4 application.

The bundles are handy for the global files that need to be included everywhere, but nearly every page has it’s own specific CSS or JS files that needs to be linked to,  ideally minified as well, and possibly combined when there are multiples.

In razor, here’s the syntax we use to link to these files:

@Html.Style("~/Styles/someFile.css")
@Html.Script("~/Scripts/foo.js", "~/Scripts/bar.js")

Pretty easy right? Just link right the the file, or multiple files and they will be included on the page, but in production they will be minified and combined when multiples exist. How is this done you might ask? Well, take a look at this class below that gives us some extensions in the @Html. namespace.

That final MakeBundleName function will make the filename for the bundle (duh). Let’s say you provide it with the two script paths from the usage example above. The final output url for the bundle would be ~/Scripts/bundles/Scripts.foo+Scripts.bar – Basically it just replaces slashes with dots and concatenates multiple files with a plus. This allows for a unique name, but it also won’t change between page loads since it’s based on the input file names.

This all came about from a StackOverflow question I helped answer. There are a few caveats to this method that could be improved upon, the biggest of which is that this will automatically decide the bundle path for you.  This means that relative paths inside of your CSS/JS files will not work when the bundle URL is used!  For our use case, this is fine, but for what you do, it might not.  It would be fairly easy to extend this to have a different syntax like this if needed:

@Html.Script("~/bundles/my/custom/path", "~/Scripts/foo.js", "~/Scripts/bar.js")

Questions? Comments? Improvements? Let me know!