Wednesday, March 25, 2009

Google Docs Security Problem Solved

I am a fan of Google Docs(beta). When I was trying to find out templates on Google Docs, I felt that I got the private spreadsheet of someone. I searched for this issue on the internet but did not find a satisfied answer. Yesterday, I found the following link. Google had admitted this security problem but I think the problem has been solved.


http://www.pcworld.com/article/160927/google_docs_glitch_exposes_private_files.html

on Wikipedia

http://en.wikipedia.org/wiki/Google_docs#Data_safety_and_privacy

Friday, March 20, 2009

Search Your Network Game Using PHP

Search games on your network, simply using PHP. This script uses a cool module of PEAR, Net_GameServerQuery- a common API to query Half Life server. PEAR () is a framework and distribution system for reusable PHP components. You need to install PEAR module Net_GameServerQuery on your PHP installation.
First change configuration to match your game server. Set IP address ( $ip ) and game type ( $protocol ) variables.



Note: Click on image for clear view.

Thursday, March 19, 2009

JAVA connection with MySQL using JDBC in Eclipse

We will discuss JAVA-MySQL connection using JDBC (Java Database Connectivity)

JDBC:

JDBC is a standard API that allows JAVA programs to access databases. The JDBC API is a collection of interfaces and classes written in the JAVA Programming Language. We can write applications that connect to databases, send SQL queries, and get the results using these standard interfaces and classes.

A JDBC driver implements these interfaces and classes for a particular Database Management System. A Java Code loads the specified driver for a particular DBMS before it establish a connection with a database.


Download JDBC Driver:


First of all you have to download JDBC driver (usually named mysql-connector-java-version).
For Example: http://ftp.fju.edu.tw/Database/MySQL/Downloads/Connector-J/

Extract downloaded zip file and copy extracted folder to your plugins folder in Eclipse Directory.
For Example: C:\Eclipse\plugins\mysql-connector-java-version


Import JDBC Driver in Eclipse.


1. Right Click on your Project in Eclipse -> Select Properties.
2. Select Java Build Path->selcect Libraries tab->press Add External JARs button.
3. Select mysql-connector-java-version-bin file from downloaded mysql-connector-java-version folder.

Done. Now you are ready to establish JAVA-MySQL connection.


JAVA Code Example:

For Example we have a database named “riksof” with a table employees(id,name,email,designation) where “id” is primary key and auto_increment.



/*Define a connection url*/
String host = "localhost";
String db = "riksof";
String tb = "employees";
String db_user = "dbuser";
String db_pw = "dbpassword";

String db_url = "jdbc:mysql://"+host+":3306/"+db+"?user="+db_user+"&password="+db_pw;

Connection conn = null;
Statement stmt = null;
String query = "";
ResultSet result = null;
PreparedStatement ps = null;



/* Load driver and Establish a connection */
try{
conn = DriverManager.getConnection (db_url , db_user , db_pw);
stmt = conn.createStatement();
}catch(Exception connectionExp){
System.out.println("SQL Connection not Established: " + connectionExp.getMessage());
}

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(Exception driverExp){
System.out.println("Driver not Found : " + driverExp.getMessage());
}



/* Now Display all records */
query = "SELECT * FROM " + tb;
try{
result = stmt.executeQuery(query);

while(result.next()){
System.out.println(result.getString("id"));
System.out.println(result.getString("name"));
System.out.println(result.getString("email"));
System.out.println(result.getString("designation"));
System.out.println("-------------------------------");
}
}
catch(Exception sqlExp){
System.out.println("SQL Exception: " + sqlExp);
}



/*Insert a single record*/
query = "INSERT INTO employees(name,email,designation) VALUES('Name','Email','Designation')";

try{
conn.createStatement().executeUpdate(query);
System.out.println("Record Stored.");
}
catch (SQLException insertExp) {
System.out.println("SQLException Caught: " + insertExp.getMessage());
}

Google Special Syntaxes

