Get popup center

function get_popup_center(popurl)

var top = (screen.availHeight/2)-61;
var left = (screen.availWidth/2)-150;
var width = 300;
var height = 150;
//var popurl = ‘’;

var oWin = popUp(popurl, top, left, width, height);


function popUp(URL, top, left, width, height)
day = new Date();
id = day.getTime();

eval(“page” + id + ” =‘”+URL+”‘, ‘” + id + “‘,’toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=”+width+”,
return “page” + id;

focus password element from password to ********

*  <form>
*  <input type=”text” name=”password” value=”Password” onfocus=”get_password_focus(this)”>
*  </form>
*  This function can be used for focus password element from password to ********

function password_focus(obj)
var newO=document.createElement(‘input’);

Protect website folders by .htaccess

<IfModule dir_module>
DirectoryIndex index.html index.php index.php4 index.php3 index.cgi index.htm index.shtml index.phtml

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_URI} !(css)
RewriteCond %{REQUEST_URI} !(js)
RewriteCond %{REQUEST_URI} !(images)
RewriteCond %{REQUEST_URI} !(videos)
RewriteCond %{REQUEST_URI} !(cache)



pdftohtml converters  PDF documents into HTML format, which is more suitable for Internet publishing. The converter produces HTML documents with texts, pictures, graphics and bookmarks.

pdftohtml software does not require Adobe Acrobat, or even Acrobat Reader.

Install pdftohtml on Fedora/Linux:

# yum install pdftohtml
# which pdftohtml

Usage: pdftohtml [Option] <PDF File> [<HTM File>]


pdftk – fedora – merge pdf files

Pdftk allows to manipulate PDF easily and freely. It does not require Acrobat, and it runs on Windows, Linux, Mac OS X, FreeBSD and Solaris etc.


  • Merge PDF Documents
  • Split PDF Pages into a New Document
  • Rotate PDF Pages or Documents
  • Decrypt Input as Necessary (Password Required)
  • Encrypt Output as Desired
  • Fill PDF Forms with FDF Data or XFDF Data and/or Flatten Forms
  • Apply a Background Watermark or a Foreground Stamp
  • Report on PDF Metrics such as Metadata, Bookmarks, and Page Labels
  • Update PDF Metadata
  • Attach Files to PDF Pages or the PDF Document
  • Unpack PDF Attachments
  • Burst a PDF Document into Single Pages
  • Uncompress and Re-Compress Page Streams
  • Repair Corrupted PDF (Where Possible)

Install pdftk on fedora/linux:

# yum install pdftk
# which pdftk

Merge Two or More PDFs into a New Document
# pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

Resume Builder pdf2txt, word2txt

Reading PDF Files

XPDF package includes “pdftotext.” You have to install XPDF/pdftotext then run the following PHP statement to get the PDF text:

$txtcontent = exec('/usr/local/bin/pdftotext svnlabs.pdf -');

Reading DOC Files

This package is called Antiword. Here’s the PHP code to grab the Word DOC content:

$txtcontent = exec('/usr/local/bin/antiword svnlabs.doc');

Configure Amazon EC2

