After reading Using MySQL as a filesystem, by Ben Martin @ linux.com, I had been pondering over the idea for a long time. And a couple of sleepless nights, the base for phpmyfs, a mysql file storage engine using php at the front end is almost ready. This is not yet production ready, though the image, or media management part is upto my expectations. Continue reading “MySQL FileSystem – A PHP Implementaion”
Category: Code Snippets
Short code fragments for different occassions
Paged Navigation – My own way
Recently while working for a wordpress plugin, though there are a lot of solutions for this, I could not find the exact thing which I needed, and thought about writing one of my own. Just writing it and using in the current project would be a waste, so thought I would slap it on here. It would help me in the long run.. Continue reading “Paged Navigation – My own way”
Fun digging into WordPress XML RPC
Once we achieved 20K visits per day at asianetindia.com (maintained by Saturn SPL), we planned to hammer in and our target was 30k in three months. We have achived that view the stats. For this twitter and blog helped a lot. We had added auto blogging, and wordtwit both to the existing asianetindia.com. It means each post when published will be tweeted, as well as a post to blog, which contains the excerpt with a back link to the original.
We wanted to get maximum links back into the blog also, and thought that a track back would be the best method and choose that against auto commenting systems. And a full time tester was doing linking related news and posts from other sites to our blog posts. It started to turn tiring when thought of the volume that was getting posted in a day. At this point, we at saturn started to think of automating the linking drive. The out come is autolinker, which is run using the random cron.
Continue reading “Fun digging into WordPress XML RPC”
Binary tree in MySQL for MLM
Recently for a student, I was asked to explain the design considerations of a Binary Tree which was to be used in an MLM solution. About 10 years back it was a nightmare, and in my career, I was lucky to get that privilage for more than a dozen times with varying schemes and structures. But now with MySQL having procedures, and functions, the tree design and related functions were a breze. Reproducing it here for future reference. This is in no way a complete solution, but just bits and pieces which may even be discarded as crap.
CREATE TABLE `binTree` ( `nodeid` int(10) unsigned NOT NULL auto_increment, `lnode` int(10) unsigned NOT NULL default '0', `rnode` int(10) unsigned NOT NULL default '0', `pnode` int(10) unsigned NOT NULL default '0', `pside` enum('l','r') NOT NULL default 'l', `tLevel` int(10) unsigned NOT NULL default '1', PRIMARY KEY (`nodeid`), KEY `parent` (`pnode`), KEY `treelevel` (`tLevel`), KEY `lside` (`lnode`), KEY `rside` (`rnode`) ) ENGINE=MyISAM;
The above is the basic structure of the tree table, and some complementary functions and procedures are accompanied to make the usage simple, otherwise would be a herculian task for the developer to do the same.
Continue reading “Binary tree in MySQL for MLM”
Threading PHP scripts using OS facilities
Recently while developing systems which consumes webservices, after a lot of optimizations were put into our code, we resorted to do some sort of benchmarking. From the begenning itself, we had proper loggers which were logging the activities to database tables, and verbose text files. For benchmarking of the systems we use xdebug, and our Open PHP Myprofiler. The code coverage analysis by xdebug, as well as cache grind showed our bottleneck was our webservice provider. While checking out, we also found that we could reduce the waiting time for webservices by requesting smaller data set from the webservice.
Continue reading “Threading PHP scripts using OS facilities”
Prototype based date picker
We had started optimizing drive for the projects of Reserway Technologies, and the work being done on the demo site. For the initial prototype, we used a dual datepicker developed in flex, which interacts with the html using javascript calls. We used this because the component was already available, and just adding a couple of handlers could do our job, and we could concentrate more on the abstraction of GDS integration. Well we are in a state where the backend is almost stable and we need more performance drive on the frontend. The first choice was ofcouse linking the libraries to google cdn. Then started cutting the curves. The biggest bottleneck was the whopping 220Kb for the flash control. I was particular to use a simple datepicker, which could be styled using css, and would be better if used the prototype library.
Continue reading “Prototype based date picker”
Using TagTheNet to generate tags on WordPress
Recently on Kerala News by Asianet, though the wp-simple-tags was there, the posts were not being tagged automatically. And on a detailed check I found it was due to a misconfiguration, and once the same was done properly the tagging started smoothly. But already a set of 8K posts were there with no or unrelated tags mistakes and un awareness of the operators who were posting to the site. Now I wanted these to be tagged properly.
I had already used the word-twit plugin and done some mods to the same, so it was more eaiser for me. Just went through the original code of word-twit and salvaged a small script which is attached here with as download.
require_once( dirname(__FILE__) . '/wp-load.php' );
The code above loads the wordpress system and initializes the wp variables and connects to the database.
global $wpdb;
Makesure we have the database abstraction object from wordpress, to select the posts, and do all the required manipulations on the same.
require_once( ABSPATH . 'wp-includes/class-snoopy.php' );
Include the inbuilt snoopy class, to mimic a web browser with the most simplicity.
Continue reading “Using TagTheNet to generate tags on WordPress”
Annoying php error related to headers
Cannot modify header information – headers already sent by (output started at /path/to/the/php/file.php:line) in /path/to/the/php/file.php on line newline
Okay the normal case would be to check the file thouroghly and make sure there is nothing that is outputted at the specified line number. But what if the line is pointing to the first line in the current file, and there is nothing visible, well the culprit may be a windows based editing software which converted the php file into UTF-8.
So the file encoding may destroy the php script. Changin the encoding back to ANSI would clear the problem.
WordTwit – just finished integrating to a couple of my wordpress sites
I have just finished integrating wordtwit to asianetindia.com as well as this blog. There is nothing much to hoot and howl about it, other than I just made some tweaks here and there. One being the addition of auto hash tagging for twitter with the help of tag the net. And another one to replace the url compression with a similar service which I started just on a fancy, also I replaced those since I was not interested in retaining the included small url options.
While working for the auto hash tagging, I found that the function twit_hit_server, near about line 215, was not updating the $output variable, with the results in case the method was post, so I just added that $output = $snoopy->results; to the conditions inside if ($post) / if ($result).
Then changed
$message = str_replace( '[title]', get_the_title(), $message );
to
$message = str_replace( '[title]', wordtwit_tagify_title(get_the_title()), $message );
inside the function post_now_published definition.
The code listing for wordtwit_tagify_title is
function wordtwit_tagify_title($text){
$output = '';
if(strlen($text) > 110) $text = substr($text, 0, 100) . ' ...';
twit_hit_server( 'https://tagthe.net/api/', '', '', $output, true, array( 'text' => $text, 'view' => 'json' ) );
$res = @json_decode($output);
if(!isset($res->memes[0]->dimensions->topic[0]))
return $text;
$topTag = $res->memes[0]->dimensions->topic[0];
$g = strpos($text, $topTag);
return substr($text, 0, $g) . '#' . substr($text, $g);
}
WordTwit is a plugin that utilizes the Twitter API to automatically push a published post to your Twitter account as a tweet. It allows all your Twitter contacts to keep up to date with your blog postings.
MySQL UDF – the first taste
Recently for Saturn SPL, as part of a prototype discussion, I was considering a fam based trigger for a process queue. We were already familiar with queueing processes in a mysql table, with auto_increment primary key, this should not be a problem. But when the number of processes increase, the table size too increases and finally we will be forced to remove those already processed. Also more than this, we wanted the table to me as compact as possible, meanwhile should be as accurate as possible. MySQL could not (AFAIK) stamp rows with mico seconds.
Continue reading “MySQL UDF – the first taste”