Jul8

Disallow de-select when select-all is checked

Posted by: Brian Chan | Filed in: technology | Tags: | 04:59 pm, July 8th, 2011 No Comments »

Very often we need to present many checkboxes, and there is one additional checkbox for select-all. The html code is somewhat like the following:

1
2
3
4
5
<input type=checkbox id=my_select_all onclick="javascript: toggle_selection();">Select All
<input type=checkbox name=opt[] value=1>1
<input type=checkbox name=opt[] value=2>2
<input type=checkbox name=opt[] value=3>3
<input type=checkbox name=opt[] value=4>4

Notice I name the js function toggle_selection because you may actually make it toggle later on.

Then, to enable the usual select-all action, this is the code:

1
2
3
4
5
6
function toggle_selection(){
	$("input[name='opt[]']").each(function (index, el)
	{
		if ($("#my_select_all").is(":checked")) $(el).attr("checked", "checked");
	});
}

Straightforward.

If you want to make the select-all checkbox toggle, change the if statement to the following:

1
2
		if ($("#my_select_all").is(":checked")) $(el).attr("checked", "checked");
		else $(el).removeAttr("checked");

Now, how do we disallow the de-select when select-all is checked? No problem, jQuery to the rescue!

1
2
3
4
5
6
7
jQuery().ready(function (){
	$("input[name='opt[]']").each(function(index, el) {
		$(this).change(function(){
			if ($("#my_select_all").is(":checked")) $(el).attr("checked", "checked");
		});
	});	
}

We are binding a onChange callback to each checkbox. Upon clicking, if our select-all checkbox is checked, our current checkbox will always be set to checked.

Don’t you love jQuery?



Jul4

Installing PEAR on osx

Posted by: Brian Chan | Filed in: DIY, technology | Tags: | 03:02 pm, July 4th, 2011 No Comments »

Assuming you have php installed and working already. And I am using osx 10.6.

Obtaining the installation package/script.

1
curl http://pear.php.net/go-pear.phar > go-pear.phar

Then run it

1
sudo php go-pear.phar

It will then ask you for the path settings. I suggest installing pear at the /usr/local dir, but this is really your preference. In my case, I entered 1, then changed the $prefix to “/usr/local/pear”. The paths below #1 should automatically change accordingly. Then enter to install.

Now, you will need to set your env path variable to point to this pear dir. Open up your ~/.bash_profile, then enter the following line.

1
PATH=/usr/local/pear/bin:$PATH

Then open up a new shell and run “which pear”. If everything is fine, you will get “/usr/local/pear/bin/pear”.

You probably want to change your php.ini file to include the pear dir as well.

1
include_path = ".:/usr/local/pear/share/pear:/php/includes"

To install a pear package, say Console_Getopt, just do the following:

1
sudo pear install Console_Getopt

I am using sudo here because I installed my pear at /usr/local. If you installed pear at your local dir you can take out sudo.

If you used sudo to install pear at your local dir, the /tmp/pear/install dir may be unwritable coz it’s owned by root. You can simply remove that by “sudo rm -rf /tmp/pear”. Then do your “pear install” again as a local user.



Jul2

IMEI

Posted by: Brian Chan | Filed in: DIY, technology | Tags: | 07:39 pm, July 2nd, 2011 No Comments »

If you need to obtain your IMEI # for some reasons, here is how. No, you don’t need the original box of your phone. ;) BTW, I am using an iphone 4 with at&t.

Fire up your phone app, then go to the Keypad tab, then punch in *#06# and a screen should automatically pop up with your IMEI #.

Actually… upon more research, for iphone 4 users, it’s actually a lot simpler. Just go to Settings -> General -> About, then scroll down to find out your IMEI and ICCID #s.



Jun30

MySQL TEXT field types

Posted by: Brian Chan | Filed in: technology | Tags: | 05:27 pm, June 30th, 2011 No Comments »

The maximum amount of data that can be stored:

TINYTEXT 256 bytes
TEXT 65,535 bytes ~64kb
MEDIUMTEXT 16,777,215 bytes ~16MB
LONGTEXT 4,294,967,295 bytes ~4GB


Jun26

DFU

Posted by: Brian Chan | Filed in: technology | Tags: | 02:36 pm, June 26th, 2011 No Comments »

If case you need to put your iphone into the DFU mode, here is a little tutorial: http://www.iclarified.com/entry/index.php?enid=1034.



Jun22

SVN Working Copy locked

Posted by: Brian Chan | Filed in: technology | Tags: | 11:09 am, June 22nd, 2011 No Comments »

I had some kind of ssh error when using subversion. I then did a force quit coz it hung for too long. Then when I started svn again but it kept saying my work directory is locked. I am using osx so I did a “Get Info” on my work directory and toggled the “Locked” checkbox but that didn’t help. Someone said do a recursive “/Developer/Tools/SetFile -a l”, but later on I found out that’s a solution for another problem. The root question here for me is, why does svn think that my work directory is locked?

Answer is, because my work directory has a zero size file called “lock” located at “my_work_dir/.svn/lock”. Once I removed it, snv then went onto another subdirectory to continue its complaint. Yea, so I ended up removing all these “lock” files (literally) to get out of my lock state. I think these lock files were created during my svn sync process, but didn’t get cleaned up since I force quitted.



Jun6

phpMyAdmin navigation frame not resizable

Posted by: Brian Chan | Filed in: technology | Tags: | 05:12 pm, June 6th, 2011 2 Comments »

If you have long database table names you may find it frustrating to use phpMyAdmin, having the end portion of many long tables names truncated. There is really no easy way to widen the navigation frame either… Your last option is to horizontally scroll right… Nooooooooooo….

OK, here is a little fix. The problem here is, there is nothing for you to grab to widen the left frame. That’s due to the fact that the frame border is set to 0. So to fix that, open up the index.php file, search for the first occurrence of frameborder, then change the frameborder variable to 1, or anything but 0.

1
2
3
     <frame frameborder="1" id="frame_navigation"
         src="navigation.php<?php echo $url_query; ?>"
         name="frame_navigation" />

Now you will have a vertical bar to hold onto to do your resizing. You can probably make the bar skinner with css, but this is already good enough for me.

One more thought, you can also hard code the frame width if you want.



Jun6

phpMyAdmin timeout after 1440 seconds

Posted by: Brian Chan | Filed in: technology | Tags: | 04:30 pm, June 6th, 2011 No Comments »

I keep getting this timeout error from phpmyadmin: “No activity within 1440 seconds; please log in again“. @#%@#$@$@ So I decided to change that setting. Open up your config.inc.php file and add the following line:

1
$cfg['Servers'][$i]['LoginCookieValidity'] = 60 * 60 * 12;

The above setting sets the timeout value to 12 hours in phpMyAdmin.

You will then get another warning: “Your PHP parameter session.gc_maxlifetime is lower that cookie validity configured in phpMyAdmin, because of this, your login will expire sooner than configured in phpMyAdmin.“. That makes sense because php’s session will time out first anyways. So we will need to change /etc/php.ini .

1
session.gc_maxlifetime = 43200

That’s 12 hours in seconds. Restart your apache server and you are done!



Jun6

Vim setting

Posted by: Brian Chan | Filed in: technology, Uncategorized | Tags: | 03:16 pm, June 6th, 2011 No Comments »

Once again this is for my sanity. When using vi, I kept finding myself doing Ctrl-G just to know where I am in a particular file, i.e. which line number. To display that all the time, place the following settings in your ~.vimrc file.

1
2
set number
set ruler

“set number” will place a vertical column on the left to show the line numbers. “set ruler” will place a bottom row to show the current line number and row number, plus where you are in the edited file in percentage. Very handy.

One more setting that I have mentioned before. You can color-code your file in vi by adding the following setting.

1
syntax on


Jun6

tree

Posted by: Brian Chan | Filed in: technology | Tags: | 09:48 am, June 6th, 2011 No Comments »

I didn’t know that osx doesn’t have the tree command, I guess I have been taking the linux dev env for granted. Here is a quick little guide to install tree from source. It will make your life a lot easier.

http://shaunchapmanblog.com/post/329270449/how-to-install-the-tree-command-on-mac-os-x