It is man's ability to remember that sets us apart, we are the only species concerned with the past. Our memories
give us voice, to bear witness to history so that others might learn, so they might celebrate our triumph and be
warned of our failures ...
Filed Under (Facebook) by Abhishek Jain on 22-12-2010
I was recently developing an application for facebook .. and came across an interesting problem ..
Problem:
The values submitted by our users were not being passed on to the next page when the application was being used for the first time.
Reason:
The form had action as “POST”
Explanation:
POST has a life time of a single request after which the values are lost .. now when the user tries using the application for the first time .. and submits the form .. facebook redirects him to the page where he/she has to provide the application access to users data .. on clicking “Allow” .. facebook redirects it to the original “action” mentioned in the form .. however in the process it doesnt forward the POST values submitted .. and hence the values are not available in the next page ..
Solution:
Instead of using POST use GET as action in the form .. this way .. all the form values are passed in the url itself and hence are not lost in the transition ..
Filed Under (PHP) by Abhishek Jain on 25-11-2010
At MyShaadi.in we provide our users with a feature to upload photos in their wedding site.
However our users have been complaining about not being able to upload photos when using Internet Explorer, though the
same image could be uploaded successfully when using Firefox or Chrome . . any non-IE browser for that matter … 
Solution
We check for file type when a user uploads an image .. to ensure only valid image types are uploaded.
In case of non – ie browsers .. for jpeg image file type is “image/jpeg” or “image/jpg” .. for png .. “image/png” ..
However as usual IE decided to not go by the usual way .. and instead of the returning the usual .. returns
“image/pjpeg” and “image/x-png” .. and thats where the culprit was … added these two to the list of valid image
types and things started working again .. 
Below is the code we use to check valid image types ..
function isValidImage($img_type) {
// allowed image types ..
$allowed_img_types = array("JPG","gif","jpg","jpeg","bmp","tif","png","image/jpeg","image/gif",
"image/bmp","image/jpg","image/png","image/x-png","image/pjpeg");
return in_array($img_type, $allowed_img_types);
}
Filed Under (Uncategorized) by Abhishek Jain on 05-08-2010
S3cmd is a command line tool for uploading, retrieving and managing data in Amazon S3. It is best suited for power users who don’t fear command line. It is also ideal for scripts, automated backups triggered from cron, etc.
S3cmd is an open source project available under GNU Public License v2 (GPLv2) and is free for both commercial and private use. You will only have to pay Amazon for using their storage. None of these money go to S3cmd developers.
Mentioned below are the steps to install s3cmd on a shared server.
1. Download s3cmd
2. Copy it to any location on your server
3. Goto to the directory
4. Run python setup.py install –user
–user installs it in the user site-package
‘/home/foo_user/.local/lib/python2.6/site-packages’
5. Add the following to the end of your .bashrc file:
export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH
“$HOME/.local/bin” prepends /home/foo_user/.local/bin to user’s PATH env variable. This variable is searched for directories, in order of occurrence – when executables are looked for.
6. Logout and login
7. Run s3cmd –configure
Update the credentials and you should be good to go.
Filed Under (PHP) by Abhishek Jain on 11-05-2010
<?php
class ImageCreator {
var $ttf_file = "English.ttf";
function createPng($text,$dest_file) {
try {
/*** a new Imagick object ***/
$im = new Imagick();
/*** a new draw object ***/
$draw = new ImagickDraw();
/*** set the font ***/
$draw->setFont($this->ttf_file);
/*** set the font color ***/
$draw->setFillColor(new ImagickPixel("#d4d4d4"));
/*** set the font size ***/
$draw->setFontSize( 40 );
/*** set the box color ***/
$pixel = new ImagickPixel( 'transparent' );
/*** get the font info ***/
$font_info = $im->queryFontMetrics($draw, $text );
/*** the width ***/
$width = $font_info['textWidth']+10;
/*** the height ***/
$height = $font_info['textHeight'];
/*** a new image with the dynamic sizes ***/
$im->newImage($width, $height, $pixel);
/*** annotate the text on the image ***/
$im->annotateImage($draw, 0,27, 0, $text);
/*** set the image format ***/
$im->setImageFormat('png');
/*** write image to disk ***/
$im->writeImage($dest_file);
} catch (Exception $e) {
$this->log($e->getMessage());
}
}
}
Filed Under (Uncategorized) by Abhishek Jain on 01-04-2010
The following three steps should do the job.
Step1
$local> ssh-keygen -t dsa
Step2
upload the ~/.ssh/id_sda.pub to server’s home
Step 3
$server> cat id_dsa.pub >> ~/.ssh/authorized_keys
You should be good to.
Filed Under (PHP) by Abhishek Jain on 29-03-2010
After going through a number of ways to execute a cron job in CakePHP ..
The option below seemed to be the simplest and easiest to execute.
However this would work only on a linux / unix machine and requires lynx be installed in your machine.
lynx –dump http://www.your_domain.com/controller/action/ >/dev/null
So for a cron job:
*/5 * * * * lynx –dump http://www.your_domain.com/controller/action/ > /dev/null
Useful links related to Lynx:
http://en.wikipedia.org/wiki/Lynx_(web_browser)
http://tips.webdesign10.com/general/lynx-browser
Filed Under (Social Media) by Abhishek Jain on 26-03-2010
Facebook has approximately 7,779,180 users in India …
Please note that the data below is approximate.
By Age Group
| Age group – 13-17 |
580,080 |
(7.46 %) |
| Age group – 18-21 |
2,128,660 |
(27.36 %) |
| Age group – 22-25 |
1,948,100 |
(25.04 %) |
| Age group – 26-30 |
1,430,520 |
(18.39 %) |
| Age group – 31-40 |
1,027,180 |
(13.2 %) |
| Age group – 40-64 |
518,520 |
(6.67 %) |
By Gender
| Total male users: 5,248,960 |
| Age group – 13-17 |
345,520 |
(6.58 %) |
| Age group – 18-21 |
1,440,060 |
(27.44 %) |
| Age group – 22-25 |
1,326,660 |
(25.27 %) |
| Age group – 26-30 |
1,000,500 |
(19.06 %) |
| Age group – 31-40 |
708,880 |
(13.51 %) |
| Age group – 40-64 |
350,240 |
(6.67 %) |
|
| Total female users: 2,414,780 |
| Age group – 13-17 |
241,080 |
(9.98 %) |
| Age group – 18-21 |
669,320 |
(27.72 %) |
| Age group – 22-25 |
602,280 |
(24.94 %) |
| Age group – 26-30 |
401,720 |
(16.64 %) |
| Age group – 31-40 |
297,040 |
(12.3 %) |
| Age group – 41-64 |
153,240 |
(6.35 %) |
| Number of users who are single |
2,088,880 |
(26.85 %) |
| Number of users who are engaged |
52,300 |
(0.67 %) |
| Number of users who are in a relationship |
181,020 |
(2.33 %) |
| Number of users who are married |
647,140 |
(8.32 %) |
|
|
 
