Archive

Posts Tagged ‘My Stuff’

Queue that only excepts N items

March 20th, 2012 No comments

I am trying to keep a list of the last 10 pages a user has been too. I tried to use Stack but it doesn’t support a fixed length so here is a dirty little class to only keep the last N items. Yes I know its a bit dirty!

public class NStack<T>
	{
		public int MaxEntries { get; set; }
		public List<T> Items = new List<T>();
		public void Add(T value)
		{
			if (Items.Count == MaxEntries)
			{
				//remove last item
				Items.RemoveAt(MaxEntries - 1);
			}
			Items.Insert(0, value);
		}
	}
Categories: c# Tags:

c# Coalesce function

November 16th, 2011 No comments

When you’ve been working heavily with c# for a few days, coalesce jumps into your head for a lot of c# issues. Heres a little helper to provide coalesce in .net

/// <summary>
/// Returns the first non null value, same as SQL's COALESCE()
/// </summary>
/// <param name="p">Args array</param>
/// <returns>First non null value</returns>
public static String Coalesce(params object[] p)
{
	foreach (Object o in p)
	{
		if (o != DBNull.Value && o != null)
		{
			return o.ToString();
		}
	}
	return "";
}
Categories: c# Tags: ,

jQuery – Syncing select options

November 4th, 2011 No comments

I had a requirement for a series of select boxes that required the related one to only allow selections above the first. I created a little utility function that enables and disables the options based on a function you supply.  Usage is pretty simple. Pass in the first and second select as jQuery objects, then pass in your function that evaluates whether an option is enabled or not.

Read more…

Categories: JQuery Tags: ,

UAD8: Query String Builder

March 13th, 2011 No comments

Ever had controls that need to add to the Query String but not duplicate or erase what’s already there? This is a little utility I dug out and just changed to use a generic dictionary recently. Just use it as you would a normal dictionary. When you instantiate a copy it picks up the current query string. There are two ToString() methods, one just return the query string and the other appends another string to the end and takes care of the ? & issues.

Read more…

Categories: Asp.Net, c# Tags: ,

jQuery equal height columns

May 12th, 2010 No comments

Sometimes equal height columns via css can be an absolute nightmare! If you’re using jQuery for other items on the page you can cheat with the following function :

function setEqualHeight(items) { 
var highest = 0; 
items.each( function(){ 
current = $(this).height(); 
if(current > highest){ 
highest = current; 
} 
}); 
items.height(highest); 
};

Read more…

Categories: JQuery Tags: ,

CMS Update – Preparing for BETA!

February 4th, 2010 2 comments

It’s been a bit quite round here recently! Don’t be fooled! The CMS is more or less finished. Just refactoring and preparing bits and bobs.

The actual core itself hasn’t really changed in 6 months and is independent from the CMS, it handles all the page, content and control creation with a single base class that you can implement to create page renderers for any page type. Current renderers are the LiveEdit renderer, Content Block, File Include and Rss (Mobile next).

Read more…

Categories: Asp.Net, cms Tags: