Search
Archives
- August 2015 (1)
- September 2014 (1)
- June 2014 (2)
- January 2014 (1)
- September 2012 (1)
- July 2012 (1)
- April 2012 (1)
- January 2012 (2)
- June 2011 (2)
- November 2010 (1)
- October 2010 (1)
- May 2010 (2)
- April 2010 (1)
- December 2009 (1)
- November 2009 (1)
- August 2009 (1)
- June 2009 (1)
- April 2009 (1)
- January 2009 (5)
- December 2008 (1)
- November 2008 (1)
- August 2008 (3)
- July 2008 (3)
- June 2008 (1)
- February 2008 (2)
- January 2008 (1)
- November 2007 (2)
- September 2007 (1)
- July 2007 (1)
- May 2007 (2)
Categories
Meta
Monthly Archives: January 2009
Lambda's and Anonymous functions in C# 3.5
Here’s a lambda function in use with the new extensions for a List object.
personnel.foreach(x => x.DoSomeCoolStuff());
360° Angle Class for C#
Here is a nifty class to handle an angle. it will wrap around increments and decrements that exceed 360 or 0, e.g. adding 20 to 350 will give 10 not 370 and subtracting 10 from 5 will give 355 not -5.
- Implicit conversion to and from double
- ToString and GetHashCode are mapped to the inner angle
- Operators +,-,>,>=,<,<= have been implemented.
- Mixing this class and doubles in statements works seemlessly.
Code sample:
Angle angle = 0; double angle2 = angle + 5; Console.WriteLine("a1:{0) a2:{1}",angle,angle2); //Output: a1:0 a2:5
Files
Making better use of mod_deflate
Output compression using Gzip and Deflate is a common feature of modern webservers. Webpages can be compressed by the server and then decompressed by the client seamlessly.
By default (at least on debian/ubuntu) Apache has a module installed and enabled called mod_deflate. While great, here is the default configuration:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
Now at a glance this is fine, But modern webpages consist of more than just html, we have CSS, Javascript, RSS and even JSON, all of which can benefit from compression but aren’t enabled by default.
Here’s a modified config file that will compress these files:
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/javascript text/css application/rss+xml application/json
This config is usually located at /etc/apache2/mods-enabled/deflate.conf
.
With this done jQuery (minified) goes down from 54KB to just 16KB of data send to the client :D
Multiple Onload Functions
Here’s a quick way not so good way (see update) of getting multiple javascript functions to be called when the page has finished loading.
Add this to the pages Head section:
And then where you need an onload event callback do this:
onload_functions.push(function() {alert('The page loaded...'););
Update:
As pointed out by phihag, this solution isn’t great, instead try using phihag’s code or use jquery and just $(document).ready(function{} {alert('The page loaded...');});
.
CSS Columns and the Box Model
One of the greatest frustrations for me when designing a website has been using css to layout a multi-column format (like this one).
I’ve found that it is important to understand the box model. more importantly knowing that when you set the width of a block element (ie div) it sets the width of the content. The padding, border and margin is wrapped arond it.