I am the process of migrating a code base from Prototype + old-school JS to jQuery (the new mayor of Awesome Town), and ran across some code that was replacing some (but not all) styles of an element. This led me to jQuery’s css() method, one of the many handy CSS-related features in jQuery.. As I often do when tinkering with a new language, library, framework or feature I like to whip up a code sample. With this example I was able to see that the css() method adds css to an element without replacing other css attributes. A working example can be found here.
<html><head><title>styles</title><scriptsrc="http://code.jquery.com/jquery.min.js"type="text/javascript"></script><scripttype="text/javascript">
function modColor(){
jQuery("#awesometown").css
({
'color':'red'
});
}
function modStyle(){
jQuery("#awesometown").css
({
'text-decoration':'underline'
});
}
function modVis(){
jQuery("#awesometown").css
({
'display':'none'
});
}
function modSize(){
jQuery("#awesometown").css
({
'color':'black',
'text-decoration':'none',
'display':''
});
}
</script></head><body><h1id="awesometown">I Am An H1 Tag On A Page With No Meaningful Content</h1><em>sung to the tune of "Horse With No Name"</em><hr/><ahref="javascript:modColor();">red,</a><ahref="javascript:modStyle();">underlined,</a><ahref="javascript:modVis();">gone,</a><ahref="javascript:modSize();">reset</a></body></html>
I use regular expressions just often enough to have to totally re-learn them every time I need to use them. After a round of Google searches, reading over a few good regex sites (here’s one) and a bit of head scratching and code tinkering I end up with the code I need.
In this particular case I needed append a variable with punctuation in cases where the variable ended in an alphanumeric character. Regex to the rescue!
1
2
3
4
5
6
7
<cfset variables.question ="what does the yellow light mean"/><cfifReFindNoCase("[a-zA-Z0-9]$", variables.question )><cfset variables.question = variables.question &"?"/></cfif><cfoutput>
#variables.question #
</cfoutput>
Reverend Jim Ignatowski
This has nothing to do with regular expressions, but it’s a classic moment from Taxi.
You
The next time you need some regex help you may want to check out http://www.regular-expressions.info. If you have any good regex tips or sites leave them in the comments below. As usual, spammers will be shot on site.
I’m into my first week at my new job and I’ve been spending some time getting my workstation setup. This task includes getting Firefox installed and adding some key Add-Ons. Here’s my list…
It’s hard to believe, but this year’s CFUnited will be the last. I had a chance to attend CFUnited a few years ago and found it to be fun and inspiring.
I urge my fellow ColdFusion developers to take advantage of CFUnited this year (while it’s..sniff…still here). As always the speaker and topic lineup is top notch.
I’ve read and coded my way through the first chapter of Head First Design Patterns and enjoyed working with the MiniDuckSimulator sample. The author(s) make a good case for favoring composition over inheritance. I look forward to understanding this concept on a deeper, actionable level as I continue onto Chapter 2. I’ve included some (but not all) of my code from Chapter 1…
/*
MiniDuckSimulator.java
creates a new instance of MallardDuck and ModelDuck
and demonstrates the different behaviors of each
*/publicclass MiniDuckSimulator{publicstaticvoid main(String[] args){System.out.println("-- new MallardDuck instance...");
Duck mallard =new MallardDuck();
mallard.performQuack();
mallard.performFly();System.out.println("-- new ModelDuck instance...");
Duck model =new ModelDuck();
model.performFly();// now he can fly!
model.setFlyBehavior(new FlyRocketPowered());
model.performFly();}}
1
2
3
4
5
6
7
8
9
10
11
12
/*
MallardDuck.java
a duck that has wings and can quack
*/publicclass MallardDuck extends Duck{// constructorpublic MallardDuck(){
quackBehavior =new Quack();
flyBehavior =new FlyWithWings();}}
1
2
3
4
5
6
7
8
9
10
11
12
/*
ModelDuck.java
a duck that cannot fly
*/publicclass ModelDuck extends Duck{// constructorpublic ModelDuck(){
flyBehavior =new FlyNoWay();
quackBehavior =new Quack();}}
1
2
3
4
5
6
7
/*
FlyBehavior.java
the interface!
*/publicinterface FlyBehavior {publicvoid fly();}
Over the last few days I’ve been sinking my teeth into Head First Design Patterns. I’m really enjoying both learning about Design Patterns as well as slinging some Java code.
I’ve been reading a lot about jQuery these days. First my friend and former associate Rick “American” Flagg suggested that I check it out, then I took notice of Ray Camden’s recent posts on jQuery. With the power of suggestion now firmly behind the wheel I headed over to the jQuery website, and worked through the first few tutorials.
Now I fancy myself a bit of a JavaScript hack, so after coding the examples in the first two lessons I began to tinker a bit. I ended up with the following fun and pointless bit of code…
Throughout my career as a software developer I’ve worked at shops that use revision control software. I’ve worked with systems that implement file locking (Visual Source Safe) as well as systems that implement branching and merging (CVS and Subversion). In my view using any system is better than using none at all.
If your organization isn’t using some sort of system for managing / storing your code then you are working in a state of unnecessary risk. For example, if you are working on a shared development environment, and the server that your code resides on is only backed up every 24 hours, you are one failed hard drive away from losing one day’s worth of work. Now imagine that your server’s backup is corrupted and you are a few months into development you could be looking at losing several months worth of work.
I’m working on generating PDF reports in ColdFusion 8 using the quick and easy cfdocument tag, and discovered that I cannot open and close tables using cfdocumentitem headers and footers. Here’s what I would have liked to do…
Apparently there is a work-around for this if one is using Open BlueDragon. If anyone out there has a ColdFusion 8 solution that they’d care to share I would appreciate it…and apparently so would fellow CF developer Renu Deshpande.