Filed Under (PHP) by Abhishek Jain on 03-03-2010
Features
- tab-completion (if readline() support is compiled into php)
- handles FATAL errors (like calling a undefined function)
- inline help
- autoload() is enabled by default
- works on all php platforms (shell wrappers for Unix and Windows)
Complete Article : http://jan.kneschke.de/projects/php-shell/
Filed Under (PHP) by Abhishek Jain on 07-09-2009
Interestingly enough, the developers over at CakePHP incorporated this little interesting tidbit: any variable set for your view with a name ending in “_for_layout” automatically gets passed into the layout.
Here’s a little example:
//in my controller
$this->set(‘var_for_layout’,$value);
Source:
http://kushaura.com/blog/view/name:Passing-Parameters-Into-Your-Layouts-in-CakePHP
Filed Under (PHP) by Abhishek Jain on 18-07-2009
What if you want a feature like twitter in your site .. twitter.com/username .. redirects you to the profile page of the user.
Usually Apache would consider “username” to be a folder under the root folder and try opening its index page. Thats not what we intend to do .. create a folder and its index page for each user .. doesnt make sense.
That’s where URL rewriting in Apache comes to the rescue and turns out its pretty simple to achieve this.
Assumption: Basic knowledge of Regular Expressions.
The Apache server’s mod_rewrite module gives you the ability to transparently redirect one URL to another,
with / without the user’s knowledge.
Lets see how do we go about it.
Some servers will not have » mod_rewrite enabled by default. As long as the » module is present in the installation,you can enable it simply by starting a .htaccess file with the command
RewriteEngine
Put this .htaccess file in your root so that rewriting is enabled throughout your site. You only need to write this line once per .htaccess file.
This is how the rule will look like in the .htaccess file
RewriteEngine on
RewriteRule ^/([A-Z][a-z][0-9][0-9])*$ /users/view_profile.php?username=$1
This rule wouldn’t change the url in the address bar, keeping the redirection hidden from the user. In case you want that add a [R] at the end of the rule
RewriteEngine on
RewriteRule ^/([A-Z][a-z][0-9][0-9])*$ /users/view_profile.php?username=$1 [R]
Note that it is also possible to chain rules and they will be executed in the same sequence as mentioned in .htaccess file.
One of the things to note here is that there would be cases where “string” in “xyz.com/string” would be a valid folder name under the root directory and not “username”. These cases would have to be handled in the view_profile.php page. There could be multiple ways to do it, which i will leave upto you to decide.
Another situation where the url rewriting thing can be used is when you have moved a page and the user is not aware of the change. You dont want to show him a 404 page (that scares people ). Use this to redirect him to the new page.
RewriteEngine on
RewriteRule ^old\.php$ new.php
|
|