Archive for June, 2009
Your poor peepers. Too much white all day long. Not only should you do this, you should use Blackle instead of regular Google to save on energy (alternatively, you can use iGoogle and just pick a darker theme). I’ve gone through and replaced the backgrounds with black and white text with CCC. Some colors (009 and 00F) have been slightly adjusted (039 and 03F) for better contrast. Other than those, the greens, reds, oranges, etc are the same. Make sure to enable “Highlight Invalid Code” or lines containing unclosed tags and the like will change to black text. Screen cap
Backup “colors.xml” in the following folder.
Vista: C:\Users\<username>\AppData\Roaming\Adobe\Dreamweaver CS4\<language>\Configuration
Windows XP: C:\Documents and Settings\<username>\Application Data\Adobe\Dreamweaver CS4\<language>\Configuration
Mac OS X: Macintosh HD:<username>:Library:Application Support:Adobe:Dreamweaver CS4:<language>:Configuration
Then replace it with this: colors.rar. Should be ready to rock.
Oh, on a side note, the font Anonymous is great for coding, very easy to read. I like it on the smallest font size setting.
I was having a grand time writing some regex patterns in my Regular Expression Tester extension for FireFox. I needed to match some special characters because the site I was working on catered to international users. I would need to be able to validate strings containing acute, umlauts, etc. So, a pattern that I was happy with that would work in typical regex fashion:
[\u0021-\u007E
|\u00A1-\u00FF
|\u2013-\u2030
|\u20AC]
This matches exclamation to tilde, inverted exclamation to lower “y” with umlauts, en dash to per thousand sign, and the euro symbol. I allowed a couple non-html 4/4.01 characters just to keep the pattern within reason. Now, I’m a CFer and the typical format of escaping “u” followed by the unicode hex does not work. What I was not sure of was whether or not I could create a range of characters with Coldfusion’s CHR() business. True enough. Check your local ascii table for more info on which specific characters you want to match. Here’s some code testing the method:
<cfoutput>
<cfset pattern = "[#CHR(33)#-#CHR(126)#
|#CHR(161)#-#CHR(255)#
|#CHR(8211)#-#CHR(8240)#
|#CHR(8364)#]" />
#IsValid("regext","@",pattern)#
#IsValid("regext","Ñ",pattern)#
#IsValid("regext","€",pattern)#
</cfoutput>
yes yes yes
PS, sorry about how narrow the content section is; Some code won’t work because I added line breaks.
I have a project I’m working on at the moment that has an incrementing series {1,2,3,n=n+1,…n} and I need to convert that into a repeating series like so {1,2,3,3,1,2,3,3,etc}. This is in coldfusion and the obvious solution is as follows:
<cfloop from="1" to="20" index="n">
<!--- gives us 1,2,3,0,1,2,3,0 --->
<cfset iCount = n MOD 4 />
<!--- manually set to 3 if iCount=0 --->
<cfif iCount EQ 0>
<cfset iCount = 3 />
</cfif>
<cfoutput>#iCount#<br></cfoutput>
</cfloop>
Well that’s great. It’s simple and probably runs fast (In production I’m only actually running from 1 to 20ish). I believe I’ve mentioned that I’m stubborn and LOVE clever solutions. We’re already running some math functions so I don’t feel bad calling it more.
Random pseudo code I’m making up as I go:
n = {1,2,3,4,...n=n+1}
n = (n-1) % 4
// 0,1,2,3, 0,1,2,3
n = n+1
// 1,2,3,4 1,2,3,4
// In binary...
// 0001 0010 0011 0100
k = n SRL 2
// 0000 0000 0000 0001
// 0,0,0,1, 0,0,0,1
n = n - k
// 1,2,3,3, 1,2,3,3
Bitwise operations ftw. There is probably some other solution involving BitAnd BitXOr.
<cfloop from="0" to="20" index="k">
<cfoutput>
#((k MOD 4)+1) - BitSHRN((k MOD 4)+1,2)#
</cfoutput>
</cfloop>
Here’s something I wasn’t aware of, if an associated array is populated by a named key, the length is not increased.
var someArray = new Array();
someArray['someKey'] = "someValue";
alert(someArray.length); // expected 1, got blank
alert(someArray['someKey']); // "someValue"
This is a problem if you’re trying to loop the array by jQuery.each(arr, function).
// Same array population
$.each(someArray, function(k,v) {
alert(k + "|" + v);
});
This will not do anything as jQuery loops by the array length. Given the way our array is set, this WILL work:
// Same array population
for(var k in someArray) {
alert(k + "|" + someArray[k]);
}
If we change our array to ditch the named key…
var someArray = new Array();
someArray.push("someValue");
$.each(someArray, function(k,v) {
alert(k + "|" + v);
});
That will work, but that isn’t how I want to do it. This is where I was spacing another method, creating an object instead of an array.
var someArray = new Object();
someArray['someKey'] = "someValue";
$.each(someArray, function(k,v) {
alert(k + "|" + v);
});
Ah ha! That’s how to rock it.
jQuery.each docs




