Archive for posts tagged with 'code'
-
Using ClientDependency Filters to manipulate HTML
On a recent Umbraco project, I needed to be able to manipulate the HTML contents before it was sent to the browser. Typically, on Umbraco projects you'd do whatever you need do within Razor templating, but in my case, I had to do after the entire page markup was built. (I won't go into details, as the requirement is specific to my client project.) My initial thought for the solution was using a Request.Filter. I'd…
-
Elegant Objects by Yegor Bugayenko
At last month's Code Cabin, I was chatting with Steve Temple about Ditto and best coding practices, he suggested that I read Elegant Objects by Yegor Bugayenko, as it made him think totally differently about object-oriented programming. Looking around Yegor's blog, I liked his ideas, so I ordered the book ... I even noticed a small CSS bug on his blog and submitted a fix for it. I do love open-source! A day or so…
-
Code Syntax Highlighting in Wyam
I'd been going back and forth on how I should handle the syntax highlighting of my blog's code snippets. A popular choice would be to use a JavaScript library, (such as Prettify or Prism). I have nothing against those libraries, but in the pursuit of making my website fast and lightweight, I wanted a non-JavaScript option. My idea was to use a .NET library to convert my source-code snippets into colourised markup. The only library…
-
Bulk Photo Resizing with ImageProcessor
I'm currently on a month long holiday in Sri Lanka, taking a nice overdue break from work, (much respect to Rich for holding the Umbrella fort!). During my travels, I've been keeping a family blog - journal updates, add a few photos, etc. However the WiFi upload speeds at the various hotels we've been staying at have been painful slow; uploading a single photo (around 3Mb) to our blog or even Facebook is taking an…
-
How to use umbraco.library GetMedia in XSLT for Umbraco v4.5
This is a quick follow-up on my previous blog post: “How to use umbraco.library GetMedia in XSLT“. At the request of fellow Umbraco South-West UK developer, Dan, that I should update the code snippets for the new XML schema in Umbraco v4.5+ First a quick notice; if you are using v4.5.0, then please upgrade to v4.5.1, as there was a tiny bug in GetMedia that caused great confusion and headaches – you have been advised!…
-
Working with XSLT using new XML schema in Umbraco 4.1
Most of the Umbraco community are aware that the XML schema in the upcoming Umbraco 4.1 release has changed. Instead of each document being a node element, the element name is the node-type alias, same with property values; they no longer use data elements with alias attributes. Here is a quick example, comparing the old/legacy with the new: <node id="1066" parentID="-1" level="1" nodeName="Home" ... nodeTypeAlias="Homepage" path="-1,1066"> <data alias="bodyText"><![CDATA[<p>Welcome to my homepage.</p>]]></data> </node> <Homepage id="1066" parentID="-1" level="1"…
-
How to use umbraco.library GetMedia in XSLT
From time to time I notice a reoccurring post over at the Our Umbraco forum; how to display an image (from the Media section) in XSLT? A quick answer can be found on the Our Umbraco wiki for the umbraco.library GetMedia method. For most uses, the last example in the wiki works great. But I want to show you a “super safe” way of dealing with GetMedia in XSLT. Where I find a lot of…
-
How to convert NameValueCollection to a (Query) String [Revised]
Following on from a comment on my previous post about converting a NameValueCollection to a (query) string – I have finally got around to revising my code snippet. Now the method will handle same key multiple values, (it no longer comma-separates them). I have also added extra parameters so that you can define your own delimiter (since the HTTP specification says that you can use both ampersands & and semicolons ;) and there is an…
-
MySql data-source support for ELMAH
Following on from my last post (a couple of months ago) about Integrating ELMAH with Umbraco, I received a comment if it was possible for ELMAH to use MySQL as a back-end data-source. After a few emails back and forth between myself and Rajiv, (as well as Rajiv’s requests over at the ELMAH support group), the advice was to simpily develop some code that implemented the ErrorLog class, (making use of the 3 core methods:…
-
Using jQuery to swap form fields
Due to an technical decision early on in my project, the date-of-birth field on a profile edit page in a single text-input element. My client would now like the date-of-birth to be 3 dropdown lists, (day, month and year). The amount of work involved making changes to both the back and front ends would take at least a day. (It sounds a lot, but you know it would). Here’s where a front-end developer’s best friend…
-
Populating multiple DropDownList controls with generic ListItem array
I’ve just had some fun spending the last half-an-hour trying to figure out why when I used the SelectedValue property of a DropDownList, it also set the value of another DropDownList control. Here’s some background to the problem. On my web-form, I have 2 fieldsets, one for a "Start Date", the other for an "End Date". For each fieldset there are 3 DropDownList; Day, Month and Year. Now rather than populating the values declaratively, using…
-
How to best embed a WMV video clip?
I hate to admit it, but I’m stuck… I’m trying to figure out how to best embed a WMV video clip in a web-page, so that it works cross-browser (and cross-platform). Even after all my years of web-development, I’m still confused to which browser supports which tag … nested <embed> tags in <object> tags … it gets messy! I’m as equally confused with the Class ID attribute: “CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6” – surely that can’t be the same…
-
How to convert NameValueCollection to a (Query) String
Most ASP.NET developers know that you can get a key/value pair string from the Request.QueryString object (via the .ToString() method). However that functionality isn't the same for a generic NameValueCollection object (of which Request.QueryString is derived from). So how do you take a NameValueCollection object and get a nicely formatted key/value pair string? (i.e. "key1=value1&key2=value2") ... Here's a method I wrote a while ago: /// <summary> /// Constructs a QueryString (string). /// Consider this method…
-
Making Request.QueryString writable (by clone/copy)
Every now and then I completely forget that the Request.QueryString (and Request.Form) object is read-only. Today I had a bit of functionality where I needed to remove a key/value from the collection - but the Remove() method (of the NameValueCollection object) throws an exception. Unfortunately, the Request.QueryString's CopyTo method assigns the values to an ARRAY, not a NameValueCollection - losing functionality and flexibility. You need to copy the Request.QueryString object to a new NameValueCollection instance,…
-
Upgrade WordPress Shell Script
Now that I’ve found my new best friend (the sourcecode short-code), I want to put it to good use now. Here’s a quick Unix shell script that I use to upgrade my WordPress installations: #!/bin/sh # WordPress Update Script # Written by: Lee Kelleher # Released: 2008-04-23 # Email: lee # at # vertino # dot # net # Released under GPL echo "Downloading current version of WordPress..." wget http://wordpress.org/latest.tar.gz echo "Uncompressing WordPress archive..." tar…
-
Posting source code on WordPress.com
I feel like a complete n00b … I’ve only just found out how to mark-up source-code snippets on WordPress.com It’s in their FAQs: How do I post source code? Essentially you use the short-code: [sourcecode language='css']...[/sourcecode] Here’s an example: // A "Hello World!" program in C# class Hello { static void Main() { System.Console.WriteLine("Hello World!"); } } I knew about WP.org plugins that did this, but I’ve been scratching my head on how do this…
-
Converting CSV to XML
There’s a bit a functionality on one of the projects that I’m working on where I need to do a lookup. The data I’ve been given is in an Excel spreadsheet – which I needed to convert to XML (as ultimately the data will be stored in a CMS that handles XML better). I’ve done a lot of projects where I need to convert XML to Excel (via CSV), but not many where I need…
-
Greasemonkey Userscripts
I made a couple of Greasemonkey userscripts this afternoon… both related to Flickr’s machine-tags, one for IMDb and the other for Last.fm.
-
I am an ALT.NET Developer
I am an ALT.NET Developer. (more here)
-
WordPress Plugin Directory
Those great people over at WordPress.org have launched a Plugin Directory! It’s very snazzy! For information about my Category Cloud Widget, go here.
-
FizzBuzz Test
Jeff Atwood talks about using a FizzBuzz test for filtering out programmer applicants (who can’t code). It seems that some are over-thinking the solution!