Tuesday, May 18, 2010

Object initialisers and Collections

Starting with .NET 3, we've received some pretty cool new syntax in C#, things that made coding a bit more pleasant, and the code look somewhat more tidy. One of these additions was the object initialiser syntax!

Basically, what it allows you to do is initialise an object, and assign a bunch of properties to this object in a single statement, instead of 1 statement per each assignment. Apart from reducing the number of statements, and grouping all these assignments (which improves readability as well), this was also used in initialising anonymous class variables, and using simple single-statement lambdas, but that's not the point of this page :)

While this works great in most cases, there's one situation where I thought I didn't have a choice than to assign some values outside the initialiser, and this was readonly collections! Because the object initialiser is used to assign values to properties, I couldn't use it to create a new object with some values in a readonly collection property, because every time I tried - I got a exception.

new DataTable
{
    Columns = new[] { new DataColumn("FirstCol") }
}

What I didn't know at the time was that this was easily fixed by using another well-known addition in .NET 3 - the array / collection initialiser!

(Read more)

Friday, April 09, 2010

Tag Cloud Sphere Leak

This is a VERY early version of the cloud sphere implementation in the HTML5 <canvas> element.

It's NOT optimised, NOT cleaned up.. and doesn't react to mouse clicks yet, but it should all come in soon. For now I'm just displaying that it's possible, and it works :)

Apart from the fact that it works only in the browsers that support HTML5 (duh!), it may have it's own quirks in some browsers. For example in Firefox the letters have a strange cyan-ish outline, and don't move very smooth. I've managed to fix it in Chrome though by rotating the canvas very slightly, but it was enough to force Chrome to render them differently.

Wasn't tested a lot (and I don't have a mac to test it there), so any feedback, advice and other comments will be greatly appreciated :)

P.S. Oh yeah, this is not a public release yet, so I'm not listing all the sources, but I've been taking ideas and some formulas from places.. All references will be accounted for when it's released.. I PROMISE :P

(Read more)

Monday, April 05, 2010

First release: IIS Log Inspector module

I've been wondering for a long time now - why does IIS manager not have some kind of log inspector.. ANY kind, even one that would simply open up the log file in a text editor! They simply force us to use third party apps, or open up the log files manually.

Lucky for us, IIS 7 was improved in many ways, and one of the new features is support for custom pluggable modules for the IIS manager! So I decided to write a basic module that will allow me to get a quick peek at what's been going on with the website. I don't want to replace big specialised tools that generate graphs, and give us all kinds of statistics - instead, I decided to get something simple that will let me get a quick look at the latest activity.

As the default format of the log files in IIS7 is W3C - I decided to support just that (at least for the moment). If I need something more at any other point in time - I'll be able to extend it, and so will anyone else if they need it!

The last reason for this post - I'm announcing (as if it were a big thing for anyone else :P ) that other than a blog - this website will host project pages. Each project page will give the readers a quick overview of the project, screen shots, installations instructions and download links!

More info, including download links are available at the project page: IIS 7 Log Inspector Module

Upd: The link ago has not been working in feed readers and on the home page for some time. Luckily - it's fixed now :)

Thursday, April 01, 2010

IIS 7 FTP Extensions - The Guide

For a couple of years now the FTP server we used at my full-time job was FileZilla. It's a good server, open source, easily configurable, stable. But one of the main features we needed was to be able to dynamically add and remove FTP users, each locked up in their own folder, all grouped in a couple of main Categories. The users were generated by the main ASP.NET powered web app, and had to be able to use their ftp accounts immediately.

FileZilla stores these accounts in an xml file, so to add new accounts we had to open up the xml, add the new user, save the configuration file, and poll the ftp server to reload it's config file. While this approach worked, it was far from perfect. And apart from the fact that we were storing the credentials in two places (they were stored in the main DB already) the main problem surfaced when 2 users tried to create accounts at the same time generating a file lock.

I wanted to move to a different server that would store all the credentials in a SQL database (ideally within our own structure), and I've finally found what I was looking for - Microsoft has released FTP7 - an ftp server that runs on IIS 7 (Windows Vista and higher only, sorry Win2003 :) )

