inverting a binary tree on a whiteboard

I kinda love this tweet from Max Howell, and many of the replies it generated. I’ve never interviewed with Google (and I doubt they’d be interested in me) but I have gone on interviews where I was asked this kind of question. A question I could have answered, straight out of college, but that I’d be pretty fuzzy on, 20+ years later.

Of course, I’ve never written anything as cool or popular as Homebrew, so I do expect to have to prove myself a bit more than Mr Howell should have to. Which is one of the reasons why I occasionally work on Project Euler problems, or take an Algorithms course on Coursera.

Fun and games with SharePoint and Open XML

I’m starting to work on a SharePoint project right now that sounds like it should be simple, but is actually kind of complicated. Or at least if seems to me like it is, possibly because I’m still new to SharePoint and I’m not always stumbling across the “right” way to solve the various problems I’m encountering.

The basic problem is to take a purchase requisition, stored as a normal SharePoint list item, and allow the user to save it to a nicely-formatted Word document or PDF, so that it can be sent out to a vendor as a purchase order.

I went through quite a few ideas for this, most of which are likely very wrong. What I’ve settled on, for now, is creating a new ASP.NET application page which will take the ID of the purchase requisition on the query string. I can then link to this page through a custom action on the regular list item display/edit form. The new page will read the fields of the list item via the SharePoint object model, substitute them into a Word document template, then allow the end-user to download that document from their browser.

Previously, I’ve always used third-party libraries, such as EPPlus, to generate Word and Excel files. But, in this case, I wanted to avoid third-party DLLs and see if I could do what I needed with just the Open XML SDK.

I’m discovering a lot of interesting things about Open XML as I go. First, there’s a tool in the Open XML SDK, called the “Productivity Tool”, that can take a Word document and generate the C# code necessary to create that Word document from scratch. When I started working on this project, I was concerned about where I would store the document template; now, it turns out that I don’t have to store it at all! I can just generate it from scratch in code each time. And I can just modify the generated code a bit so that the values I need to substitute in can be variables instead of constants.

The generated code, unfortunately, is pretty messy. My first shot at running my purchase order template through the tool resulted in 10,000 lines of code. I made some changes in the document to simplify things, and I got down to about 7500 lines, which is still a lot.

I also discovered the “Power Tools for Open XML” library, which can be used to simplify the formatting on a Word document a bit. I ran it on my template, then generated new C# code, and now I’m down to 7200 lines. Still a lot, but it’s manageable.

So it seems like I now have a viable solution that doesn’t need to read or write anything to/from the file system, doesn’t have any oddball DLL dependencies, and should be pretty straightforward to code, test, and deploy.

Microsoft Build

I kept an eye on the news coming out of Microsoft Build yesterday. There’s a good overview at The Next Web. At some point, I’d like to try out Code on my Mac. It’ll be interesting to see if it gets any traction, and how this affects Xamarin Studio. There are a lot of short articles out there on Code, but there’s not much substantial information in any of them. I just checked Scott Hanselman’s site, though, and he has a good post up about it. He makes it clear that this is more of an editor than a full IDE:

This a code-focused and code-optimized lightweight tool, not a complete IDE.

So it’s not exactly a direct competitor to Xamarin Studio. Maybe more of a competitor to Sublime Text? This makes me wonder, though, if they have bigger plans for Mac/Linux, or if this is just a weird little side project that will fade into oblivion a few years from now.

setting up a SharePoint 2010 development VM

I’ve blogged previously about my failed attempt to set up a SharePoint dev VM at home, on my laptop. I’ve given up on that for now.

But one of the SharePoint projects at work finally got far enough through the “spec” phase that I could justify asking our IT ops people to help me get a SharePoint dev VM set up at work. The regular help desk guys set up the base image (Windows Server 2008 R2), and the SharePoint admin guys then installed SharePoint 2010 on it, so I don’t have too much insight into that part of the setup.

Having been handed a working VM with SharePoint 2010 Server installed, it was then up to me to get Visual Studio up and running. That wasn’t much of a challenge. I installed VS 2012 Ultimate. The installer actually gives you the option to install the SharePoint tools, so I didn’t even have to do that separately.

I did have a bit of a problem, post-install, in that some Windows Update that came down automatically killed SharePoint. I had to re-run the SharePoint config wizard several times, make a couple of registry patches, restart some app pools in IIS manually, and so on and so forth. In the end, I’m not entirely sure which combination of random trickery was actually responsible for getting things running again, but whatever it was, I seem to have a working environment again.

But that pretty much killed the entire day, so I have to say that setting up a working SharePoint dev VM is not a trivial task, even if you’ve got experienced admin guys doing the bulk of the initial setup work.

Not at RailsConf

I’m spending a little bit of my spare time right now trying to learn Ruby, and Ruby on Rails. I recently finished a course in Web Application Architecture on Coursera, which used Rails as part of a general overview of modern web apps.

And now I’m working on Michael Hartl’s Rails Tutorial book. The book is free to read online. I’m enjoying it so far, and getting a lot out of it.

