October Quickie: A Little Bit of Everything

Well yeah, it started snowing today here in Moscow, but this post is not about snow. I remember I’ve done some quickie before, but couldn’t find it. Perhaps it was something I mentioned inside the blog post with a different title. But anyways, this is a short roundup of what I’ve been up to lately.

Let’s start with Python.. After reading a very popular book called Programming Collective Intelligence by Toby Segaran (review coming later), I had no choice but to peek at how Python is doing. I didn’t carry out much of the excercizes in the book while reading it, but I did run a few experiments afterwards. Some of the code examples were translated into PHP to immediately implement into my Twibots project, the juice was left for later.

This weekend I decided to gather some data from the Twitter Streaming API for some experimental purposes, and I decided to do this in Python. Of course I hadn’t had much time to read good books (still waiting from Amazon), but the plenty online tutorials, guides and articles out there are quite okay. So with a little trial and error I managed to write a script which gathers a little over 10,000 tweets in 30 minutes and dumps them into a database. That’s 20,000 tweets an hour, ~ half a million tweets a day. What am I going to do with those? I’ll give you an insight on this project a little bit later ;)

Twitter. I finally got #newtwitter. I thought it was a joke. It’s not a secret that I have multiple Twitter accounts, but I use them for development purposes, and guess what, those accounts were switched to the new Twitter three weeks before my account was. So yeah, I’m a little mad at Twitter, but their new look really rocks. They also need some updates to their mobile version.

.NET MVC. Some of you might be wondering (or not) what happened to that .NET MVC project of mine. Well it’s 99% finished, but we’re constantly coming up with changes to the content part, switching images around and other dirty work. Latest comment from the client was – okay so I open up Safari, click View and check the Zoom Text Only option. Then I zoom in and the whole design breaks! You guys promised me nice-looking XHTML in Opera, Safari, Chrome, IE and Firefox, what the heck?

PHP. I wrote an app in PHP that allows me to turn off my PC from my iPhone. I extended it to include volume up/down features a few days later. These are the kind of apps you write when you’re lazy ;)

And finally some goodies from all around the web for web designers and developers:

That’s it for today. Cheers!

How To Deploy & Publish a .NET MVC Application

This is the second post in the series called .NET MVC From a PHP Developer’s Perspective where I discuss the pros and (mostly) cons of jumping onto the .NET bandwagon. Keep in mind that I’m a php/unix guy. I’m now at week 5 and I recently deployed my .NET MVC application to a web hosting provider. This was done for a testing and debugging purpose, since I had to become familiar with the whole process.

We begin with picking the right hosting plan for your .NET MVC application, then proceed to deploying your application and the contents (images, javascript, etc). Finally I show you a little trick on how to deploy your database in a format (.bak) most hosting providers will (hopefully) accept.

Picking the Right Hosting Plan

I picked Parking.ru – a Russian Windows hosting provider, which were generous enough to provide me with a two weeks trial period. My choice was based on a few calls to several different hosting providers, their technical teams had no clue about if my .NET Framework 4, MVC 2.0 application with an SQL Express database would run on their hosting plans. The answers were all similar to:

Well we’re not sure, you may try this hosting plan, but we’re not sure. And you still have to pay in order to use it. It’s running Windows Server, but we don’t know what MVC is, so we can’t guarantee you anything, sorry.

Heh, there was always a problem with Russian hosting providers, but overall the service is getting better. Tech teams now at least know whether they’re offering Apache or nginx ;) But anyways, I was quite happy to get a free trial at Parking.ru, and since they had no FAQs on how to publish my MVC application, I ran off to Google.

Publishing Your Application and Contents

It’s not really a big deal after you get it the first time. Visual Studio can automatically publish your application and the contents to a remote FTP server, which in my case worked like a charm. The only prob I had is with the external contents such as images, stylesheets and some javascript, which all sumed up to around 500 files. I didn’t add them as resources to my project, thus they were never published. Some common sense was required here, so I fired up my favorite FTP client and flushed them all manually.

Publishing Your SQL Express Database

