Put your message here! Contact me for more information
 
 







 

Archive for August, 2006


 

While I was constructing a SQL string to run through a cfquery command, I found out about the bug in how ColdFusion’s cfquery handles quotes:



sql = “SELECT * FROM someTable WHERE thisColumn = ‘thatValue’”;


#sql#

The server refused to work the script! Why? Because ColdFusion for some mysterious reasons automatically replace the single quote around ‘thatValue’ with 2 single quotes, e.g. ”that value”.

So how do you solve this? Wrap the sql string with a replace like this


#replaceNoCase(sql, “””, “‘”, “all”)#

=== Update ===
There’s another way to solve the doubled single-quote problem is to use the #preserveSingleQuotes# as shown in this article from Adobecrodia (or Macrodobe, whatever works for you)





dbtype="#arguments.dbType#">
#preserveSingleQuotes(arguments.SQLString)#




(http://www.adobe.com/devnet/coldfusion/extreme/cftags_cfscript.html)

view comments
 


Well, today is my first day working with MSSQL. It’s been quite a learning curve. Truthfully speaking, working with MySQL is so much easier because MySQL does provide a more flexible way of handling different data formats, especially with datetime.

In MSSQL, if we want to extract the date part from a datetime column, here is the (crazy!) conversion:


SELECT (CAST(FLOOR(CAST(DateTimeColumn AS float)) AS myNewAlias) FROM someTable

On the other hand, in MySQL, the query is an elegant SELECT with the call of the appropriate formatting function.

Here comes another question, how do you actually GROUP the records by DATE? For example the dataset contains tons of UserName entries of different times but same date, here is the code that will group and count those entries


SELECT UserName convert(char(10),DateTimeColumn ,111) as groupDate, Count(*) as hits FROM someTable
GROUP BY UserName, convert(char(10),DateTimeColumn ,111)

Notice the repeating convert() in both the SELECT part and the GROUP BY part. If you do

-- this query doesn't work in MsSQL!
SELECT UserName convert(char(10),DateTimeColumn ,111) as groupDate, Count(*) as hits FROM someTable
GROUP BY UserName, groupDate

then you will be yelled at with “invalid column name groupDate”.

More on MsSQL is coming as I’m working with it and … ColdFusion! (I’m slowly building up a CFSCRIPT and PHP comparison chart and hopefully will be able to release it soon)

view comments
 


I’ve just made a comments on php.net’s manual page under imagecopyresized() about resizing transparent PNGs with GD. Here is the post again, hopefully it can help someone. Comments are welcome.

Belows is the code snipet that allows you to resize a transparent PNG and composite it into another image. The code is tested to work with PHP5.1.2, GD2, but I think it can also work with other versions of PHP and GD.

The code has been commented to help you read through it. The idea of resizing the transparent PNG image is to create a new destination image which is completely transparent then turn off the imageAlphaBlending of this new image so that when the PNG source file is copied, its alpha channel is still retained.

===Code:===


/**
* Compose a PNG file over a src file.
* If new width/ height are defined, then resize the PNG (and keep all the transparency info)
* Author: Alex Le - http://www.alexle.net
*/
function imageComposeAlpha( &$src, &$ovr, $ovr_x, $ovr_y, $ovr_w = false, $ovr_h = false)
{
if( $ovr_w && $ovr_h )
$ovr = imageResizeAlpha( $ovr, $ovr_w, $ovr_h );

/* Noew compose the 2 images */
imagecopy($src, $ovr, $ovr_x, $ovr_y, 0, 0, imagesx($ovr), imagesy($ovr) );
}

/**
* Resize a PNG file with transparency to given dimensions
* and still retain the alpha channel information
* Author: Alex Le - http://www.alexle.net
*/
function imageResizeAlpha(&$src, $w, $h)
{
/* create a new image with the new width and height */
$temp = imagecreatetruecolor($w, $h);

/* making the new image transparent */
$background = imagecolorallocate($temp, 0, 0, 0);
ImageColorTransparent($temp, $background); // make the new temp image all transparent
imagealphablending($temp, false); // turn off the alpha blending to keep the alpha channel

/* Resize the PNG file */
/* use imagecopyresized to gain some performance but loose some quality */
imagecopyresized($temp, $src, 0, 0, 0, 0, $w, $h, imagesx($src), imagesy($src));
/* use imagecopyresampled if you concern more about the quality */
//imagecopyresampled($temp, $src, 0, 0, 0, 0, $w, $h, imagesx($src), imagesy($src));
return $temp;
}
?>

===Example usage:===


header('Content-type: image/png');

/* Open the photo and the overlay image */
$photoImage = ImageCreateFromJPEG('images/MiuMiu.jpg');
$overlay = ImageCreateFromPNG('images/hair-trans.png');

$percent = 0.8;
$newW = ceil(imagesx($overlay) * $percent);
$newH = ceil(imagesy($overlay) * $percent);

/* Compose the overlay photo over the target image */
imageComposeAlpha( $photoImage, $overlay, 86, 15, $newW, $newH );

/* Open another PNG file, then resize and compose it */
$watermark = imagecreatefrompng('images/watermark.png');
imageComposeAlpha( $photoImage, $watermark, 10, 20, imagesx($watermark)/2, imagesy($watermark)/2 );

/**
* Open the same PNG file then compose without resizing
* As the original $watermark is passed by reference, it was resized already.
* So we have to reopen it.
*/
$watermark = imagecreatefrompng('images/watermark.png');
imageComposeAlpha( $photoImage, $watermark, 80, 350);
Imagepng($photoImage); // output to browser

ImageDestroy($photoImage);
ImageDestroy($overlay);
ImageDestroy($watermark);
?>

view comments
 

For the past couple of years, I have allowed people to post on this page regarding Primerica because I was interested in hearing people’s comments on that subject. I appreciate all the posts made here, and from those comments, it is clear that Primerica is a legitimate company, and that the opportunity it provides is suitable for some people and not for others. Because the discussion has gone on for some time now and I am moving on to other projects, I have decided to close this page to further comments.

view comments
 

POTCI’ve been listening to the Pirates of the Caribbean soundtracks for the past 2 weeks. when I saw the first POTC and listened to the final ending score, I knew that I had to get the soundtrack. I did, thanks to TorrentsSpy. I wish I have some money to shell out for the CD, but it’s a different stories. I’ll pay for the actual CD when I start working

I have to admit that both albums are really excellent. But if I have pick, I would pick the first one. Eventhough the second one was written by Hans Zimmer, the man himself, the first one, written by Klaus Badelt, has better melody. I absolutely love the epic melody of the “He’s a pirate”. The 2nd one doesn’t have any melody or lines that can compared with “He’s a pirate”. Don’t get me wrong, the 2nd album is at the high position in my listening list too - I just love the melodies of the first album more.

Listening to the albums, I can close my eyes and drift along with every songs, every movements and imagine myself amongst the pirates, sailing on the Black Pearl with Jack Sparrow…

Amazing albums. Highly recommended. I wonder what the 3rd movie will be like. And for sure I’ll get the Soundtrack too to complete the trilogy.

view comments