I haven’t updated either my iPhone or iPad to iOS 5 yet, but, as a programmer, I’m happy to see that they’re finally doing automatic reference counting in Objective-C. I’m wondering if the instructor for my NYU iOS class is going to work any iOS 5 stuff into the class or not. I could see where it would be hard to update class materials on the fly for this stuff, and our classroom iMacs probably still haven’t been updated to the latest version of XCode, but I’m hopeful.
Category: programming
accessing an IMAP account from .Net
I’ve been working lately on a couple of programs that need to access IMAP e-mail accounts. First, if you need to do this in .Net, MailSystem.NET is a good open source library. I’ve had a few problems with parts of it, but the basic functionality is solid.
Figuring out how to test and troubleshoot a program that’s reading messages and moving them around in an e-mail account can be a little tricky. First, it’s useful to know how to do IMAP stuff at a low level. This page has a great overview of how to access an IMAP account directly over telnet. And, if you want to copy the contents of one IMAP account to another, so you can have an account to test against, then imapsync is a very good thing.
One other random helpful hint: I’m working with both GMail and 1&1 IMAP accounts. I’ve found that there are some unexpected differences between them. For instance, GMail generally returns a message containing the word “Success” when a command is successful. 1&1 returns a completely different message, so you need to be careful about what you’re looking for in a response string.
Blogger shenanigans
Hmm, the bit of code I’ve been using to generate a tag cloud stopped working for a bit, then just started working again. Maybe it’s time to review that code and rewrite it. I know a lot more about JavaScript (and jQuery) now than I did when I took that code from someone’s blog, tweaked it a bit, and pasted it into my template.
Nice jQuery plugins
I’ve been working on a web page for the last couple of days that has to do a bunch of stuff client-side, so I’ve been relying more on JavaScript and jQuery, rather than the usual ASP.NET Web Forms stuff I’m used to.
Here’s a list of three relatively simple jQuery plugins that I’m using. I’ve found that, when looking for a way to do something in JavaScript/jQuery, there are usually several options. There are a lot of plugins out there. Some of them are well-written, cross-browser compatible, small, and quick. Others are a little buggy. These three appear to be in the former category.
Watermark plugin for jQuery — We usually use the Ajax Control Toolkit watermark extender. This seems to work just as well, with minimal effort.
jquery-color — I wanted to do some simple color animations on this page. Basically, I wanted to just briefly highlight a new entry with a color background, then have that background color fade out. This can be done with jQuery UI, but that’s a heavy bit of code to include, if you don’t really need it all. This plugin took a while to track down. The page for this at plugins.jquery.com just has a bunch of dead links on it. And searching for jquery color animation on Google mostly leads you astray. I found links to jquery-color on a couple of Stack Overflow questions.
simplepager — I’m displaying a list of comments on the page, and I needed to have a way to display them 10 at a time and page through them. This, again, is something that would be easy for me to do server-side with a ListView and DataPager, but I hadn’t really had to do it client-side before. There’s one site I worked on recently where the original author had implemented his own custom pager, but I didn’t want to use that code if I could avoid it. (Not that there was anything wrong with it, but it was well-integrated into that specific instance, and would have required work to generalize.) I had to make a minor change to this plugin, and I’m thinking that maybe I should submit it back to the author and see if he’ll merge it into the release version. I probably need to create an account on Github to do that, but that wouldn’t be a bad idea anyway.
truly annoying programming problems
I spent a few hours on Friday working on a problem that’s weird enough that I feel it warrants a blog entry. I made a few changes to one of our systems at work recently, and rolled them out Friday morning. This system is a VS 2008 solution with several projects in it. One of the projects is a bunch of web services, both SOAP and REST, that are deployed as a single DLL. I made a minor change to one of the REST services, but didn’t touch the SOAP services. And I made a minor change to a class in what is essentially a data access layer project that is referenced in the web service project, but nothing that should have affected the SOAP services. I’m saying all this to establish that I did not change anything that should have changed the SOAP services at all.
Returning to the data access project: this project was initially auto-generated through some CodeSmith templates, long before I started working for the company. The idea was that every class was implemented as a partial class broken into two files, with one file that contained auto-generated code, and one that could be used to add custom code. Now, some of these classes are used as output for the SOAP services. And those services just use the default XML serialization. (Some of you may see where this is heading.)
So we’re got a class called, let’s say, “Location,” broken into file X and file Y. File X contains properties A, B, and C, and file Y contains properties D, E, and F. Up until Friday, these properties had always been serialized from file X, then file Y, so they appeared in the output as A, B, C, D, E, and F. For some reason, on Friday, the compiler decided to process file Y before file X, and give me an XML document ordered as D, E, F, A, B, C. And, of course, the C# programs we have that actually call these web services don’t like getting their properties out of order. They expect everything to look exactly like the WSDL that was pulled in when they were last deployed. Oh, and most of them don’t have any useful error-handling or logging, and do a lot of their work in a declarative manner, through controls in the .aspx files rather than in code-behind, where I can see what’s going on step-by-step in the debugger. So figuring out what had gone wrong was interesting.
It had never really occurred to me, though I’m sure I read it at some point, that there is no guarantee as to the order in which the C# compiler will process the individual files that make up a partial class. (See this Stack Overflow question for reference.) I think the reason it changed now is that I moved the project from VSS to Mercurial recently, and that change probably caused enough of a disturbance to muck things up a bit.
I think if I had been the one that had implemented this thing in the first place, I would probably have done custom XML serialization, just because I’m a bit of a control freak, so I wouldn’t have ever had this problem.
Well, anyway, the moral of this story is that you shouldn’t assume that, just because a bit of code has been working for years, and you honestly haven’t touched it at all, that nothing can go wrong with it, and that the compiler will always output the same code given the same source code.
PHP Cookbook
I’m going to be doing some maintenance programming on a PHP/MySQL site pretty soon. I know a little PHP, probably enough to get by on this project, but I’d like to learn more. I have an old introductory PHP book around here somewhere, but I wanted to pick up something more substantial. So I picked up O’Reilly’s PHP Cookbook at Borders on my way home from work today. I have so many programming books that I’ve barely started reading, but this one looks like it’ll be a good reference.
TortoiseHg 2.1
I upgraded to TortoiseHg 2.1 yesterday.
This item, under the “improvements” list, is huge:
(file history) added context menu for file revision features
Thank you so much for implementing this! I’m using it every day now. Of course, I see that a bug fix release, 2.1.1, was made available this morning, so now I need to upgrade again. Well, the install is pretty painless, so that’s OK.
fun with Twitter and Facebook
I just finished working on a module to automatically post news stories from a client web site to Twitter and Facebook. I know that’s not a big deal, but it was kind of cool, and it took a bit of effort to get the Facebook thing figured out. (See this stackoverflow.com post for some detail on that.)
I used the Facebook C# SDK for the Facebook stuff, Twitterizer for the Twitter stuff, and EasyHttp to access the bit.ly API, for URL shortening. And of course I pulled them all into the project with NuGet. I feel like the master of all social media APIs now.
Unicode
Unicode in 33 minutes. Having just recently finished updating an older system to deal with Unicode, I find this highly entertaining.
Moving a VSS database to Mercurial
Here’s a document I wrote up for work yesterday. I think it may be generally useful for anyone else out there who is considering moving from Visual SourceSafe to Mercurial. This write-up is specific to an organization working in a Windows environment, using Visual Studio 2008 & 2010, and using bitbucket.org as a back-end for Hg. I also assume you’re using TortoiseHg and VisualHg.
- Insure all files are checked in to VSS.
- Get a new, full copy of the project from VSS.
- Make all files writable (uncheck read-only flag in Win Explorer).
- At both the solution and project levels, delete all *.SCC files.
- Edit the .SLN file to remove the “SourceCodeControl” section. It should begin with “GlobalSection(SourceCodeControl)” and end with “EndGlobalSection”.
- Edit each .CSPROJ file (one in each project folder) and remove all settings starting with “Scc”. There should be 4 — SccProjectName, SccLocalPath, SccAuxPath, and SccProvider.
- In the same folder as the solution file, in Windows Explorer, right-click, and select “Create Repository Here” from the TortoiseHg menu. Make sure “add special files” is checked.
- Edit the new “.hgignore” file and insert contents as per below. You may need to modify this file, depending on the project.
- Optional: create a README.TXT file in the solution folder, describing the project. This will automatically be displayed on the Bitbucket home screen for this repository.
- Right-click in Windows Explorer and select “Hg Commit” from the Tortoise menu.
- Review the list of files shown. If you see anything that shouldn’t be in source control, cancel out and modify the .hgignore file accordingly.
- Click the “All” button to select all files. Enter “Initial Hg Commit” as the comment. Click “Commit”.
- When that is done, exit from the commit dialog and review the project in Windows Explorer. Make sure that all files that should be in source control have a green check superimposed over their icon.
- Create a new repository in Bitbucket for the project:
- https://bitbucket.org
- Repositories, Create repository.
- Enter an appropriate name.
- Language should usually be set to C#.
- Make a note of the repository address.
- Back in the main solution folder, right-click and select “Synchronize” from the Tortoise menu.
- Set the remote repository to the address you noted above. Hit the ‘save’ icon, and give this alias a name.
- Hit the “push” button.
- When that is done, check the project page in Bitbucket to make sure the source is all there.
- As a sanity check, create a new temp folder on your hard drive, and pull a new copy of the repository into it.
- Select “clone” from the Tortoise menu.
- Enter the full path to the Bitbucket repo as the source (“https://bitbucket.org/…”) and leave the destination as-is.
- When the clone is done, open the project in Visual Studio.
- Go to Tools, Options, Source Control, and switch your plug-in to VisualHg.
- Take a quick look through the files in the solution, and see if any appear to be missing. (A missing file will have a yellow triangle icon overlay.)
- Do a full build of the solution.
- If possible, run a few tests to be sure it’s working. After the build, exit Visual Studio, and bring up the Hg Commit dialog at the root level. If you see any changed files to check in, they are probably temp files that should be excluded. If this is the case, please edit .hgignore accordingly.
- When done, simply delete your temp folder.
- You have now migrated a VSS database to a Hg repository.
Note that I am not retaining version history here, just starting fresh in Hg. If you want to move your version history over, please look at vss2hg.pl. I tried this out on one of my VSS databases, and it did work, after some tweaking, though it didn’t quite manage to get 100% of the data over, and it was a bit confused about dates. I decided that it wasn’t worth bothering with it, in my case.
References:
- stackoverflow.com — how to remove VSS bindings.
- visualstudiohacks.com — small program to automatically remove bindings.
- stackoverflow.com — sample .hgignore files for VS 2008
- stackoverflow.com — sample .hgignore files for VS 2010.