OffBeatMammal

Searching for monkeys in Cyberspace

Comment Spam - why do they bother?

clock October 31, 2006 23:54 by author OffBeatMammal

I had to give up on my previous blog solution because the comment spam was getting out of control and it was hard to manage. That led me to Community Server which has a better approach to spam control.

That now means that with the basic out-of-the-box facilities and a couple of excellent add-ons [6 rules and Akismet] I've not had a single spam comment get published, and almost no collateral damage.

But, even though the spam comments are not getting published they keep on coming. Today alone I've had to make about 80 entries for one site go away. What's even stupider is that the site isn't currently promoting viagra, breast enlargements or unlimited free porn.... it's spruiking badly worded investment tips in (in some cases) companies who don't even match the claimed stock ticker!

Makes me wonder why they bother! They're getting no benefit from their efforts and I could certainly do without the time wasting while I hit delete on their quarantined rubbish.

They keep trying to fill my mailbox up as well. Luckily a combination of SpamCop.net and Outlooks junk filters means that it's very rare that I actually see anything that's too time wasting. And I feel good because I report almost every one of the spam emails I get via SpamCop. For good measure I also install the Project Honeypot spambot catcher on pretty much any site I work on.

Currently listening to: Driftkikker What



MaxLength on a Textarea

clock October 26, 2006 11:14 by author offbeatmammal

Although HTML is very clever (and there are lots of very clever things hidden if you go looking) there's one thing that's bugged me since I first started putting forms together in a webpage.

Why is there a maxlenth parameter on an <input type="text"....> field but no maxlength attribute on a <textarea....>....</textarea>

Now I know it's possible to write some javascript and attach it to a text area that you want and control user input that way. But it requires thought and effort and it's not a very elegant solution.

But, as you can see... the problem can be solved:

I came across the concept of CSS behaviours (or is that behaviors) thanks to a really handy script 'behaviours.js' from Ben Nolan which allows you to assign a behaviour to a CSS rule. I then applied that to allow me to add a couple of extra attributes to the Textarea HTML tag. Specifically the Maxlength and showremain function. Adding them to a page is as easy as this (the hardest bit it to remember to include the two scripts!)

<html> <head> <script type="text/javascript" src="/scripts/behaviour.js"></script> <script type="text/javascript" src="/scripts/textarea_maxlen.js"></script> </head> <body> <p>Limit 120 Characters: <TEXTAREA rows="5" cols="30" maxlength="120" showremain="limitOne"></TEXTAREA> <br>Chars Remaining:<span id="limitOne">--</span></p> <p>Limit 50 Characters: <TEXTAREA rows="2" cols="30" maxlength="50" showremain="limitTwo"></TEXTAREA> <br>Chars Remaining:<span id="limitTwo">--</span></p> </body> </html>

 The logic to check the length of the selected object, enforce it and (if required) update the span showing the remaining characters is within the textarea_maxlen script. It registers functions against the onkeydown, onkeyup, onpaste and onblur methods for the CSS textarea attribute.

var CSSrules = { 'textarea' : function(element){ element.onkeydown = function(event){ return doKeyPress(element,event); } , element.onpaste = function(){ return doPaste(element); } , element.onkeyup = function(){ return doKeyUp(element); } , element.onblur = function(){ return doKeyUp(element); } } } Behaviour.register(CSSrules);

the actual javascript to check and enforce the length and update the progress is all pretty standard stuff - in fact, it's probably not that elegant but it was more a case of getting it working in a hurry and having it work in IE (PC), FireFox (PC, OSX and Ubuntu) and Safari (OSX) - the test platforms for the project (if you can tidy it up, please leave a comment here!) The biggest problem I encountered was the different event handling models for IE and Gecko based browsers - both in when events were triggered and how to stop them bubbling further!

var detect = navigator.userAgent.toLowerCase(); // Keep user from entering more than maxLength characters function doKeyPress(obj,evt){ maxLength = obj.getAttribute("maxlength"); var e = window.event ? event.keyCode : evt.which; if ( (e == 32) || (e == 13) || (e > 47)) { //IE if(maxLength && (obj.value.length > maxLength-1)) { if (window.event) { window.event.returnValue = null; } else { evt.cancelDefault; return false; } } } } function doKeyUp(obj){ maxLength = obj.getAttribute("maxlength"); if(maxLength && obj.value.length > maxLength){ obj.value = obj.value.substr(0,maxLength); } sr = obj.getAttribute("showremain"); if (sr) { document.getElementById(sr).innerText = maxLength-obj.value.length; } } // Cancel default behavior and create a new paste routine function doPaste(obj){ maxLength = obj.getAttribute("maxlength"); if(maxLength){ if ((window.event) && (detect.indexOf("safari") + 1 == 0)) { //IE var oTR = obj.document.selection.createRange(); var iInsertLength = maxLength - obj.value.length + oTR.text.length; try { var sData = window.clipboardData.getData("Text").substr(0,iInsertLength); oTR.text = sData; } catch (err) { } if (window.event) { //IE window.event.returnValue = null; } else { //not IE obj.value = obj.value.substr(0,maxLength); return false; } } } }

In order for this to work in your own page remember: you must go and download the behaviour.js file from Bens site, and the textarea_maxlen.js script from here.

With a bit more imagination and time you could extend this to enforce rules like MaxLength="500" MaxWords="150" to lock down how much data can be entered, or MaxCaps="15%" to stop them SHOUTING.

The maxlength attribute is part of a proposed HTML5 standard, but it'll be interesting to see if we ever get there with the directions devolving to XHTML and microformats an rich internet application technologies such as WPF/E.



MaxLength on a Textarea

clock October 26, 2006 11:14 by author OffBeatMammal

Although HTML is very clever (and there are lots of very clever things hidden if you go looking) there's one thing that's bugged me since I first started putting forms together in a webpage.

Why is there a maxlenth parameter on an <input type="text"....> field but no maxlength attribute on a <textarea....>....</textarea>

Now I know it's possible to write some javascript and attach it to a text area that you want and control user input that way. But it requires thought and effort and it's not a very elegant solution.

But, as you can see... the problem can be solved:

I came across the concept of CSS behaviours (or is that behaviors) thanks to a really handy script 'behaviours.js' from Ben Nolan which allows you to assign a behaviour to a CSS rule. I then applied that to allow me to add a couple of extra attributes to the Textarea HTML tag. Specifically the Maxlength and showremain function. Adding them to a page is as easy as this (the hardest bit it to remember to include the two scripts!)

<html><head><script type="text/javascript" src="/scripts/behaviour.js"></script><script type="text/javascript" src="/scripts/textarea_maxlen.js"></script></head><body><p>Limit 120 Characters: <TEXTAREA rows="5" cols="30" maxlength="120" showremain="limitOne"></TEXTAREA> <br>Chars Remaining:<span id="limitOne">--</span></p><p>Limit 50 Characters: <TEXTAREA rows="2" cols="30" maxlength="50" showremain="limitTwo"></TEXTAREA> <br>Chars Remaining:<span id="limitTwo">--</span></p></body></html>

 The logic to check the length of the selected object, enforce it and (if required) update the span showing the remaining characters is within the textarea_maxlen script. It registers functions against the onkeydown, onkeyup, onpaste and onblur methods for the CSS textarea attribute.

var CSSrules = {
'textarea' : function(element){
element.onkeydown = function(event){
return doKeyPress(element,event);
}
,
element.onpaste = function(){
return doPaste(element);
}
,
element.onkeyup = function(){
return doKeyUp(element);
}
,
element.onblur = function(){
return doKeyUp(element);
}
}
}
 
Behaviour.register(CSSrules);

the actual javascript to check and enforce the length and update the progress is all pretty standard stuff - in fact, it's probably not that elegant but it was more a case of getting it working in a hurry and having it work in IE (PC), FireFox (PC, OSX and Ubuntu) and Safari (OSX) - the test platforms for the project (if you can tidy it up, please leave a comment here!) The biggest problem I encountered was the different event handling models for IE and Gecko based browsers - both in when events were triggered and how to stop them bubbling further!

var detect = navigator.userAgent.toLowerCase();// Keep user from entering more than maxLength characters
function doKeyPress(obj,evt){
maxLength = obj.getAttribute("maxlength");
var e = window.event ? event.keyCode : evt.which;
if ( (e == 32) || (e == 13) || (e > 47)) { //IE
if (maxLength && (obj.value.length > maxLength-1)) {
if (window.event) {
window.event.returnValue = null;
} else {
evt.cancelDefault;
return false;
}
}
}
}
function doKeyUp(obj){
maxLength = obj.getAttribute("maxlength");
if (maxLength && obj.value.length > maxLength){
obj.value = obj.value.substr(0,maxLength);
}
sr = obj.getAttribute("showremain");
if (sr) {
document.getElementById(sr).innerHTML = maxLength-obj.value.length;
}
}
// Cancel default behavior and create a new paste routine
function doPaste(obj){maxLength = obj.getAttribute("maxlength");
if (maxLength){
if ((window.event) && (detect.indexOf("safari") + 1 == 0)) { //IE
var oTR = obj.document.selection.createRange();
var iInsertLength = maxLength - obj.value.length + oTR.text.length;
try {
var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
oTR.text = sData;
}
catch (err) {
}
if (window.event) { //IE
window.event.returnValue = null;
} else {
//not IE
obj.value = obj.value.substr(0,maxLength);
return false;
}
}
}
}

In order for this to work in your own page remember: you must go and download the behaviour.js file from Bens site, and the textarea_maxlen.js script from here.

With a bit more imagination and time you could extend this to enforce rules like MaxLength="500" MaxWords="150" to lock down how much data can be entered, or MaxCaps="15%" to stop them SHOUTING.

The maxlength attribute is part of a proposed HTML5 standard, but it'll be interesting to see if we ever get there with the directions devolving to XHTML and microformats an rich internet application technologies such as Silverlight.



Implementing a Sleep function for VB.NET

clock October 26, 2006 04:50 by author OffBeatMammal

I encountered an interesting problem today. A function that needed to be run on a webserver (as an aspx page) but it did a huge amount of processing based on the users input - lots of file reads and database updates. It was dragging performance on the rest of the site down while it ran.

In a normal scripting environment for a Windows application it's easy - the sleep({seconds to sleep}) command is your friend. But you can't do it in VB.NET for a webpage.

Unless, that is, you have SQL Server 2005 or another database that supports the WAITFOR DELAY {time to delay} command. 

Sub sleep(sec as integer) Dim con_timeout, sql ' indicate a number of seconds, up to 59 ' if you need more than 59 seconds, you will need to adjust the SQL below If sec > 59 then sec = 10 End if ' make sure timeout doesn't expire! ' assumes we have an already active connection to the database called "con" con_timeout = con.commandTimeout con.commandTimeout = sec + 5 sql = "WAITFOR DELAY '00:00:" & right("00" & cstr(sec),2) & "'" con.Execute(sql,,129) ' put the timeout back con.commandTimeout = con_timeout End Sub

Now the script may take a fair bit longer to operate, but the judicious use of sleep(2) within the more tightly looping and time consuming bits of code means that the server can spare some cycles to answering other demands on it.

Of course, you then need to make sure that your script doesn't timeout, so careful use of Server.ScriptTimeout to balance it is also called for



Implementing a Sleep function for VB.NET

clock October 26, 2006 04:50 by author offbeatmammal

I encountered an interesting problem today. A function that needed to be run on a webserver (as an aspx page) but it did a huge amount of processing based on the users input - lots of file reads and database updates. It was dragging performance on the rest of the site down while it ran.

In a normal scripting environment for a Windows application it's easy - the sleep({seconds to sleep}) command is your friend. But you can't do it in VB.NET for a webpage.

Unless, that is, you have SQL Server 2005 or another database that supports the WAITFOR DELAY {time to delay} command. 

Sub sleep(sec as integer) Dim con_timeout, sql ' indicate a number of seconds, up to 59 ' if you need more than 59 seconds, you will need to adjust the SQL below If sec > 59 then sec = 10 End if ' make sure timeout doesn't expire! ' assumes we have an already active connection to the database called "con" con_timeout = con.commandTimeout con.commandTimeout = sec + 5 sql = "WAITFOR DELAY '00:00:" & right("00" & cstr(sec),2) & "'" con.Execute(sql,,129) ' put the timeout back con.commandTimeout = con_timeout End Sub

Now the script may take a fair bit longer to operate, but the judicious use of sleep(2) within the more tightly looping and time consuming bits of code means that the server can spare some cycles to answering other demands on it.

Of course, you then need to make sure that your script doesn't timeout, so careful use of Server.ScriptTimeout to balance it is also called for



Script debugging in IE

clock September 26, 2006 03:46 by author offbeatmammal

When I'm developing pages that have a lot of JavaScript in, I love Firefox. Ignoring all the hype about why it's better than Internet Explorer it does have one really cool, out of the box debugging tool - the JavaScript Console. It makes tracking problems down so easy. Sure it's a two step process (find the offending error message in the console log, and then look in the source viewer to find the actual line - sometimes a tricky thing when the page is dynamically generated).

But all is not lost in IE. Far from it. Most people when they want to debug JavaScript in IE complain that the only way to do it is to go and buy a copy of Visual Studio. Well, sure, you can do that if you want. But as anyone who's used it to try and debug one typo in a page it can be overkill. Luckily the answer lies in the free (and very small download) MS Script Debugger.

It's integrated with IE (including the latest IE7 betas and release candidate) - when you get a JavaScript error reported on the page just hit "yes" to debug and get taken to the offending line nicely highlit in a source viewer (and if you want to check the source at any time the debugger adds a new item to the "view" menu).

The other toy that makes developing and debugging (JavaScript, HTML, CSS and graphics) in IE a pleasure is the new developers toolbar. This little add-on for IE7 comes with a whole host of goodies from on-screen rulers, a fully featured DOM inspector, the ability to disable browser functions (eg JavaScript or CSS), site level cookie control, highlighting (and detailed information) for any element you might need to examine and even a handy resizer to fit common screen sizes to see how things look.

As a developer currently working on an image,CSS and JavaScript heavy site these tools are invaluable in helping me to deliver what the designer and client want. Give them a quick try and see what you think....



Script debugging in IE

clock September 26, 2006 03:46 by author OffBeatMammal

When I'm developing pages that have a lot of JavaScript in, I love Firefox. Ignoring all the hype about why it's better than Internet Explorer it does have one really cool, out of the box debugging tool - the JavaScript Console. It makes tracking problems down so easy. Sure it's a two step process (find the offending error message in the console log, and then look in the source viewer to find the actual line - sometimes a tricky thing when the page is dynamically generated).

But all is not lost in IE. Far from it. Most people when they want to debug JavaScript in IE complain that the only way to do it is to go and buy a copy of Visual Studio. Well, sure, you can do that if you want. But as anyone who's used it to try and debug one typo in a page it can be overkill. Luckily the answer lies in the free (and very small download) MS Script Debugger.

It's integrated with IE (including the latest IE7 betas and release candidate) - when you get a JavaScript error reported on the page just hit "yes" to debug and get taken to the offending line nicely highlit in a source viewer (and if you want to check the source at any time the debugger adds a new item to the "view" menu).

The other toy that makes developing and debugging (JavaScript, HTML, CSS and graphics) in IE a pleasure is the new developers toolbar. This little add-on for IE7 comes with a whole host of goodies from on-screen rulers, a fully featured DOM inspector, the ability to disable browser functions (eg JavaScript or CSS), site level cookie control, highlighting (and detailed information) for any element you might need to examine and even a handy resizer to fit common screen sizes to see how things look.