Meanwhile, RailsConf 2015 is going on right now, in Atlanta. I should keep an eye on that on Twitter, and see if anything interesting comes up that might be useful for a guy who’s new to Rails.

Text Editors

Possibly the most time-honored and effective way for a programmer to procrastinate on his or her work is to spend time messing around with text editors and/or IDEs. There’s a good case to be made that spending time selecting the right editor/IDE, and tweaking it appropriately, pays off in spades, due to increased productivity over time. But honestly, I can’t say that I haven’t sometimes spent time messing around with my text editor or IDE just as a procrastination tactic.

Yesterday, a new beta of Sublime Text 3 was released, along with the new version of Komodo Edit/IDE, so it makes sense to think about editors a bit.

I bought a personal copy of Komodo IDE about a year ago, and I’ve been using it on the Mac and on Windows, mostly for PHP programming. And now I’m using it for Ruby too. It’s a little heavy to use it as a general text editor. For quick text file editing, I’m using Notepad++ on Windows and TextMate on the Mac. But Komodo is pretty good for PHP and Ruby.

I messed around with Sublime Text a few years ago, but didn’t really like it enough to stick with it. (And, at the time, I didn’t really have a good use case for it anyway, given the kind of work I was doing then.) Occasionally, I think about giving it another try.

At work, I don’t really need to worry about text editors much, since nearly all of the work I do is being done in either MorphX (the Dynamics AX IDE) or Visual Studio. Both of those environments work fine, for their intended use, and (in both cases) it wouldn’t be realistic to consider using a different tool for text editing.

But, for my recreational programming, whether that be PHP, Ruby, or whatever else, it’s nice to have a good programmer’s editor handy. I’ve already shelled out the $59 to upgrade my personal license for Komodo IDE to version 9. (If I thought I was going to need to do any serious Ruby development, I’d probably give Sublime Text another shot and see if it was significantly better than Komodo.)

I keep thinking I should be a real programmer, and learn more about VIM and/or Emacs, but I never quite get around to it. VIM Adventures looks like it might be a fun way to learn VIM. (Of course, I’ve been saying that I should learn more about VIM and Emacs for years; I just found blog posts from 2008 and 2005 saying basically the same thing I just wrote here.)

more fun with Ruby

I’ve been making good progress through The Book of Ruby this week. I’ve continued to use the simple Ruby install on my ThinkPad, since it’s working fine, and I don’t yet need any of the fancy stuff; I’m still just working my way through language basics.

But I stumbled across an interesting class on Coursera that was just starting up, called Web Application Architectures, which covers Ruby on Rails. Initially, I resisted the urge to sign up for it, since I don’t think I’m really ready to start messing with Rails yet, but my curiosity got the best of me, and I went ahead and registered for it.

So now I’m messing with the somewhat arcane process of setting up Rails. Initially, I looked at trying to get Rails to work with my existing Ruby install on the ThinkPad, but (to make a long story short) that didn’t work out. So I looked at a couple of other options for installing a Rails dev environment on Windows, including RailsInstaller and RailsFTW, but I had some problems with both of them and decided to go a different way, rather than try to resolve the issues. (Finding pages like this and this on Reddit pretty much convinced me that setting up Rails on a Windows machine was a bad idea.)

So I went ahead and installed Ubuntu 14.04 under VirtualBox and followed the instructions found here to set up Rails. That seems to have gone smoothly, but I won’t really know for sure until I’ve done some meaningful work. I’m still not entirely sure if I’m going to stick with it, or punt on the course for now and avoid the messy complications of Rails until I have a better grounding in basic Ruby, but I’m going to spend some more time on it this weekend and see how it goes.

Oh, and as a side note, it’s fun to be messing with Linux again. I haven’t really touched Linux in a while. Ubuntu was fairly easy to set up under VirtualBox, and it seems to be running fine. The desktop UI is attractive and reasonably fast, even in a VM with only 1.5 GB of RAM allocated to it. (I’ll probably have to bump that up to 2 GB if I get serious about the Rails stuff.)

Learning Ruby

I’ve always been curious about Ruby, but never got around to learning it. I was inspired to actually dive in and start learning it recently, after listening to a Hanselminutes podcast where Scott Hanselman interviewed the creator of Ruby, Yukihiro Matsumoto, aka “Matz”. After messing around with SharePoint recently, I was in the mood to work on something as different as possible from that. Something where I could just install a nice little interpreter, and start working, without having to worry about spending a whole day setting up a VM first. Ruby sounded pretty good, on that front. The community seems to be pretty friendly, and there’s lot’s of good training material out there.

After looking around for a good place to start, I settled on The Book of Ruby. The publisher had a Pi Day sale this weekend, so I got the book/ebook combo for a good price. For a development environment, I’m using Komodo IDE. which I bought some time ago, for PHP work. It works OK for Ruby too, though I think there are probably better options. (But it’s good enough for now.) For Ruby itself, I installed it on my ThinkPad using the Ruby Installer for Windows, which was simple and straightforward. I also have Ruby installed on my Mac, apparently by default, since I don’t remember ever installing it myself. But I’ve decided to use the ThinkPad for my Ruby work for now, for a few reasons (bigger screen and keyboard, mostly).

