Archive for November, 2008

github-repos – GitHub repo information in your webpages! 4

[UPDATE]: You an see github-repos working over there on the right in my sidebar! It took me about 2 minutes to set up in my blog. I’m happy with it’s flexibility so far.

After attempting to add Dr. Nic’s GitHubBadge javascript pluggin into my new forum, erlanguid.com, I decided to create my own version that will work with multiple possible elements in the page (as is necessary in a forum). It should be noted that I am by no means a javascript expert and I used Dr. Nic’s pluggin as reference for some of my code. Credit where credit is due: Thanks Dr. Nic!

Via some jQuery 1.2.6 (required) goodness and a little bit of elbow grease, I seem to have it working alright. You can view the single source file here, but I still need to write some unit tests for it.

The main purpose for me was making this info available anywhere in the page. In this case, I wanted to put the information under the user information in a post, but the next chunk of code I’m going to write will be making use of a custom bbcode tag for my forum, where it will insert just the div and the javascript will take care of it when the page loads. Basically all you have to do is get the div in there an make sure your css is to your taste.

But without further adieu, I’ll quickly walk you through the code and how to make use of it should you so desire!

^ I defined some constants so the classes and html template are easy to edit for your given situation.

^ I’ve defined two methods and one object array, as you can see, for my GitHubRepos object within the javascript.

^ GetRepos is the first method called by document ready jQuery method. It loops through all the divs that match the GITHUB_PROJECTS_CLASS constant, which is .github-projects by default. So in your page you need at least one of these to see anything! For each of those divs it checks to see if an id is defined. This id must be a string that matches the username of the repos’ owner, that you wish to display in said div.

^ I realize it seems a little but clunky to set the id value as the user name, but in practice it reduces the amount of javascript, so stick with me!

^ If the id has been set (not undefined), it will attempt to add the object to the GitHubRepos.displayObjects array element corresponding to the username, which is itself an array. What we end up with is the ability to access all the div elements in the DOM with the username that correspond to that user! Again that array of arrays may seem clunky but this little bit of frontloading will save us pain down the road.

^ Here we insert a new script resource into the pages head element so that it will call github and give us back a call to GitHubRepos.DisplayRepos with some JSON data as a parameter. Note that only one call is made per user since in the loop above we simple added the extra DOM objects to the displayObjects[username] array. The resulting script element that’s loaded into the page looks like this:

When this loads into the DOM it will retrieve code from GitHub with JSON data and execute GitHubRepos.DisplayRepos with that data. It looks like this (thanks GitHub!):

And that will of course call our next method:

As you can see the above is relatively painless, because we’ve already queried the DOM once and stored the results in the displayObjects array we don’t have to query it again we can simply act. By looping through all of the DOM objects that correspond to the user login that was passed in JSON data we can fill each of the with links and divs and other fun things from the REPO_TEMPLATE.

Make sure to look at the classes from the template and example page html so you can make the display look how you want. Here’s how I have it on my site:

Screenshot of the resulting page information.

And thats about it except for a format(str) helper function that let me insert the data into the templates in a clean fashion. You can view and fork the source code from repo at GitHub. If you see something wrong please post in the comments and let me know so that I can make it better. And give it a try!

PostSharp: filters for C# 0

Aspect oriented programming is a relatively new paradigm but it’s existence in the the .NET world was brand new to me when one of my clients/bosses Kris Kniaz stopped by my desk and told me about it. He pointed me at their site and at first it was a little vague what the software was trying to accomplish but about 2 minutes into reading it over I realized I was looking at C# filtering!

So what do I mean by c# filtering? In Rails, when you want to run a specific method before, after, around another method you use a filter. This makes for some very DRY code when you throw in the ability to white list and black list methods from the filters.

The obvious and oft-cited example in Rails is authentication:

For the destroy method in SomeController, before its executed, authenticate will run, which might makes sense! Note that the :only option can be replaced with :except option to black list or it can be left off all together.

So in the case of PostSharp you would end up with something like this:

Its not quite as DRY as The Rails Way, but its a pretty awesome tool to have in your kit!

Obviously this has some draw backs, in the same way it does with Rails. If your programmers aren’t smart they are going to overlooking a lot of possible code executing when they see those attributes. In general it can just lead to a lot of unintended branch logic, but good documentation/communication among your team, and using this powerful tool in the right scenario could result in some really clean solutions.

I encourage you to take a look at the PostSharp demo video, and comment if you’ve used it before!

ASP.NET on Rails 1

A friend at work alerted me to the new MVC framework that’s in beta for .NET and I was really excited to see what they had come up with. He showed me some code samples and I immediately recognized some very Rails-ish stuff in there. So lets take a look and see what they have going on because so far its looking pretty awesome.

Disclaimer: Obviously Rails isn’t the worlds first MVC implementation, its just a really nice one and I think MS has definitely taken a few cues here.

Directory Structure (courtesy of Scott Guthrie’s blog):

A logical directory structure for an MVC app to be sure. I would kill to have this on some of my current projects where locating things you are looking for is a nightmare. It may not be Rails’s “Convention Over Configuration” but its a nice step in the right direction from my perspective.

Routing:

Routes! Routes! I loves me some Routes! Making your web apps RESTful has many advantages (see here, and here for some examples) and in any case the flexibility that custom routes provides is enormous. Think of how much nicer SharePoint url’s could be :), and, as ScottGu mentions, it helps in optimizing SEO.

Backward Compatibility:

If you were a good little software architect/engineer and built decoupled user controls and master pages there’s no reason why you can’t re-use that code again on your new shiny MVC pages!

Plug and Play:

