Math problem
Math problems are getting much trickier nowadays…
Math problems are getting much trickier nowadays…
Very often, when data size gets bigger and bigger, some scripts will break due to default memory limit. I got the following error today. 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. $ php -h Usage: php [options] [-f] [--] [args...] php [options] -r [--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...] php [options] -a -a Run as interactive shell -c | 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 Parse and execute . -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r Run PHP without using script tags -B Run PHP before processing input lines -R Run PHP for every input line -F Parse and execute for every input line -E Run PHP 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 Load Zend extension . args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf Show information about function . --rc Show information about class . --re Show information about extension . --ri Show configuration for extension . Looks like -d with do it. So I ran the following: 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. ...
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/
Below is how you can detect non-ascii characters with javascript. s = $("#something").val(); for (var i=0; n = 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/
Got a “max_allowed_packet” error during mysqldump. This happened after I added a longblob to one of my tables. Below is the error: 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. ...
[youtube &w=560&h=315] It’s no longer something we read from scientific novels. Amazing! BTW, I have no idea how that guy just picks up the superconductor. It is supposed to be extremely cold, right?
Here is what the output of “launchctl list” means: list [-x] [label] With no arguments, list all of the jobs loaded into launchd in three columns. The first column displays the PID of the job if it is running. The second column displays the last exit status of the job. If the number in this column is negative, it repre- sents the negative of the signal which killed the job. Thus, "-15" would indicate that the job was terminated with SIGTERM. The third column is the job's label. So when you run “launchctl list | grep something”, the columns correspond to: 1. PID (if it’s running) 2. last exit status code 3. process name ...
Here is the link: http://itunes.apple.com/app/gmail/id422689480?mt=8
I remember dealing with this problem a few years ago. At that time, I didn’t know better so ended up generating tab delimited files. A few years later, I finally gain my dignity back by generating real excel files. I found many libraries out there, below are a few: Ruby roo: http://roo.rubyforge.org/ Ruby spreadsheet: http://spreadsheet.rubyforge.org/ OpenXML: http://openxmldeveloper.org/ Apache POI (Java): http://poi.apache.org/index.html Pear Spreadsheet_Excel_Writer (PHP): http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php PHPExcel: http://phpexcel.codeplex.com/ Python Excel: http://www.python-excel.org/ I believe they will all work just fine as they all look promising. ...
GROUP_CONCAT is very useful when you are doing a GROUP BY, and want to capture the values from other columns. For example: SELECT country, GROUP_CONCAT(city SEPARATOR ',') AS city_arr_str FROM myTable GROUP BY country ORDER BY country Then in say PHP, you can read the city names for each returned row: foreach ($rows as $r){ $country = $r["country"]; $city_arr_str = $r["city_arr_str"]; // parse the city names $city_arr = explode(",", $city_arr_str); // do your stuff... } Everything is fine and all, until later on your database gets much bigger. ...