For a long time I have been using the image captcha with random characters, and got fed up. I had seen numeric computational captcha or Mathematical captcha where one has to calculate the answer of an equation with simple arithmetic and supply the result for verification. Last night I was pondering over this while watching a movie on the TV. Well the out come is obvious.
Read more…
Code Snippets, PHP, Tips
I was digging through my old codes to get this, still could not find. Hence when I wrote it, just made a note here such that later it wont be difficult to find atleast for me.
Read more…
Code Snippets, PHP, Tips
php snippets, php tips
This is not any new thing and may be discussed at different other places. But just as I came across like any other things, I just wanted to make a record of this.
When selecting datetime to be displayed in a JavaScript ui library, select the unix_timestamp * 1000 from the sql.
Read more…
Javascript, PHP, Tips, mysql
MSSQL, mysql
With the help of some colleagues, I could export all the indexes and primary keys, which we were using from a MySQL table as MSSQL compatiable TSQL using a union query and on the MySQL information_schema.
I did the migration to MSSQL using some tips found online, and calling a sp after connecting directly with the MySQL server. Actually forgot how it was done. Anyway it does not matter in this post. Will add it as a comment later on. The important matter was that, the method did not import any of the indexes, or primary keys. We manually created those were absolutely necessary to roll out the project. And now that we were about to release a service patch, and this includes more incredible search methods, the indexes are absolutely necessary.
Read more…
Tips, mysql
MSSQL, mysql
Writing this post and am getting ready to hide behind strong walls, since mostly lighttpd is meant to fly light, or serve faster without the bloat and dynamic flexibilities. But certain situations may occur where one may have to forget the religion and behave sensibly. For a major project which was collaborated by different teams of our spread out offices, one part was developed by a team who were more exposed to benefitting the furls (friendly urls), by using apache rewrites. The bang off was detected only at the last moment of roll out to the beta deployment at client environment.
Read more…
PHP, Tips
htaccess lighttpd, lighttpd rewrites for developer
A reader once asked me if I could build a command line tool which takes title from one file, and content from another file to create wordpress post. I tried, which finally gave an outline to this script. I dont think that this is very high fly, but for those whom the xmlrpc is mumbo, this might be somthing worth looking into.
Read more…
Code Snippets, PHP, Tips
php cli, wordpress, xml rpc
While strolling around I found some bits and pieces which I put together to get a short twitter counter in php.
<?php
ob_start();
$json = file_get_contents("http://twitter.com/statuses/user_timeline/php_trivandrum.json?count=1");
$data = json_decode($json, true);
ob_get_clean();
echo $data[0]['user']['followers_count'];
?>
Nothing more to write now..
Code Snippets, PHP, Tips
php twitter counter, twitter counter
Now a days script driven web applications are getting more and more complicated with background operations and triggered events. Debugging or event tracking is tough once the application is moved into production. Fresh and aspiring programmers are always too cautious to wade into deeper waters, and always go with line by line testing. Almost always in the course of debugging or code optimizations I see a lot of them using file_put_contents or echo to check variables at a particular point of execution.
I always gave the pressure to use a good logging system from the start itself, and to add level based message logging with debug_backtrace wherever needed. The most recent class abstraction for php programmers which is being used in our custom framework is attached to the downloads here. The file logging is being done after serializing, compressing and base64_encoding to keep logs in single lines, and to make sure they dont take up too much of the space.
Read more…
General Articles, PHP, Tips
php command line, php snippets, php wrapper, script logging
Sorry this is nothing related to php, though I wanted to run a cron job or scheduled job at a random time, searching the Internet gave me lots of ideas but I found the apt solution only yesterday.
Read more…
Tips, Uncategorized
cron, shell
This is not much to brag about, still we had a very large dataset as variable dimensional and variable depth, which we wanted to be sent to a custom function using prototype.js. For the data exchange we use JSON, but the varying depth and related tags, made us to do like hell in the javascript templating that we had to find a method to flatten the array in such a way that each of the associative keys would not be mangled.
The final out come is function array_flatten
function array_flatten($p, $ki = ''){
if($ki !== '') $ki .= '-';
$rv = array();
foreach($p as $k => $v){
if(is_array($v))
$rv = array_merge($rv, array_flatten($v, $ki.$k));
else
$rv[$ki . $k] = $v;
}
return $rv;
}
The flattened dataset, helped us to do rendering in less than half the iterations, and the application response was more better after using this.
PHP, Tips
Recent Comments