Archive

Archive for the ‘web development’ Category

Open Source Wiki

September 10th, 2009

I was recently asked to create a knowledge base system at work… knowing that there were plenty mature open source projects that would work well, I opted not to write my own and instead chose one called MoinMoin.

To be honest I did not paticullary care what language it was written in (I can program in anything). My primary concerns were stability and simplicity. My decision in selecting MoinMoin was based primarily on the fact that the people who would be responsible for adding content did not have a solid grasp on basic web technologies, would have a difficult time learning HTML, and whom I did not trust to afford the luxury of a WYSIWYG editor.

MoinMoin allows new pages to be created simply by typing in the address you want, sub pages are created as subdirectories, and content is added in plain-text format using special identifiers which are later cast to html and styles (depending on which template you use). I felt that it included an adequate amount of embedded how-to documentation for them and that the syntax should be realitively easy for them to grasp in a short time.

I did have some issues with the install… but as usual, it was my fault and I soon had it running within its own application pool on IIS. I tested the system extensively for performance in cpu and memory overhead and it runs like a champ. Time will tell if the office actually uses it though 8-)

If you have any suggestions, questions, or experiences setting up your own Wiki I would be happy to hear from you so please comment.

For additonal help with wiki selection I recommend an article published by O’Reilly: Choosing a WIKI

web development

FREE CODE: Paging record list.

November 13th, 2008

When listing records from a database you will often need to break those records up into multiple pages, so that your users do not see hundreds of rows at once. What follows is a custom tag which does exactly that.

Parameters

  1. pageScale – (integer) Default 0. This will limit the number of pages returned depending on the current page. 0 means no scaling will occur.
    Example: pageScale=5, startRow=24, pageSize=8, records=64. Given these parameters this tag will return an array of 5 structures. The first page will start with 2 the last page will be 6. There are 8 total pages.
  2. startRow – (integer) Default 1. The first record of the current page.
  3. pageSize – (integer) Default 20. How many records to list per page.
  4. records – (integer) Default 0. How many records to page through.
  5. variable – (string) Default “pages”. The name of the array to create in the caller scope.

Source Code

Enjoy, it’s free. Until next time, dream in digital.

Free Stuff, web development ,

Using a Captcha with Cold Fusion 8

November 11th, 2008

Anyone who has spent time web surfing in the last few years has seen the popularity of Captchas rise to the point where it’s almost considered bad practice to not use one. The reality is in today’s world you need to protect your application from spam bots and brute force cracks. And fortunately for us Cold Fusion programmers, CF8 makes this incredibly easy with the edition of the cfimage tag.

Although relatively easy from a programmatic standpoint, when using cfimage for captchas you should take your intended audience into consideration in order to make the best decision on setting attribute values. Those you will need to take into consideration are width, height (overall image size), fontsize, and difficulty (how hard the text is to read).
Qusetions you might and should ask before proceeding:

  1. How old are my readers?
  2. How tech-savvy are my readers?
  3. Do my users have any visual disabilities?

I decided for my purposes that my average readers would be in their 20s, technicaly-savvy and unlikely to have any visual impairment. After playing around with the sizes for a while I finally settled on this:

Here is sample output at each difficulty level:

Low:

Medium:

High:

Once you are satisifed with your captchas look you need to do a bit of programming to make it useful. You will need to:

  1. Come up with a method for generating a random string
  2. Store the string for comparison after form submittal
  3. And lastly compare the value entered by the user to our captcha string to make sure it’s a match

[1. Come up with a method for generating a random string]

There are tons of ways you can do this… heck you probably have a method already lying around somewhere already. But incase you don’t, the key thing with random string generators is to chose random numbers from the ascii table and then use chr() to pull out the character. Since my captchas are inherently case sensitive (see part 2), I pull random numbers from 65,90 (A-Z).
*I could have technically used both upper and lowercase since my code converts the input to uppercase prior to doing the hash check anyway, however I felt using one or the other provided more uniformity, and ultimately uppercase letters were easier to read.

function randString(len){
	var i = 0;
	var str = "";

	var chr1 = "";

	for (i = 0; i < len; i++){
		chr1 = chr(randRange(65,90));

		str &=  chr1;
	}
	return str;
}

[2. Store the string for comparison after form submittal]

I chose to store mine within the form begin submitted using the Hash() function… although I could have easily stored this in the session or client scope if I wanted to. You can use any of these methods or come up with another, but consider following my lead b/c it is fundamentally simplier and doesn’t require an active memory store.
*Take note that hashing the string means the input is case sensitive.

<input name="rs" type="hidden" value="<cfoutput>#hash(rs)#</cfoutput>" />

[3. And lastly compare the value entered by the user to our captcha string to make sure it’s a match]

In this case we have to hash the input (form.captcha) and compare it to our stored value (form.rs):

<cfset rs = hash(ucase(form.captcha))> <!--- hash input --->

<cfif rs eq form.rs and len(trim(msg))> <!--- do comparison --->

For detailed information on cfimage, check out the livedocs entry from adobe.

Download the complete example.

web development