Sunday, September 6, 2009

Use GMail SMTP to send mail in PHP

An example to use phpmailer class to send email using a gmail account.

$mail = new PHPMailer();
$mail->SMTPAuth   = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // use ssl
$mail->Host = ""; // GMAIL's SMTP server
$mail->Port  = 465; // SMTP port used by GMAIL server
$mail->Username   = ""; // GMAIL username
$mail->Password   = "password"; // GMAIL password
$mail->AddReplyTo("","FirstName LastName"); // Reply email address
$mail->From = "";
$mail->FromName = "FirstName LastName"; // Name to appear once the email is sent
$mail->Subject = "Subject of the email"; // Email's subject
//$mail->Body = "Hello World,<br />This is the HTML BODY<br />"; //HTML Body
$mail->AltBody = "This is a test email"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body); // [optional] Send body email as HTML
$mail->AddAddress("", "Test email");  // email address of recipient
//$mail->AddAttachment("files/"); // [optional] attachment
$mail->IsHTML(true); // [optional] send as HTML
echo "Mailer Error: " . $mail->ErrorInfo;
echo "Message sent!";

Friday, August 14, 2009

Modify PMapper Map File from url

Simply use mapscript to modify the contents from the globals.php after roughly line 60:$map = ms_newMapObj($PM_MAP_FILE);

Documentation on PHP MapScript

Use the following to get capabilities on a WMS

Friday, July 24, 2009

Printing Google Visualization

Google Visualization Api does not provide an api to print them. One way is to convert your codes to Google chart api which renders images.

The other way is to use the following:

Website Thumb Generator can be used to create website thumbnails for your needs, or start your own website thumbnail generation service.

Windows hosting
PHP GD library (installed on most hostings)
Permissions to execute third-party applications (i.e. exe files)
Permissions to execute Internet Explorer

How it works:
Website Thumbnail Generator checks if it already has website image in the cache, and shows it in the browser.
If no cached image then IECapt would be run from the script.
IECapt would run Internet Explorer, grab full sized website screenshot from it, and save image into the folder you specified in script settings.
Then Website Thumbnail Generator would resize image, and show it in the browser.

Download IECapt from Place it in some folder on your server.
Download Website Thumbnail Generator using link below, and unzip it to the same folder.
Update webthumb.php with your settings for thumbnails folder, cache time, default thumbnail size, etc.

Sample usage:

Website Thumbnail Generator

Wednesday, July 22, 2009

JNI example

A simple example of JNI

Java Native Interface (JNI) is a standard programming interface for writing Java native methods and embedding the JVM into native applications. Simply, it is a Java technology with which a Java application can call a method written with such as C, C++ and assembly.

Adopting JNI is very simple. You need two components -- a Java program, and a native library. The native library is written in other languages and compiled on corresonding platforms.

A function defined in the native library should be declared in Java code as a 'native' function. And the native library needs to be load in Java code with the System.loadLibrary method. The natvie function could be referced by other regular functions in the Java code.

Following is an example of the Java Code.