I’m finding that The Book of Ruby is pretty well-written and organized, with good sample programs, at least so far, where the material is pretty basic. (I’m about 20% of the way through the book.) One slight annoyance though is that the sample code, as downloaded from the web site, is not formatted according to the usual Ruby standards. There are actual tab characters in the files rather than spaces, and the indentation isn’t always consistent. That might not seem like a big thing, but it bothers me a bit. So that set me off on a search to find a good code formatter for Ruby. Komodo doesn’t have one built in, but their web page on how to set up a new formatter links to a specific tool that looked like it work work well. Unfortunately, I found that it would always delete the last line of any code file I fed through it. This is probably due to some specific weirdness with the sample code from this book, and not a general problem, but regardless, I can’t really use that formatter. So that set me off on a search that led me to Rubocop, which is a static code analyzer that happens to also include a code formatter. That works great, though I haven’t tried to integrate it with Komodo yet.

TFS query PowerShell script

It’s been a while since I posted any PowerShell code here, so here’s a quickie script that I’m using to help with my workflow for checking in Dynamics AX changes.

First, a little background: We have a slightly odd workflow set up in TFS for tracking the projects we do in Dynamics AX. For each project, we open a TFS work item. We then check in all changes for that project under that work item. So far, so good. But we also routinely close out a work item after the first deployment that contains a check-in for that work item. So bug fixes and enhancements after the initial deployment are technically being checked in against a closed work item.

The problem here is that the check-in dialog within AX shows a list of open work items assigned to the current user, and doesn’t provide a mechanism for searching for other work items. It does allow you to manually add a work item to the list, but it can only do that by ID. But we have our own project number, which is stored as part of the work item title, and we generally don’t use the TFS work item ID for anything, so I generally don’t know it off the top of my head. So I often have to go into Team Explorer in Visual Studio to look up the work item ID for a project before I can check it in. That’s not a huge inconvenience, but I thought it would be nice to have a little PowerShell script that could look up the work item ID for me, given an AX project number.

The script shown below isn’t terribly complicated, but it shows off a few interesting little things. I started with an example script taken from Julian Kay’s blog.

First, we’re using the TFPT command-line query capability. This is part of TFS Power Tools, and uses a query syntax called WIQL.

Second, we’re doing a little rudimentary parsing of the data returned from TFPT to pull out the first work item ID. Then, we’re copying it to the clipboard with the clip command. (Looking at this script, I’m pretty such there’s a better way for me to pull out the work item ID, but the way I’m doing it now works fine.)

And finally, we’re displaying the results to the screen, so if by chance more than one result is returned, I can see the list and decide which work item is the right one.

If I wanted to go a few steps further with this, I could probably integrate this into AX completely. The check-in dialog in AX is a regular AX form named “SysVersionControlCheckIn”, and there’s no reason I couldn’t customize it. (But that’s a problem for another rainy day.)


# Given AX project #, return ID.
param (
[string]$projno = $( Read-Host "Enter project # (e.g. 123.4)" )
)
[string]$tfpt = "C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools\TFPT.EXE"
[string]$svr = "http://myTfsServer:8080/tfs/defaultcollection"
[string]$projname = "myProjName"
[string]$query = "SELECT [System.Id], [System.Title] FROM WorkItems " +
"WHERE [System.TeamProject] = '$projname' " +
"AND [System.Title] CONTAINS '$projno' " +
"ORDER BY [System.Id] asc"
$data = & $tfpt query /collection:$svr /wiql:$query /include:data
if ($data -ne $null) {
$line = ($data | select -first 1)
$taskid = $line.split("`t")[0]
$taskid | clip
}
$data
Write-Host "Press any key to continue …"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

view raw

tfpt_ex1.ps1

hosted with ❤ by GitHub

 

Beginning SharePoint 2013 development

Beginning SharePoint 2013 DevelopmentBeginning SharePoint 2013 Development by Steve Fox
My rating: 4 of 5 stars

I’m supposed to be getting involved in some SharePoint development at work soon. But I have no details on the specific project that I’ll be working on yet. So I’ve been doing some general background reading on SharePoint, in the hopes that some of it proves useful.

This book is structured so that each chapter gives you a quick introduction to one aspect of developing for SharePoint. A lot of stuff can be considered under the general heading of “SharePoint development”, and the book tries to cover as much as it can. I think it does a good job of covering the basics, and giving a new SharePoint developer a good overview of the various ways in which a developer can interact with SharePoint.

If, like me, you really have no idea where to start with SharePoint, this is a good book to pick up and read through. It covers enough of the basics that it should get you pointed in the right direction. But it’s not going to take you very far, once you’re actually off and running.

View all my reviews