Nov30

Commit failed (details follow): File ‘your_file’ is out of date

Posted by: Brian Chan | Filed in: technology, Uncategorized | Tags: | 02:12 pm, November 30th, 2011 1 Comment »

I have no idea, but all of a sudden I got this svn error during my commit.

My solution is roughly the following.

1
2
3
4
5
6
cp your_file your_file.bak
svn revert
svn update
cp your_file.bak your_file
svn commit
rm your_file.bak

A nice workaround that helped me move on.



Nov29

17 Keys To Success

Posted by: Brian Chan | Filed in: life | Tags: | 06:39 pm, November 29th, 2011 No Comments »

Jim Rogers‘ Keys to Success (taken from the titles and sub headings of each chapter of the new book, “A Gift To My Children“):

1. Do not let others do your thinking for you

2. Focus on what you like

3. Good habits for life & investing

4. Common sense? not so common

5. Attention to details is what separates success from failure

6. Let the world be a part of your perspective

7. Learn philosophy & learn to think

8. Learn history

9. Learn languages (make sure Mandarin is one of them)

10. Understand your weaknesses & acknowledge your mistakes

11. Recognize change & embrace it

12. Look to the future

13. “Lady Luck smiles on those who continue their efforts”

14. Remember that nothing is really new

15. Know when not to do anything

16. Pay attention to what everybody else neglects

17. If anybody laughs at your idea view it as a sign of potential success



Nov29

indispensable

Posted by: Brian Chan | Filed in: fun | Tags: | 12:30 am, November 29th, 2011 No Comments »

Dilbert.com



Nov28

First thing in the morning, I got this mysql server error.

1
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Apparently, /tmp/mysql.sock is missing. I know that’s the right path, but the file is not there.

I restarted the mysql server by press the “Start MySQL Server” button, but it’s not running. I ran mysqld, but it gave me more errors and failed to start.

I ended up making it work by providing a my.cnf file, which I hadn’t needed.

1
sudo cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf

Modify the default settings if needed. Then press the “Start MySQL Server” button again. My apache server then worked fine.



Nov17

Carrots

Posted by: Brian Chan | Filed in: Uncategorized | Tags: | 09:50 am, November 17th, 2011 No Comments »


Nov14

Math problem

Posted by: Brian Chan | Filed in: fun | Tags: | 02:02 pm, November 14th, 2011 No Comments »

Math problems are getting much trickier nowadays…



Nov11

PHP command line memory limit error

Posted by: Brian Chan | Filed in: Uncategorized | Tags: | 12:00 pm, November 11th, 2011 No Comments »

Very often, when data size gets bigger and bigger, some scripts will break due to default memory limit. I got the following error today.

1
2
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /someDir/myScript.php on line 15
Segmentation fault: 11

I checked my php help. I am using version 5.3.6.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$ php -h
Usage: php [options] [-f] <file> [--] [args...]
       php [options] -r <code> [--] [args...]
       php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
       php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
       php [options] -- [args...]
       php [options] -a
 
  -a               Run as interactive shell
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse and execute <file>.
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -r <code>        Run PHP <code> without using script tags <?..?>
  -B <begin_code>  Run PHP <begin_code> before processing input lines
  -R <code>        Run PHP <code> for every input line
  -F <file>        Parse and execute <file> for every input line
  -E <end_code>    Run PHP <end_code> after processing all input lines
  -H               Hide any passed arguments from external tools.
  -s               Output HTML syntax highlighted source.
  -v               Version number
  -w               Output source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.
 
  args...          Arguments passed to script. Use -- args when first argument
                   starts with - or script is read from stdin
 
  --ini            Show configuration file names
 
  --rf <name>      Show information about function <name>.
  --rc <name>      Show information about class <name>.
  --re <name>      Show information about extension <name>.
  --ri <name>      Show configuration for extension <name>.

Looks like -d with do it. So I ran the following:

1
php -d memory_limit=512M myScript.php

It worked fine.

If you can afford to change your php.ini file, use – -ini to see where your php.ini file is, then make your changes accordingly. You can also use -n to ignore your php.ini file, but then you will be using default parameters which may be even harder to debug.



Nov10

Validate line by line

Posted by: Brian Chan | Filed in: Uncategorized | Tags: | 04:14 pm, November 10th, 2011 No Comments »

Here is a good compilation of codes doing string format validation in C#, VB.NET, Java, Javascript, PHP, Perl, Python, and Ruby. It’s a good reference page.

http://answers.oreilly.com/topic/224-how-to-search-line-by-line-with-a-regular-expression/



Nov9

Stop UTF 8 with javascript

Posted by: Brian Chan | Filed in: technology | Tags: | 03:58 pm, November 9th, 2011 No Comments »

Below is how you can detect non-ascii characters with javascript.

1
2
3
4
5
6
7
8
s = $("#something").val();
for (var i=0; n < s.length; i++) {
	var c = s.charCodeAt(i);
	if (c >= 128) {
		alert('Invalid character \'' + String.fromCharCode(c) + '\'');
		return false;  // or throw an error
	}
}

Of course if you have to take in non-ascii values, then be prepared to set up your environments first. The links below will help.
http://us.php.net/manual/en/function.base64-encode.php
http://pureform.wordpress.com/2008/03/23/make-your-website-completely-utf-8-friendly/



Nov8

max_allowed_packet error during mysqldump

Posted by: Brian Chan | Filed in: Uncategorized | Tags: | 02:15 pm, November 8th, 2011 1 Comment »

Got a “max_allowed_packet” error during mysqldump. This happened after I added a longblob to one of my tables. Below is the error:

1
2
mysqldump --routines --user=root -p localDB > backup.mysql.txt
mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `table2` at row: 86

It turns out max_allowed_packet is set to something less than whatever is in my row 86. Longblob can go up to 4Gb so I will need to override the max_allowed_packet value.

I found the following way the easiest to re-enable the dump.

1
mysqldump --routines --max_allowed_packet=100M --user=root -p localDB > backup.mysql.txt