The best thing about it is that you can write custom extensions for it that will control the authentication process, the user roles, the home folder, and logging. It sounds simple and straightforward at first, but it's not as perfect as we'd like at first. After working on it for the better part of a day (slowly becoming a long night) I decided to write this semi-definitive guide to setting up custom authentication in FTP 7!

(Read more)

Wednesday, March 31, 2010

Public announcement: The Big Bang

Update:

I'm updating the DNS entries, so if you see this update - you're looking at the brand new thing ;)
I've temporarily emulated the old blogger links for the feeds as well (the emulated links return the Atom feed) but I still recommend updating them to the new ones: Atom and Rss

No, the world isn't going to collapse on itself and explode (or implode? or both?). I'm just finally ready to leave Blogger, and host the blog by myself.

This will include having my own hosted website that will do all the cool bits behind the curtains. Of course it's not all going to be perfect, and the biggest hit will be a new link structure. The new engine will still have a redirect rule for the blogger's page url's, so that I won't lose the Google search ratings (as low as they are, they're still good, right? :) ), but the feed urls are going to change, so you'll have to update them soon!

I know this is long overdue, and I've been kind of ready for it for awhile now, but just didn't have the time and circumstances to do it. Also, pretty much none of the current hosters are ready to host .NET 4 code, so it has been holding me back as well.

(Read more)

Friday, January 22, 2010

Current progress: Open Id

I haven't been posting any updates on the blog system / cms that I'm writing lately, and it's mainly because there wasn't much to write about. With work and a bucket full of IRL issues, I didn't really have a lot of time to work on it, but I am not letting it drop away!

One of the things that I really wanted, while planning it was the ability to use my site as an OpenId provider. This way I could use it to log in into other systems, and have my profile link back to my site automatically. Yay to more visits!

Luckily for me, I didn't have to write the implementation from scratch, as there are ready-made libraries available out there, and the one that looked best for me was DotNetOpenAuth. It supports OpenId, OAuth, ICards, and is just simple and easy to use.

It didn't take me a lot of time, to set it up, and now I've got my own OpenId provider that can actually provide some info about me (using Simple Registration or Attribute Exchange), one feature that a lot of other providers I used completely ignored :S

Blog comments

I guess some of you have noticed the change the comments area on my blog. And to answer your question (if you did wonder in the first place) - yes, it's not a new style or skin. The comments aren't even hosted by Blogger / Google anymore!

I do kind of hate the comment system on blogger. I mean - yeah, it kind of works. But any kind of notifications are disabled by default, and you have to always "follow" posts to know if someone posted a reply to you, and if you forget - you might never know someone did at all!

Worst of all, the comments don't support threading. I mean, come on.. Thousands of websites online have at least some kind of "reply to comment" support. Whether it's just prefixing the comment with the parent comment number, or having full-featured threading with indentation =/

So anyway - I moved the comments to Disqus, but only temporarily. While I'm working on my blog engine (which will have it's own comment system, btw), I don't want to have a big mess in here. Furthermore - I'm getting instant notifications, threading and a moderation panel as well, not mentioning the ability to export all comments, so that I can import them in my system when I'm done :)

And to everyone using blogger, I still suggest: if you're not satisfied with what you have here - move to an external comments system. Whether it's Disqus, Intense Debate, or anything else.

Monday, January 11, 2010

rTorrent is OUT, Transmission is IN

Ok, I guess I started celebrating WAY too soon after my previous post. While the whole setup did look extremely satisfying it had a couple of drawbacks.

For example, I really got used to uTorrent's .!ut file extension. This way my media center didn't pick up files that weren't finished yet. Unfortunately I didn't find a nice way to do the same in rTorrent, but it wasn't crucial, so I let it go. Then the interface was sometimes failing to connect to rTorrent, and I was forced to refresh the page time after time until I got it up. The configuration file was rewritten as soon as you did an update of the application, so I was forced to keep local copies of my configured version, and so on.

