Categories
- Andy and Javi: Actionscript and AIR Quick Tips
- Arc90
- Architecture
- Avi and Patrick: Java Quick Tips
- Avi: REST Quick Tips
- Ben: PHP Quick Tips
- Business
- Chris and Corey: JQuery Quick Tips
- Chris and Matt: Unix Quick Tips
- Culture
- Dave: PHP Quick Tips
- Design
- Development
- Foresight
- Javi: CF Quick Tips
- Javi: JQuery Quick Tips
- Jobs
- Joel: .Net Quick Tips
- Lab
- Music
- Patrick and Joel: XML Quick Tips
- Reviews
- Tech
- The Internets
- Thoughts
- Trends
- Web
- What We Are Reading
Archives
A jQuery Tip: Don't Use jQuery
Sometimes, there's too much of a good thing. jQuery fires its "$(document).ready()" as soon as the DOM is loaded, but what if that's too soon?
I recently ran into a problem when I was using a script that will resize an iframe, but the iframe hadn't loaded yet. So, after some debugging I realized that--for once--jQuery was not the answer. Resorting to the classic window.onload, which waits until everything is loaded, solved the problem.
The real solution here? Sometimes a Ferrari just won't replace the old pick-up truck.
Comments (1) | Technorati Tags : jQuery DOM ifram window.onload
Posted on May 14, 2008 by Doug BurnsUnit Testing with JUnit 4 and Spring
I really like Java annotations for reducing XML configuration and simplifying code. Spring 2.5 introduced a new annotation-based unit test framework that further improved the great one it already provided. Using this, along with JUnit 4, you can create Spring unit tests without having to subclass anything.
An example unit test is shown below, along with an explanation of the annotations used.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/applicationContext.xml"})
public class ExampleTest
{
ExampleObject objectUnderTest;
@Test
public void testSomethingTrue() {
Assert.assertNotNull(objectUnderTest);
Assert.assertTrue(objectUnderTest.getSomethingTrue());
}
@Test
@Ignore
public void testSomethingElse() {
Assert.assertNotNull(objectUnderTest);
Assert.assertTrue(objectUnderTest.getSomethingFalse());
}
@Autowired
public void setObjectUnderTest(ExampleObject objectUnderTest)
{
this.objectUnderTest = objectUnderTest;
}
}
-
@RunWith- JUnit annotation that specifies that the Spring class runner should be used for running the test. -
@ContextConfiguration- Specifies the location of your Spring application context xml file(s). This gets inherited by subclasses, so you can use it in a base class to configure all of the tests in your application. -
@Test- Indicates that the method should be run as a test. Note that although I used the pre JUnit 4 naming conventions (class names postfixed with "Test" and method names prefixed with "test"), this is not a requirement. -
@Ignore- When this annotation is added, the associated test method will not be run. This is a great alternative to commenting out the methods which was required prior to JUnit 4. In this case, the test would fail if the @Ignore annotation wasn't used because objectUnderTest.getSomethingFalse() does not equal true. -
@Autowired- Indicates that Spring should "wire" this dependency when initializing the test. In this case, a Spring bean named objectUnderTest will be provided.
Comments (0) | Technorati Tags : Java Spring JUnit
Posted on May 13, 2008 by Ben SgroFormatting Debug Output with print_r(
PHP's built in debugging functions, var_dump and print_r, are great for displaying a structured representation of a complex object or array and for viewing data printed to stdout. But what if you want to write that information to a log file?
There are a few decent recursive functions that iterate through the array or object. But there's really nothing quite like the format provided by print_r.
Many programmers don't realize that you can supply the print_r function with a second boolean argument. When set to TRUE (example below), debugging output will be not be rendered to stdout, which allows you to save it to a variable instead.
PHPCODE $complexDebug = print_r($_SERVER, TRUE); error_log($complexDebug); END_PHPCODE
The previous code will take the print_r output of the SERVER array and save it as a string to the 'complexDebug' variable.The second line writes the string (preserving its format) to the error log file.
Comments (0) | Technorati Tags : PHP debug var_dump print_r object array
Posted on May 9, 2008 by Javier JulioMultiple File Extension Filters For CFDirectory
In a recent blog post by Ben Nadel (which should be his...oh, I don't know...56,423rd CF tip?!) he explained that by using the pipe character you can specify multiple file extension filters on the cfdirectory tag. For example, you can do the following:
That would return only Excel and CSV files. You can specify more filters by simply separating them with a pipe character. It seems like the Adobe Documentation team needs to update the ColdFusion Reference because it currently states the following for the filter attribute:
"File extension filter applied to returned names, for example, *.cfm. One filter can be applied."
Such a helpful tip really ought to be stated in the documentation or, even better yet, used as an example. So instead, I'll do all the work for you! Here is an example I wrote up matching the style used in the cfdirectory reference page:
Comments (5) | Technorati Tags : Multiple File Extension Filters CF CFDirectory
Posted on May 6, 2008 by Josh DiehlWhen technology isn't the power behind a killer software feature
Like so many people I waited until the last minute to do my 2007 taxes. After some deliberation I decided to prepare them myself with the caveat that I'd need software to help. I did a little research and decided to go with Intuit's TurboTax desktop version. Intuit also offers an online version of Turbotax for about half the price but I wanted control over my data and didn't want to get locked into one vendor for next year.On whole I think they've gotten the user experience down to about a B+. Its questionnaire format does a good job of guiding you through the various tax issues and making sure you're saving as much money as is allowed. Once completed it can be a little confusing when you need to change something but overall my complaints were minor. Solid but unremarkable software.
Except... Turbotax had a trump up its sleeve. It turns out they've negotiated data sharing agreements with a range of payroll providers, including mine. I was shocked to discover that in about 60 seconds (after entering my provider's ID and then a figure from my W2 as a "password") all of my wage information was imported automatically. No typing, no double checking. Wow! What a killer feature. Not only did it validate my decision to purchase Turbotax it got me excited enough to come into the office the next day and rave about it.
It struck me that the real work in including this feature wasn't accomplished at the keyboard but in the board room. Sure it was probably hard work to format and import the data but the real sweat was in getting all those payroll providers to sign up and share their information. It seems like an obvious move but it took someone at Intuit to not only have the bright idea but to pick up the phone and start calling payroll companies.
I think software folks too often attack problems with a strictly technical mindset. Can you picture the W2 brainstorming meeting? "What if we have them scan the W2 then OCR the data? Wait! What if they enter only half the fields and we can calculate the rest?" Technical wizardry is great but it's only one tool in the software palette. It's easy for developers (and ex-developer manager-types) to default to this way of thinking. It's in their comfort zone, it doesn't require unpleasantness like negotiations and contracts, and it offers the chance to write whiz-bang code. For some challenges the technical approach works, but for others it's sub-optimal or just impossible.
The marketplace has lots of examples of software that wouldn't have succeeded without this approach: Apple's iTunes store, OpenTable's reservations, Seamlessweb's ordering. All of these work because people at those companies were willing to step out of the realm of code and do some old-fashioned horse trading. In the context of software as a product, the non-technical approach can mean golden opportunities for companies versatile enough to take it.
Comments (2) | Technorati Tags :