The major issue was of course with the database. As I wrote in my previous article, the MVC Music Store is the tutorial my application was based on. The tutorial creates the models from a database scheme, and all the data is stored in an SQL Express file with the MDF extension. My hosting provider supported backups (.bak) which I could upload to their servers, so I googled around for ways to generate such backups.

Most articles I came across mention SQL Server Management Studio, so I installed that, and after a few trial and error, I managed to get my SQL Express database inside the Studio. Now what’s weird is that the backup option didn’t work, yielding something about incorrect filenames. Of course my database was called [C:UserskovsheninDocumentsVisual Studio 2010…], but SQL queries worked quite okay, so did an SQL export which generated an SQL dump of all my data. Unfortunately that was not good enough for my hosting provider.

With a few more experimenting and searching, I came across the following query, which could be issued within Visual Studio itself (does not require the SQL Server Management Studio). It generates a .bak file which is exactly what I was looking for:


Honestly, I have no idea what some of the options mean, but I’m sure Google can help. One thing you should pay attention to is the square brackets in the database name, especially if it contains the space character (which it will, if you saved your database in the Visual Studio directory by default). The command could not be parsed by Visual Studio, but the execution generates a .bak file on your hard drive. I instantly uploaded the file to my hosting provider, and voila!

I spent 3-4 hours in total on deploying my MVC application, but now that I got it right, takes me a couple of minutes. Then again, I really miss mysqldump, subversion and the rest. They seem to be a little more lightweight than .NET and IIS.

A 60-Day Trip from PHP to .NET MVC

This is quite an unusual post I guess, something that came in to my mind a few days ago. If you’re familiar with my biography you know I’m in love with php, unix and the open source world. The reason I’m writing this post (or maybe set of posts) is that I found quite a good client, who’s very strict about technology, so the very basic website that they’re looking for should be written in .NET in a little less than two months.

I haven’t finished the whole project yet, but I’d like to give you a short overview of .NET MVC from a PHP developer’s perspective, as well as share some coding thoughts in general. Don’t treat me as a Microsoft hater though, I love what they’re doing, and there are a bunch of very rich web applications driven by Microsoft’s technology! But since I’m used to what I’m used to, I feel a little bit weird and disappointed.

Why did I pick MVC? Well, perhaps because it’s quite new compared to the rest, and a bit of a challange since I don’t have any friends familiar with this monster. So the only places to find help are Google and Stackoverflow. MSDN is pretty much useless, especially the localized versions.

There are several reasons why I called .NET MVC a monster, and here’s a short list based on the first few weeks of my experience:

  • Too many abstractions (week 1)
  • No SQL code at all (week 2)
  • Models are built using drag ‘n drop (week 3)
  • Name conventions are silly (week 3)
  • Confusing (week 4)

Getting used to LINQ

I started my trip by exploring the MVC Music Store Tutorial on the ASP website, which gives quite a clear overview of how to setup a basic website structure, handle some user input and work with the database using LINQ. Wow, I never thought SQL was so complicated that they had to reinvent it. I’ve seen some abstractions over SQL (PDO, Zend_Db) but LINQ is something different:

var shop = (from s in db.Shops where s.Slug == id select s).First();
var workingHours = (from m in shop.ShopMetas where m.Key == "working-hours" select m.Value).ToList();
var comments = (from c in db.Comments orderby c.PublishDate descending select c).Skip(page * 5).Take(5).ToList();

Third line shows my implementation of pagination on a page full of comments. Groups and joins are even more “fun”. I came across a handy resource for studying LINQ called Hooked on LINQ with an awesome section called 5 minute overviews.

But anyways, quoted from Wikipedia: Some benchmark on simple use cases tend to show that LINQ to Objects performance has a large overhead compared to normal operation.

Haven’t tested, haven’t benchmarked, maybe it’s different. But from what I’ve seen, same old SQL is under the hood. Now, a few words about models.

Building Models and Relations