As a developer currently working on an image,CSS and JavaScript heavy site these tools are invaluable in helping me to deliver what the designer and client want. Give them a quick try and see what you think....



Enabling HTML cleverness in CommunityServer

clock August 27, 2006 11:18 by author offbeatmammal

It was a little thing, but it bugged me with CommunityServer.

I could never include HTML or JavaScript in a specific post. Some HTML worked, other HTML just got stripped out (had driven my mad trying to style images initially.

I'd posted on the CS forums but not had any luck until I found this answer which basically said I should have RTFM in the first place!

Of course the functionality was as designed, and (of course) there is a way to fine-tune it. In this case in the <markup> section of the CommunityServer.config - it allows you to specify what tags and parameters are valid (and any not on the list simply get converted to safe markup. It's very clever. And just goes to prove I really should try and find more time in the day to read manuals!



Enabling HTML cleverness in CommunityServer

clock August 27, 2006 11:18 by author OffBeatMammal

It was a little thing, but it bugged me with CommunityServer.

I could never include HTML or JavaScript in a specific post. Some HTML worked, other HTML just got stripped out (had driven my mad trying to style images initially.

I'd posted on the CS forums but not had any luck until I found this answer which basically said I should have RTFM in the first place!

Of course the functionality was as designed, and (of course) there is a way to fine-tune it. In this case in the <markup> section of the CommunityServer.config - it allows you to specify what tags and parameters are valid (and any not on the list simply get converted to safe markup. It's very clever. And just goes to prove I really should try and find more time in the day to read manuals!



HTML still has some clever tricks

clock August 27, 2006 10:37 by author OffBeatMammal

Even after many years of hacking up HTML pages it surprises me when I discover some new tricks. Or even better old tricks than now work how you expect them to! One of the great things about the forthcoming IE7 release (currently at "Release Candidate 1") is how it's adding a lot more consistent and correct support for CSS. Things like the hover attribute now work everywhere, not just on address links. Now if only Safari would implement the <label for="{id}>label text</label> I'd be happy (oh and if the CSS folks could trouble themselves to come up with a decent 'float:bottom;' type solution for site footers/copyrights that doesn't involve too much fiddling around).

Anyway, I digress. The two old yet new goodies I found (while, as usual, hunting for something totally unrelated) are firstly the <optgroup> sub-element for a <select>... it allows you to group related items together while not itself being selectable

<select>
	<optgroup label="Sites">
		<option value="s01">BigBrother</option>
		<option value="s02">ClubAV</option>
		<option value="s03">AMD Means Business</option>
	</optgroup>
	<optgroup label="Clients">
		<option value="ess">Endemol Southern Star</option>
		<option value="csa">Cat Savard Advertising</option>
		<option value="zzarg">Zzarg Advertising</option>
	</optgroup>
</select>
appears in the browser as:

 

The next discovery is the <fieldset><legend> pairing. This allows you to create a block of related fields with a common boundary. And it's stylable with CSS. In fact, with the new IE7 style capabilities you can even change the look when it has focus

Log In:

So how did we create this? First of all the basic HTML
<fieldset>
	<legend>Log In:</legend>
	<label for="un">User Name:</label> <input id="un"> 
	<label for="pw">Password:</label> <input id="pw" size="10">
</fieldset>
and then some simple stylesheet magic
<style>
fieldset {
	width: 450px;
	border-top: 1px solid #efefef;
	border-left: 1px solid #efefef;
	border-bottom: 1px solid #cccccc;
	border-right: 1px solid #cccccc;
	padding: 1em 1em 1em 1.5em;
}
fieldset:hover {
      border: 1px solid #ABC2EC;
    }
</style>

 

It all goes to show... you can teach an old dog new tricks. And it's even better when the tricks are actually old ones, that now just happen to work fine!



Search

Calendar

<<  November 2014  >>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

Sign in

Twitter


    follow OffBeatMammal at http://twitter.com



     
    Donate unused CPU cycles with BOINC Stats and Account Management from BOINCStats.com



    Blogroll

    Archive

    Tags

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2014