Sunday, January 29, 2012

The Case of the Missing "Close" Button on a JQuery Tools Overlay

I have a button on a page that may or may not be there. When I clicked the button, I wanted a JQuery Tools Overlay to pop up with some information and links. Because the button may or may not be there, I had to create the overlay programatically. I found information on doing so here: http://flowplayer.org/tools/demos/overlay/trigger.html So, on my page, I created a div for the overlay as such:
And, in the function called by the button's on click event, I added this:
 $('#interp_pool_div').html(doctor_selection);
 $('#interp_pool_div').overlay({
            oneInstance: false,
            mask: '#dcdcdc',
            effect: 'apple',
           });
               
         $("#interp_pool_div").overlay().load();
This worked well, except for one thing - the close button didn't appear the second time that I opened the overlay. Also, I was a but worried about memory leaks caused by repeatedly creating the overlay. It turns out that because I was putting the data directly in the overlay div, the second time it ran, it was overwriting the html for the close button. So, the answer was to put a second div inside the overlay div and then load the content into that one. I also but a simple check around the code that creates the overlay to avoid creating it a second time. So, the final working code appears as such: In the HTML:
In the JavaScript, outside the onclick function:
 var overlay_exists = false;
In the function called by the button click:

$('#interp_data').html(doctor_selection);
                              
if(overlay_exists === false){
     $('#interp_pool_div').overlay({
          oneInstance: false,
          mask: '#dcdcdc',
           effect: 'apple',
           
         });
         overlay_exists = true;
}
$("#interp_pool_div").overlay().load();

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:
UPDATE `table` SET fieldname = REPLACE(fieldname,',','|||');
Worked like a charm.

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:


<?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.

Friday, July 8, 2011

Social Skills

I've been thinking about social network etiquette lately. Specifically, I've been thinking about how to deal with spammy friends. Google Plus allows us to easily choose what types of posts to share with groups of friends. I can make sure my programming links and posts only go to fellow programmers. News about job changes, advancements go to my networking people, pictures of the kids go to family and close friends, etc.

I try to be very careful about not sharing the wrong types of information with the wrong people – or too many posts with any particular group. However, not everybody I follow on social networks are as careful. On Facebook, I hide a lot of posts from people whom I like, but just can't take the noise level of their posts. On Twitter, it was more of a pain. I had to choose certain twitter clients that allowed me to filter out noisier friends.

Google Plus doesn't have any sort of filters yet. If it would allow me to chose which circles I want to see in my main stream, I would be satisfied. But right now, I would have to go look at specific circles to see the non-noise posts. And, circles are actually better used for me to sort whom I'm going to say what from – not whom I'm going to read from. While I may want to share a picture of my new apartment with a cousin, I don't necessarily want to read about her Amway business.

Until now, I've always used tools and filters to try to clean up the noise. But, that means I'm missing some things from people I genuinely do care about. I'm starting to wonder if I should not be using software tools to correct the problem, but use communication skills instead. In Google Plus, I wonder if it would be polite to request that certain people put me in certain kinds of circles rather than others? Would it be polite to suggest that they not share everything they say with everybody in their network? How does one even begin to tell a friend they simply talk too much or that I really don't want to be sold to?

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.

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.