We all know MVC doesn’t go around without models, yet, I never thought models could be designed using only your mouse! I was quite surprised when I saw the models being generated from a database schema in the Music Store tutorial, yet, that’s not as deep as it goes. More interesting is inheritence, mapping, foreign keys and relations, all this using only your mouse! I felt kinda dumb, really. For a second I thought this was programming for kids, but hey, it really makes life simpler! Kudos to Microsoft ;)

Visual Studio Data Model

Worth mentioning is that there’s a flag called Singularize model names when building models from a database schema, which converts the Shops table to a Shop model, a Comments table to a Comment model, (quite cool this one) a News table to a News model, and a (surprise) Movies table to a Movy model.. Whaa? ;)

Next is something that took me quite some time to sort out, so to save you that time, I’ll give you a quick tip.

The Master View

Master views are cool, but according to Google, one of the most frequently asked questions by .NET MVC newbies is “how on earth do I pass data into my master view”? Yup, I asked that question too, but didn’t get too much responses. So here’s a newbie response (how I see it): Master views are very similar to normal news, so they need data passed by a controller. You can go ahead and pass the same data for the master view with each and every controller that you create, but it would be difficult to manage, you need something more centralized.

So the answer would be to create an abstract class (OOP, remember?) which would derive from the standard Controller class, then change your controllers to derive from your newly created class. Easy as that:

public abstract class ApplicationController : Controller
    public ApplicationController()
        // This is how you pass some data to your master view
        ViewData["my-key"] = "my value";

Then make sure you derive your controllers from the new ApplicationController. Here’s my Home controller:

public class HomeController : ApplicationController
    public ActionResult Index()
        return View(viewModel);

Note that I dropped the namespace for both code pieces of code to make them shorter. The namespace used is MyApplication.Controllers. Let’s switch over to the actual Master view and here’s how you capture the data:


That wasn’t very difficult, was it? You can pass all the data/objects you want in ViewData as well as run LINQ queries inside the Application Controller for your sidebar widgets, menus and other stuff that comes from the database.

Well folks! That’s about it. I’ll keep you posted on my experience in .NET MVC but honestly, I’m getting tired of it already, can’t wait to ride home and get my hands back onto php ;) Thanks for reading and sharing!

Trends: WordPress vs Drupal vs Joomla

The battle’s been going on since 2004-2005, the three open platforms (WordPress, Drupal and Joomla) have been competing for ages. Which is the most popular? Of course you could search for reviews, votes, researches. I even came across a commercial research document about content management systems, their pros, cons and popularity. It still is difficult to convince clients (especially the bigger ones) to use open platforms for their websites. Tonnes of questions are asked about security, performance, etc.

This article will not review any of the platforms mentioned above, nor will it give pros and cons to certain properties of such platforms. We’ve seen enough reviews, tests, benchmarks and even competitions to figure out which the best platform is. In my opinion, there’s no best platform, each is good, and which ever to use is a decision the developer should make.

Anyways, I had my coffee this morning and decided to check out what Google is up to, so I browsed to the Labs. The list is quite big but suddenly I spotted Google Trends, which has been around since 2006. Haven’t used that for a while ;) Sticking in “wordpress, drupal, joomla” into the trend search, I came up with the following results:

Trends: WordPress vs Drupal vs Joomla

Quite interesting isn’t it? Joomla (orange) was in a leading position from 2006 to late 2008, and in late 2009 WordPress (blue) took the lead. Drupal (red) heh, wha? There’s also a ranks by regions, cities and languages which give even more interesting results. For instance, Joomla still leads in Russian, Italian and German languages, and Drupal is very popular in India.

These stats are good when comparing the open platforms, they also show that open platforms are growing overall. But does this convince our clients to pick an open source platform for their website? I recall or three latest clients who calimed that they’d love .NET websites and an ASP (seriously) website. Let’s see:

WordPress vs .NET vs ASP

So Microsoft’s technologies are not as popular as they were in 2004, at least based on Google searches. There’s much more fun stuff you can do with Google Trends, but the question remains. Is this information useful when speaking with clients? Does the global trend mean that pictures in regions will change over time? And why is .NET losing popularity? Just thinking out loud ;) Cheers, and don’t forget to tweet this post if you like it.