UPDATE `table` SET fieldname = REPLACE(fieldname,',','|||');Worked like a charm.
Thursday, September 8, 2011
A MySQL Query to Replace a Character in a String
I wrote an import script for our old application to the new application database recently. While testing the import today, I noticed that a certain field used comma delimiters in the old database, but used ||| in the new, and my conversion script hadn't taken that into account. I needed a quick way to replace all the commas that came over in the input with pipes.
Here is the query that did it for me:
Friday, August 26, 2011
Unit Testing in Cake PHP 2.0
I had some trouble getting Unit Testing working with Cake PHP 2.0. But, after quite a bit of time of tinkering, I got it working.
1. The first step is to get PHP Unit installed. I used Pear, which worked with no problems. These Instructions worked for me on Windows.
2. I am using the latest version of Cake PHP 2.0 from git. Setting that up is essentially the same as setting up Cake PHP 1.3.x
3. I added a simple User model with the following table structure:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` char(50) DEFAULT NULL,
`password` char(40) DEFAULT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
4. My goal for this first unit test was simple - get a unit test running and make it assert some trivial truth. I grabbed an example unit test from Cake PHP 1.3.x and tweaked it. And, this test should hopefully work for you as well to help establish that you have your environment working and so you can see the new naming conventions and directory structure.
In app/Test/Fixture, I created a file UserFixture.php with the following contents:
5. In app/Test/Case/Model I created the file UserTest.php with the following contents:
6. Running the test was as simple as in Cake 1.3.x - Go to your application and call test.php. Select App/Tests and run your User Test Case.
1. The first step is to get PHP Unit installed. I used Pear, which worked with no problems. These Instructions worked for me on Windows.
2. I am using the latest version of Cake PHP 2.0 from git. Setting that up is essentially the same as setting up Cake PHP 1.3.x
3. I added a simple User model with the following table structure:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` char(50) DEFAULT NULL,
`password` char(40) DEFAULT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
4. My goal for this first unit test was simple - get a unit test running and make it assert some trivial truth. I grabbed an example unit test from Cake PHP 1.3.x and tweaked it. And, this test should hopefully work for you as well to help establish that you have your environment working and so you can see the new naming conventions and directory structure.
In app/Test/Fixture, I created a file UserFixture.php with the following contents:
<?php
class UserFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'User'
* @access public
*/
public $name = 'User';
/**
* fields property
*
* @var array
* @access public
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'username' => array('type' => 'string', 'null' => false),
'password' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
/**
* records property
*
* @var array
* @access public
*/
public $records = array(
array('username' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
array('username' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
array('username' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'),
array('username' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'),
);
}
5. In app/Test/Case/Model I created the file UserTest.php with the following contents:
<?php
App::import('Model', 'User');
class UserTestCase extends CakeTestCase
{
public $fixtures = array('user');
public $User;
public function setUp()
{
$this->User =& ClassRegistry::init('User');
}
public function testGetInstance()
{
$created = $this->User->field('created', array('User.username' => 'mariano'));
$this->assertEquals($created, '2007-03-17 01:16:23', 'Created Date');
}
}
?>
6. Running the test was as simple as in Cake 1.3.x - Go to your application and call test.php. Select App/Tests and run your User Test Case.
Tuesday, October 6, 2009
I Spent How Much at the App Store?!!!
Just learned about an Mac application that shows me how much I have spent at the iPhone app store. The free App Store Expense Monitor puts an item in my menu displaying the total amount I've spent. $269.21. I'm stunned. Those little 99-cent apps add up.
Of course, I've got a couple of big-ticket items in there too. $30 for a log-me-in app that I never use being the most lamentable.
The expense monitor also was kind enough to export a csv file of all my app store purchases - including free apps. Maybe this tangible evidence will curtail some of my impulse purchases.
Friday, September 18, 2009
Finally! A YUI Book to Help Me Get a Handle on this Stuff
I am working through Dan Wellman's book Learning the Yahoo! User Interface library: Develop your next generation web applications with the YUI JavaScript development library.
The examples in it are not any better than the examples provided online for free by Yahoo!. However, the accompanying prose really helps me 'get' what is going on with the code. This means that I am finally starting to understand what I am doing with these YUI controls and am not just copying and pasting and hacking to make things work.
As much as I hate Javascript, now that I understand it a bit more, the fear and loathing is starting to diminish. And, when I'm done, I think I will have a pretty sleek Scheduling application written for ZMR.
The examples in it are not any better than the examples provided online for free by Yahoo!. However, the accompanying prose really helps me 'get' what is going on with the code. This means that I am finally starting to understand what I am doing with these YUI controls and am not just copying and pasting and hacking to make things work.
As much as I hate Javascript, now that I understand it a bit more, the fear and loathing is starting to diminish. And, when I'm done, I think I will have a pretty sleek Scheduling application written for ZMR.
Sunday, September 13, 2009
Yet Another Reason I Love Apple
I tried to backup my iTunes music. I really did. I had it on an external USB drive. I set up Carbonite (which doesn't backup external USB drives :( ) I also started synching my library to my husband's using the new Family share in iTunes 9. But, when the roof sprung a leak and destroyed my USB drive and many important components of my beloved Macbook pro, I found I hadn't quite backed up enough.
I had heard rumors that the iTunes store would grant a one-time only re-download of my entire library in case of just such an emergency. I emailed them with my tale of woe, and less than 24 hours later, I am downloading everything I have ever bought from iTunes.
Now, I won't compare them with Audible, which lets me download my stuff whenever I want as many times as I want because I am just feeling too much Apple love. Now, I just need to figure out a way to earn enough money to fix or replace my beloved Macbook Pro.
Wednesday, September 9, 2009
iTunes 9.0
iTunes 9 is out, and if you have and iPhone, this is a very worthwhile update. Apple gave us an interface within iTunes to organize our iPhone apps. I helped hubby get his phone updated and organized, and even he was impressed.
Saturday, March 7, 2009
ColorSplash - Put Some Style Into iPhone Photos

I love black and white films that have small, bright splashes of individual colors. There is something so compelling about islands of dazzling color in a sea of gray. ColorSplash ($1.99) is an iPhone app that allows you to create that effect in your photographs.
The app works by converting any image in your photo library (or one that you snap on the fly through the app) to black and white and then allowing you to selectively add color back to key areas. My first attempt was to edit a close-up picture of my youngest child. She has blue eyes that I thought would pop right out of the picture. Unfortunately, her eyes were just a wee bit too light to really pop.
My second try was a picture of the girls with Santa. As you can see, Santa's red suit jumps right out of the sea of gray. I think I would be happier with the shot if there was a tiny splash of red somewhere else in the photo, but all in all, it's a good picture considering it was done with a camera phone.
The user interface is easy to pick up. Zooming and moving around the picture works as you would expect. There are two buttons - one to convert to black and white - one to restore the color. Click the desired button, and then paint the area with your finger. Color appears or disappears as desired. It brings to mind the paint with water books from my childhood.
With the right photographs, this application can produce some stunning effects. I believe it was $2 well spent, and I look forward to playing with it some more.
Subscribe to:
Posts (Atom)