But these were all small issues, and I could live with them, because I didn't know better. Until the app started hanging. Badly. As in it would just stop responding to anything. I could see it in screen, but couldn't do anything. The web interface just became useless at this point, with no chance of connecting to the RPC interface. And when the router started hanging because of it in the in the middle of my work day - I just killed the process (it didn't want to die either btw -.- ) and left it as it was.

Later, after a bit of searching, I saw that I wasn't the only one with these problems, and a number of people have moved on to Transmission. Not everyone, though, because for others it was just too complicated and advanced. Nonetheless it was praised as a powerful client, and at the same time very resource "safe". With a low memory imprint (rTorrent took hundreds of MB ram! Thank god for the swap drive :D ), and very few dependencies (rTorrent pulled up about 5 more packages, Transmission just required 2) it seemed like an awesome solution, so I decided to give it a try.

After installing it, and failing to understand what to do out of the box, I went to their website for some docs. With a nicely structured wiki, it took me only a couple of minutes to get a settings file (stored in the user's home dir btw, YAY!), start the service and connect to the in-build web interface! Furthermore, there's a .NET remote app that I could install locally, and control almost all functions from a nice and familiar interface.

Half an hour later, I have a new torrent app running, with everything I want. Unfinished file names, nice remote control options, authentication and IP bindings, and a warm fuzzy feeling of accomplishment inside :)

rTorrent is here!

I've been playing around with my router for a long time, and it's been "upgraded" with a ton of cool new stuff already since I bought it. External antenna, open linux firmware, dedicated application storage and swap drive, external storage. With a USB hub plugged in I managed to even share an old printer across the network, and add a network-shared 1TB hard drive!

The next thing that I wanted to do was: torrents!

I have heard of people installing torrent apps on routers before, and with the storage attached directly to the router (and my laptop's HDD being completely filled up) I decided to give it a try.

I won't describe how I set it up, and configured it. There are tons of tutorials on how to do this on the net already, and I followed tips from the http://wl500g.info forums. The end solution that I have set up right now looks like this:

  • rTorrent installed and running off the router's dedicated external flash drive.
  • lighttpd + php set up and running, with the ruTorrent WebUI sitting on top.
  • The web UI is controlling rTorrent using XMLRPC.
  • Torrents are stored on a dedicated torrent ext3 partition on the external 1TB drive, and are shared on the network

I guess I spent about 5 hours setting it up (mainly because of my lack of knowledge in linux), but it was SO worth it!

Thursday, January 07, 2010

Extending LINQ selectors with custom expressions

While working with a particularly nasty linq query, I came up with a situation that I've been in a number of times already, since I started working with Linq 2 SQL, and I'm sure so have a lot of other people.

Basically, the query was using a filter that was based on multiple columns in a couple of different tables. This is of course easily done with linq, but what I wanted to do was to store this filter in a shared class, so that I can reuse it in multiple places. The problem is - if you try to use a method, an extension method or a custom property with this logic inside, linq will just throw an exception:

Method 'Boolean IsComplete(Linq.Product)' has no supported translation to SQL

I have tried to find workarounds on multiple occasions, and at some point I have found a solution that could be used in a filter: instead of using a method, or a property, I could use an Expression tree. It can be passed in a Where extension method, and it will be parsed by the Linq 2 SQL provider, and translated to SQL, if it's possible. E.g.:

public static Expression<Func<User, bool>> IsActive = u => u.IsActive && !u.IsDeleted;

This has worked fine until I needed something different: at some point I had to get this property in a selector, not a filter. Because the value had to be assigned to a property in a complex object, I couldn't just assign the expression to the Boolean field. Trying to .Compile() and .Invoke() the expression didn't help either, as I was greeted with more exceptions.

(Read more)

Monday, December 28, 2009

Coming soon: new engine

The main reason I've bought this domain was to build a website of my own, to be able to "promote" what I can do, and just have a good place to experiment, build, plan and learn.

Originally the idea was to have a simple site with a collection of various experiments, addons, code snippets, and have it backed up by this blog. After some pondering and looking around, I realised I wasn't satisfied with blogger at all. Also, I actually wanted to make something... bigger, I suppose

So my current plans are to build a simple (at first) CMS / blog system. It will replace this blog, once it's finished, and will provide me with a good foundation for whatever I'll have in mind. Also, I'll get a chance to build a project on my own terms, with me being able to make all the decisions as I see fit, not restricted by anyone else or any deadlines (except the ones I set for myself).

The plan so far is to use ASP.NET MVC, jQuery and MS SQL. I'm not sure about any time frames yet, as I don't want to rush it, but I know one thing for sure: I'm going to enjoy it :)

Tuesday, December 15, 2009

Updates

After a very long delay, I'm finally back here. Unfortunately I didn't have almost any free time on my hands, and this really did a thing on my schedule. With all the stuff happening IRL I completely forgot about this blog, or any updates that I wanted to write here.

So this time, I hope I'm back for real. I'm going to put more effort into it, and try to keep posting whenever I have something new to share.

I have finally purchased a domain, so the blog now has a shiny new url! I'll also try to get some kind of design for it as well, as I'm not that happy with the default one, but I don't promise anything outstanding. Sometimes I wish I were a designer, but I know I'm not going to switch for sure. Programming's just too good for me.

Tuesday, August 25, 2009

jQuery + TableSorter + QuickSearch = headache?

I know I haven't posted anything in a long while, but it's not because nothing happened or that I didn't have anything new to learn. It's just all in the lack of free time.

Anyway, lately I started using more and more jQuery in my development. And today the issue I stumbled upon is integrating the TableSorter and QuickSearch plugins in a page.

I found Bill Beckelman which explained how it should work, but when I tried to implement it locally, I realised that it's not actually working as expected. After a bit of debugging I realised that the quickSearch onAfter event is fired too early, and actually runs while the table is searched - not after that. Now that's a problem, because checking the number of results and striping wouldn't work well.

After a bit of online search, I didn't found any solution and ended up getting my hands dirty. Surprisingly, the fix wasn't hard at all (thanks to the small size of the js file!). To fix the issue all I had to do is find the qs() function, and move the options.onAfter(); call a couple of lines higher - inside the setTimeout call that actually does all the processing. Hey, that wasn't so hard!

The reason Bill Beckelman's demo works though, is that he uses an older version of the library, where the qs() method didn't use setTimeout.

 

Useful links:

Table Sorter library: http://tablesorter.com/docs/

Quick Search library: http://rikrikrik.com/jquery/quicksearch/

Monday, June 01, 2009

The adventures of system backup

As my parents' system was becoming more and more 'polluted' (read as filled up with junk, random data, more and more running processes and so on) it was running slower and slower, and at times it was a pain just doing something trivial.

Of course, they aren't really advanced in all the techy stuff (or, actually, really aren't advanced) it was up to me to dig up all the data, and throw out the rest..

As that's not my system, I can't be sure that there are no settings, files or any other small things that I can miss, I decided to make a full copy of the first partition, a separate 'actual data' backup, then reinstall the system and restore the data. If we find something missing, I'd restore the partition from the backup, grab the data, and copy it to the system.

I used Acronis True Image in the past, and I found it to be perfect for the task, but I didn't want to use it now for two reasons: 1) I didn't have a licence for it now and 2) for some strange reason I didn't want to use the trial, as it felt "dirty" leaving it on the system to "expire and die" :)

So I started looking for some free alternatives, and of course I have found a couple of solutions.

(Read more)

Monday, May 05, 2008

Validators in Custom Configuration Sections

Today I was extending/cleaning/rewriting my Exception Handling library to take advantage of the new .NET 3.5 features.. It proved to be quite fun, so I started making it more useful, and easy to use.

At some point I decided to change the way I stored all the settings in the configuration file. Before I had my own configuration section, that used the standard AppSettingsSection class. Simple and fast. But it didn't look clean. All the settings were mixed up together etc etc..

So I created a clean new sectionGroup with several sections, collections and so on. When I reached the notification e-mail field, I thought that having a validator would be... A lot better :)

Strangely enough, when I added the RegexStringValidator, the application crashed, telling me my e-mail was not valid againt the regular expression..

(Read more)

Pager: 1 2 >