public class JNIFoo {
public native String nativeFoo();

static {

public void print () {
String str = nativeFoo();

public static void main(String[] args) {
(new JNIFoo()).print();

# javac
# javah -jni JNIFoo

A file named as JNIFoo.h is created by running the above two commands. A function of 'JNIEXPORT jstring JNICALL Java_JNIFoo_nativeFoo (JNIEnv *, jobject)' is in the JNIFoo.h file. The function must be implemented in a source code file (e.g. a C file), and it is the actually entry to do what the funtion of natvieFoo() in Java code do.


#include "JNIFoo.h"

JNIEXPORT jstring JNICALL Java_JNIFoo_nativeFoo (JNIEnv *env, jobject obj)
int i;
int ds_ret;

char* newstring;

jstring ret = 0;

newstring = (char*)malloc(30);

if(newstring == NULL)
return ret;

memset(newstring, 0, 30);

newstring = "foo: Test program of JNI.\n";

ret = (*env)->NewStringUTF(env, newstring);


return ret;

JNI libraries are named with the library name used in the System.loadLibrary method of your Java code with a prefix and a suffix. On different OS, the prefix and suffix might be different.

On Solaris OS, it is prefixed by 'lib' and suffixed with '.so'

# cc -Kpic -G -o -I/usr/java/include -I/usr/java/include/solaris foo.c -z text

On Linux OS, it is prefixed by 'lib' and suffixed with '.so'.

# gcc -shared -fpic -o -I/usr/java/include -I/usr/java/include/linux foo.c

On Windows OS, it is prefixed by nothing and suffixed with '.dll'.
It could be compiled with Visual Studio automatically and create a file named as foo.dll.

On Mac OS, it is prefixed by 'lib' and suffixed with '.jnilib'.

# gcc -dynamiclib -o libfoo.jnilib -I/System/Library/Frameworks/JavaVM.framework/Headers foo.c -framework JavaVM

To run the JNI program locally, the following command is fine:

# java -Djava.library.path= JNIFoo

Drupal Anonymous user access denied for view

  • First, enter the following query :

    INSERT INTO node_access VALUES (0, 0, 'all', 1, 0, 0);

    Ignore any error shown.

  • Next, enter the following query:

    update node n set status=1 where nid in (x);

    where x contains all the newly created node is ex: 1,2
  • Thursday, July 16, 2009

    Compile LAPACK and BLAS as DLL on Windows

    BLAS (Basic Linear Algebra Subprograms) is a library that provides standard routines for basic vector and matrix operations.

    LAPACK is a library that provides functions for solving systems of linear equations, matrix factorizations, solving eigenvalue and singular value problems. LAPACK library have dependency to BLAS library because of the LAPACK functions using BLAS functions to work.

    Both of those libraries are written in Fortran77 and no binaries provided for windows. The sources are downloadable from netlib site. So you can compile and use their libraries. However makefile and make solutions for compiling under windows are cumbersome.

    So I recommend compiling directly from the sources using a FORTRAN compiler. There is a free and open source FORTRAN compiler for Windows which is the port of gnu FORTRAN compiler for Windows. You could also use Cygwin and tools in cygwin but your dynamic library loader will have dependency to cygwin dlls. MinGW is a collection of tools that allows you to produce native Windows programs. G77, make, gcc are the common tools provided by Mingw.

    Here are the steps to go to compilation

    • Download most current version of LAPACK from Netlib and extract the sources

    • Download almost all of the Mingw tools and extract the tools

    • Copy dlamch.f and slamch.f from INSTALL directory SRC directory

    • Set path to have mingw binaries

      • set PATH=c:\mingw\bin\;%PATH%

    • Go to root directory of the extracted folder and compile using g77

    • First compile BLAS. –shared option is needed in order to functions to be exposed from the dll. -O generates optimised code. -o filename is the output file

      • g77 –shared -o blas.dll BLAS\SRC\*.f –O

    • Compile LAPACK with BLAS dependency

      • g77 –shared -o lapack.dll src\*.f blas.dll -O

    Here is the output:

    c:\\lapack-3.1.1\\copy INSTALL\\dlamch.f SRC\\dlamch.f
    1 file(s) copied.
    c:\\lapack-3.1.1\\copy INSTALL\\slamch.f SRC\\slamch.f
    1 file(s) copied.
    c:\\lapack-3.1.1\\set PATH=c:\\tools\\mingw\\bin\\;%PATH%

    c:\\lapack-3.1.1\\g77 --shared -o blas.dll BLAS\\SRC\\*.f -O

    c:\\lapack-3.1.1\\g77 --shared -o lapack.dll src\\*.f blas.dll -O

    Hope this helps.

    Wednesday, July 1, 2009

    Google advanced search

    Google advanced search:
    as_q=test (query string)
    &hl=en (language)
    &num=10 (number of results [10,20,30,50,100])
    &as_epq= (complete phrase)
    &as_oq= (at least one)
    &as_eq= (excluding)
    &lr= (language results. [lang_countrycode])
    &as_ft=i (filetype include or exclude. [i,e])
    &as_filetype= (filetype extension)
    &as_qdr=all (date [all,M3,m6,y])
    &as_nlo= (number range, low)
    &as_nhi= (number range, high)
    &as_occt=any (terms occur [any,title,body,url,links])
    &as_dt=i (restrict by domain [i,e])
    &as_sitesearch= (restrict by [site])
    &as_rights= (usage rights [cc_publicdomain,cc_attribute,cc_sharealike,cc_noncommercial,cc_nonderived]
    &safe=images (safesearch [safe=on,images=off])
    &as_rq= (similar pages)
    &as_lq= (pages that link)
    &gl=us (2-digit country code in lowercase)

    Thursday, February 5, 2009

    HTML Map Tag

    Example:An image map, with clickable areas:
    <img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap" />
    <map id ="planetmap" name="planetmap">
    <area shape ="rect" coords ="0,0,82,126" href ="sun.htm" alt="Sun">
    <area shape ="circle" coords ="90,58,3" href ="mercur.htm" alt="Mercury"> <area shape ="circle" coords ="124,58,8" href ="venus.htm" alt="Venus">
    Definition and Usage
    The area tag defines a region in an image map.
    The area element is always nested inside a map tag.
    Browser Support
    The area tag is supported in all major browsers.
    Differences Between HTML and XHTMLIn HTML the tag has no end tag.
    In XHTML the area tag must be properly closed.

    if shape="rect" thencoords="left,top,right,bottom"
    if shape="circ" thencoords="centerx,centery,radius"
    if shape="poly" thencoords="x1,y1,x2,y2,..,xn,yn"

    Sunday, February 1, 2009

    Manually export Printer Drivers

    Open registry and export the following key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3\

    Get the list of files took from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3\\Dependent Files

    Copy them from

    Go to the destination machine and do the reverse tasks.