In the era when people go online before the morning tea, Google search engine is an essential part in our everyday life.
Being a full-text search engine Google indexed entire website instead of title, links and description. Google search engine support Boolean operators, basic AND, OR, and quoted strings, as well as it offers special syntax for quick and precise query. Here are some of the common syntax which are very useful for professional peoples;

intitle:
intitle: search is restricted to page titles
intitle:"pakistan"
allintitle:"kashmir dispute" pakistan

inurl:
inurl: search is restricted to URLs.
inurl:view.shtml
allinurl:search help

intext:
intext: searches only body text
intext:"riksof.com"

inanchor:
inanchor: searches for text in a page's link anchors.
inanchor:"university"

site:
site: search by either a web site or a top-level domain.
site:gov
site:pk
site:edu.pk

link:
link: gives a list of pages linking to the particular URL.
link:www.riksof.com

cache:
cache: find copy from Goolge indexed cache even it is no longer available at its original location.
cache:www.amazon.com

daterange:
daterange: limits your search to a particular date or range of dates that a page was
indexed.
Note that daterange: works with Julian, not Gregorian dates (the
calendar we use every day).
"Osama Bin Laden" daterange:2452389-2452389
Aerospace daterange:2452389-2452389

filetype:
filetype: searches the suffixes or file extensions.
java filetype:pdf
"marketing" filetype:ppt

related:
related: finds pages that are related to the specified page.
related:www.ebay.com
related:www.cricinfo.com

info:
info: provides a page of links to more information about a specified URL.
info:www.wikipedia.com

phonebook: //not very useful for Pakistan
phonebook: phone number looks up.
phonebook: Karachi

There are still more syntax for easy, precise and rapid search and Google is adding more day by day.

Wednesday, March 18, 2009

PHP Image Gallery & Truncate a string in Smarty

PHP Image Gallery
Description:

This is an image gallery script that allows you to simply upload new full sized images in FTP and the script will automatically create the thumbnails for those images and add those images to a paged thumbnail gallery suitable for browsing.

Instructions:
First of you have to set the variables in the code below.
  1. Scroll down to about line 30 and look for $config['size']. Set this to the maximum width or height you want your image thumbnail to be.
  2. On the next line in the $config['imagequality'] set this to the JPEG quality you would like your thumbnails to be. I recommend you keep it set to 70.
  3. $config['rows'] and $config['cols'] are the number of rows and number of columns of thumbnail images you want shown on each page.
  4. $config['maxShow'] is the number of page numbers to show at one time. for instance if you have 100 pages of images, you can set this to only show the page numbers of the 10 pages close to where you currently are.
  5. $config['thumbs'] is the relative path to where you want the thumbnail images to be stored. Include the trailing slash.

File Permissions:

  1. You'll need to change the permission on the directory you set $config['thumbs'] to. CHMOD it to 775 or 777 so PHP and GD2 can automatically write and create your thumbnails in that directory.

Changing the Look:

  1. The entire gallery table is controlled by the CSS settings you'll find toward the bottom of the gallery.php file. I tried to comment each specific part of the CSS and what it controls so you can easily change the look of the gallery without actually having to actually edit any of the PHP.

Here is the Code:

You can download the gallery.php file from the following link.

http://www.ricocheting.com/scripts/gallery.html

Truncate a string in Smarty

Suppose you have a sentense in smarty that contains more characters and the rows of the table where you wants to show it will become wrap which sounds very bad. So you can use smarty variable modifier called 'truncate'.

How to use Truncate:

It has following syntaxes,
truncate:how_many_characters_to_show:what_characters_appear_at_end
truncate:int:int
lets,
$yourString = "Hello World";
  1. {$yourString|truncate}//output// Hello World
  2. {$articleTitle|truncate:3}//output// Hel...
  3. {$articleTitle|truncate:3:""}//output// Hel
  4. {$articleTitle|truncate:3:"---"}//output// Hel---
You can also find more detail from
http://www.smarty.net/manual/en/language.modifier.truncate.php
Special Thanks:
Ihsanuilah Khan