1.Boot 2 linux servers on EC2
2.Assign elastic IP to each of them
3.Register a domain (eg
4.On the domain settings – create 2 host records – and and point each record to each of the elastic IPs.
5.On your 2 nameserver instances – create dns zone for ns1. and ns2 respectively
6.Make ns2 a slave of ns1 – you can if you wish add ns3… ns4.. etc etc but its not necessary unless your site is getting millions of users.
7.Boot another EC instance and install the Scalr application.
8.Create a user on ns1. called “named” that has permissions to update the dns zone records on ns1.
9.The DNS settings of the scalr application will refer to the nameservers ns1. with user “named” and password as set on ns1.
10.Your application for example will have the domain  Register this domain and set its nameservers to your ns1. and ns2 mentioned previously.
11.You need to first create a new zone file on ns1 for
12.In Scalr when asked for the application domain name – simply enter – and scalr will handle the rest.


You will need to register a domain name with a domain registrar.  After registering, you will need to enter your NS records for the domain name.  The NS records should point to a Domain Name Server (DNS).  Most registrars require at least two DNS servers to eliminate a single point of failure.

Some registrars provide free DNS services.  If you choose such a registrar, you would need to add a CNAME record for your sub-domain and ask any DNS application support related questions to your registrar.

Alternatively, you can launch and configure your own DNS servers on Amazon EC2.  A popular choice for Linux based DNS servers is BIND:

Another option is to outsource your DNS servers using a third-party provider, for example


Mysql useful queries

Select DATE_FORMAT (NOW(), ‘%Y’) – DATE_FORMAT(BirthDate, ‘%Y’) – (DATE_FORMAT(NOW(), ’00-%m-%d’) < DATE_FORMAT(BirthDate, ’00-%m-%d’)) AS Age From tbl_member where 1;

Change collation:

Alter table `tbl_student` convert to character set utf8 collate utf8_swedish_ci;

Shift mysql column:

ALTER TABLE tableName MODIFY column column_2 int AFTER column_1;

Get video info with user info:
SELECT `video_id` , `video_title` ,
( SELECT userid FROM tbl_members
WHERE `member_id` = v.member_id
) AS owner
FROM `tbl_video` AS v

Select concat(a.Day,’_’,a.Hour) as IDX From tbl_time;

Switch Case:
SELECT, a.group_name ,
WHEN a.is_feature= ‘t’ THEN ‘Featured’
ELSE ‘Unfeatured’
END as Featured
FROM `tbl_member_groups` a;

2 Way Friendship:
SELECT CASE WHEN mf.member_id = ‘”78″
THEN mf.friend_id
ELSE mf.member_id
END AS f_id,
FROM tbl_member
WHERE mid = f_id
) AS uname
FROM tbl_member_friend AS mfWHERE ( member_id = ’78’ OR friend_id = ’78’ ) AND is_accepted = ‘t’;

SELECT b.ID as us_id,c.ID as ctu,c.Nationality,e.Name as cname, b.Username, d.Name FROM user b
LEFT JOIN teacher c ON b.ID = c.UserID
LEFT JOIN teacher_photo d ON c.ID = d.TeacherID
LEFT JOIN country e on e.ID=c.Nationality
IN ( SELECT CASE WHEN tf.user_id = ‘$ID’
THEN tf.friend_id
ELSE tf.user_id
END AS f_id
FROM friend tf
user_id = ‘$ID’
OR friend_id = ‘$ID’
AND tf.`is_accept` = ‘t’ order by tf.date_added desc

SELECT a. * , c.Nationality, e.Name AS cname, b.Username, d.Name
FROM forum_reply a
LEFT JOIN user b ON a.poster_thread_id = b.ID
LEFT JOIN teacher c ON a.poster_thread_id = c.UserID
AND b.ID = c.UserID
LEFT JOIN teacher_photo d ON c.ID = d.TeacherID
LEFT JOIN country e ON e.ID = c.Nationality
WHERE a.thread_id = ‘1’;

Remove duplicate records:
SELECT * FROM old_table WHERE 1 GROUP BY [COLUMN TO remove duplicates BY];

Stored Porcedures:
CREATE PROCEDURE simpleproc (OUT param1 INT)
SELECT * FROM testimonial;
CALL simpleproc(@a);

SQL Injection:
Select * from tbl_user where name = ‘sandeep’ OR ‘1’ = ‘1’;

Insert Duplicate:
INSERT INTO `teacher_photo` SET TeacherID =7, Name = ‘7-teacher.jpeg’,
FileType = ‘image/jpeg’ ON DUPLICATE KEY UPDATE Name = ‘7-teacher.jpeg’, FileType = ‘image/jpeg’;

Reporting month year wise:
Select count(hits), month(add_date) m, year(add_date) y From ‘sales’ where 1 group by m,y;

Interchange columns values:
Update userinfo set sex = case
when sex = ‘f’ then m
when sex = ‘m’ then f

Case sensitive data:
Select * From member where BINARY uname = “sandeep”;

Get third max mark holder:
Select * From ‘marks’ where 1 order by mark desc limit 2,1;

Get duplicate in table:
Select title From ‘books’ group by title having count(*) > 1;

Set Character set to UTF-8:
SET NAMES ‘utf8’;

Check for Online:
FROM tbl_member_groups