Again from Scott’s blog, “… it’s highly extensible and pluggable…”, which is music to my ears. One of the great things about Rails, and one of the reasons I really believe in it as a long term technology is that while it is opinionated software, you can swap out its main pieces like ActiveRecord < => Datamapper . This means that if you think Datamapper will serve your project better then you’re free to use it, and anyone with a better idea for an ORM can jump right in and write one. If ASP.NET MVC can live up to this not only will it be a better framework for it, but I wouldn’t be surprised to see a bunch of custom pieces from hackers who want something better or just different.

Looking forward:

If you are a web developer and you’re main expertise is with .NET then this is something to be very excited about. Not just as a tool for building websites but also because MS can recognize a better way to get things done for developer’s and they are willing to throw money at making our lives easier. Good stuff all around!

XMLViewer Silverlight Control 0

So instead of rolling happenings into a gem, I got bored and decided to hack together some Silverlight and see what it was like. I’ve often said that C# is awesome for development, but that ASP.NET is not the best. The event driven model makes me want to gouge my eyes out (Page_Load, After_Load, Post_Pre_After_Load), but that’s another blog post that I’ve been meaning to write.

Anyhow! I wanted to try Silverlight out because your basically building a GUI app, which .NET is great for, but deploying it with the browser. Cross Platform no less! So please try it out, post what you think, and I’ll get the code up on codeplex or something tomorrow if I can find the time.

XMLViewer Silverlight Control

[UPDATE] Source available at codeplex.

Gem or Plugin? 0

So I think that my event tracking system happenings is pretty nice. Nice enough that people might want to use it for their projects. The question that I’m trying to answer is: can I roll this in to a gem so I get all the package management niceness (Dependencies, etc) that goes along with gems, or do I need to create a plugin with generators and such?

From what I’ve read, views are the main sticking point. It _seems_ like I could just create my Controller and Model classes and force the user to inherit from them, but what about the Views? This sounds like a job for a generator, which I am loath to create, but laziness will be the death of this little piece of code.

Hopefully I can get off my duff and get this done. I’ll post back soon when I come to a decision.

Microsoft and Devs: marriage counseling needed 2

Since I started posting on this blog again I have been thinking a lot about Windows 7 and how MS could make it developer friendly. A lot of these ideas have come from discussions with colleagues (I work for a Microsoft consulting firm) and also from articles I’ve read that I agree with.

There are two or three main problems with how Microsoft treats its development community that I take issue with. I’ll decide whether its two or three as this post continues but the point is: Good developer’s want access to the best tools (ide & api), good developer’s make good applications (elegant inside and out), and good applications make a good platform.

1. Cost of entry

This probably doesn’t need much explanation, but I doesn’t have to be an all or nothing proposition. I don’t think many weekend devs will care about the Business Analysis tools for Visual Studio, but I think the MS development community would explode if they would release the full version of Visual Studio for free. Something simple like, “free developer tools for use with free software.” It would give college students, kids, and virtually anyone who wants to tinker with software a reason to look at the Windows platform. As it is right now, the cost is prohibitive at 250 for Standard Edition and 690 for Professional Edition.

Good devs are born from the desire to program for fun, but if you make it so the only people with access to your tools are people working at large corporations, its no longer fun its work.

2. API/Widget availability

Windows 7 is seeing the release of the “Ribbon” to developers. Currently you have to license it from Microsoft, which I didn’t even know was possible until I saw a quick presentation from Knowledge Lake at the NY Sharepoint User’s Group about how they had to do just that.

This also goes back to an article I read on Arstechnica where Peter Bright points out that the UI widgets aren’t released/standardized for the Windows platform. Not only does this mean we don’t get to use the ribbon but it also means that Windows turns into a hodgepodge.

I’m not quite sure what drives this mentality but I would like access to everything that I can get my hands on to make my apps as nice as possible. Microsoft can only benefit from awesome third party applications.

3. The community

I run a SharePoint Developer’s user group. The people who show up are really great, and I’ve had some awesome talks with guys like Paul Galvin, Michael Lotter, and Bob Fox about community development and software development.

But the feeling around these groups is just not as enthusiastic as I’ve seen elsewhere and I think its based on the simple fact that NONE of the people who show up hack in their spare time. They come for their professional betterment, not for fun, and it shows. The broader view of .NET is worse still. With the exception of the folks who work on the unadulterated awesomeness that is The Mono Project, there are very few in the community that can match the enthusiasm of the people that work on something like Rails/Gnome/KDE/etc.

This is a much tougher issue to address since a lot of the problem may stem from Microsoft’s image and where they spend their time/money. Lord knows they have plenty of the last to hold hackfests, competitions, and other community events geared toward bringing people together who are excited about the technology. It needs to be about developing for fun, instead of developing for your boss.


The great hope

If MS started to work some of these angles I think we could start to see the same vibrant open source development community around .NET apps that you see now with OS X and Cocoa. Oh, and give me a real command line too :D.

I welcome comments, and I hope that bit about the community wasn’t too harsh, but .NET is pretty awesome and everyone could benefit from a few small changes.

ym4r_gm patch submitted! 0

As promised I submitted my ym4r google maps rails plugin patch. That’s pretty much the first patch I’ve ever submitted for anything, so here’s hoping they don’t come back and lambast me for my ridiculously stupid idea.

If you look at the diff its around 5 lines but I thought it was a pretty nice little extra. I just added a :function option that lets you specify a function that you can call in javascript client side to actually render the map instead of the the default window.onload or automatic. Here’s what using the option looks like

and this renders as the following in the page

Meaning you can just call it whenever you would like.

I added this in because I was loading 5 – 10 map divs per page and they were display=none, so it didn’t make sense to send the call to Google for the map unless the user wanted to view the hidden map. Here’s hoping they except the patch!

Next Page »