24.4.09

Upgraded to Jaunty Jackalope

Wow! I just installed Ubuntu 9.04 Jaunty Jackalope and was really amazed on how fast the thing booted up.

Also, the install experience was really really nice. I just went through 7 steps and after a restart, here I am.

Try it now. It's very stable, so far so good, considering that I already "hacked" the system compiling things that I have had in the last linux that I used.

Peace!

12.3.09

Adding gmail SMTP to symfony 1.0

PHPMailer is already included in symfony, so why add one yourself?

The thing is, I never get PHPMailer that is bundled with symfony to work with my gmail account so I decided to find something that can be done.

1.) Create a file myMailer.class.php inside your lib directory (either in apps/app_name/lib or in your root lib directory)
2.) Put these codes in there:


class myMailer {

public function __construct($username, $password, $user_alias) {
$this->from = $username;
$this->password = $password;
$this->user_alias = $user_alias;
}

public function send($to, $subject, $body) {

$eol = "\r\n";
$host = 'gmail-smtp.l.google.com';
$port = 465; $fname = $this->user_alias;
$data = 'Date: ' . date ( 'r', time () ) . $eol;
$data .= 'From: "' . $this->from . $eol;
$data .= 'Subject: ' . $subject . $eol;
$data .= 'To: "' . $to . '" <' . $to . '>' .
$eol; $data .= 'X-Priority: 1 (High)' . $eol;
// you can comment this one out if you want a normal email.
$data .= 'X-Mailer: ' . $eol;
$data .= 'MIME-Version: 1.0' . $eol;
$data .= 'Content-Type: text/plain; charset="ISO-8859-1"' . $eol;
$data .= 'Content-Transfer-Encoding: 8bit' . $eol . $eol;
$data .= $body . $eol;

$has_error = false;
if ( ( $smtp = fsockopen ( 'ssl://' . $host, $port, $errno, $errstr, 5 ) ) ) {
fputs ( $smtp, 'HELO ' . $host . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) { $
has_error = true;
}
sleep(2);
fputs ( $smtp, 'AUTH LOGIN' . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
sleep(2);
fputs ( $smtp, base64_encode ( $this->from ) . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
sleep(2);
fputs ( $smtp, base64_encode ( $this->password ) . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
sleep(2);
fputs ( $smtp, 'MAIL From: <' . $this->from . '>' . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
} sleep(2);
fputs ( $smtp, 'RCPT To: <' . $to . '>' . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
sleep(2);
fputs ( $smtp, 'DATA' . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
sleep(2);
fputs ( $smtp, $data . $eol . '.' . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
sleep(2);
fputs ( $smtp, 'QUIT' . $eol );
if ( ! $this->test_return ( $smtp, $error ) ) {
$has_error = true;
}
fclose ( $smtp );
}
return !$has_error;
}

function test_return ( $res, &$error ) {
$out = fread ( $res, 1 );
$len = socket_get_status ( $res );
if ( $len > 0 ) {
$out .= fread ( $res, $len['unread_bytes'] );
}

//echo $out;
if ( preg_match ( "/^5/", $out ) ) {
$error = $out;
return false;
}
return true;
}

}


3.) In your controller, you can now use it this way:

$mail = myMailer(“username@gmail.com”, “thisshouldbeaveryhardpassword!@#$!@#$!@#$”, “From Me!”);
if($mail->send(“spam_victim@somewhere.com”, “This Is Spam”, “<div style=’font-size:300px’>GET THIS</div>”)) echo “Mail Sent!”;
else echo “Mail is not sent!”;


And you’re done!

8.3.09

Sending HTTP Posts through JAVA

I found this truly helpful tip :D

http://www.javaworld.com/javatips/jw-javatip34.html?page=1

From the site:

    URL              url;
    URLConnection   urlConn;
    DataOutputStream    printout;
    DataInputStream     input;
    // URL of CGI-Bin script.
    url = new URL (getCodeBase().toString() + "env.tcgi");
    // URL connection channel.
    urlConn = url.openConnection();
    // Let the run-time system (RTS) know that we want input.
    urlConn.setDoInput (true);
    // Let the RTS know that we want to do output.
    urlConn.setDoOutput (true);
    // No caching, we want the real thing.
    urlConn.setUseCaches (false);
    // Specify the content type.
    urlConn.setRequestProperty
    ("Content-Type", "application/x-www-form-urlencoded");
    // Send POST output.
    printout = new DataOutputStream (urlConn.getOutputStream ());
    String content =
    "name=" + URLEncoder.encode ("Buford Early") +
    "&email=" + URLEncoder.encode ("buford@known-space.com");
    printout.writeBytes (content);
    printout.flush ();
    printout.close ();
    // Get response data.
    input = new DataInputStream (urlConn.getInputStream ());
    String str;
    while (null != ((str = input.readLine())))
    {
    System.out.println (str);
    textArea.appendText (str + "\n");
    }
    input.close ();



Thanks to the person who posted this :D

11.2.09

Signing Jar Files

Compared to most Java programmers, I can still call myself a newbie.

I just learned how to sign java jars to be able to maximize the potential of applets.

1.) First of all you need to create your keystore. A keystore file (usually named .keystore in your home directory) contains your private and public keys. .keystore is stored in a binary jks format (Java Key Store) similar to PKCS #12 containing both public and private keys, protected by a passphrase. The first four signature bytes of a Sun .keystore file in hex are FEEDFEED. ( http://mindprod.com/jgloss/keystore.html)

    To create your keystore, you need the keytool which you can get with most java jdk. At the command line, you type something:

    keytool –genkey –alias alias_to_be_used

    you need to specify alias_to_be_used as this will be the alias that you will be using for the jarsigner command later.

2.) You can save your .keystore file if you are going to transfer to other machines or reformat the machine that you are going to be using. You just have to remember to put it at your home directory.

3.) You can now create your jar file. After which you can issue the command:

    jarsigner –storepass yourpassword –keypass yourpassword jarfile.jar alias_to_be_used

     you have to specify yourpassword for both the storepass and keypass as they could be different passwords (as you will be prompted in the keytool to be able to do so). Also don’t forget to change jarfile.jar for the filename of your jarfile and alias_to_be_used for the alias you supplied to keytool.

4.) That’s it you have a jar signed file.

Enough for now, back to work...

3.2.09

Now: Java

Hi,

It's been a while since I posted here and a lot of things happened already. Tonight, I will be posting of a different thing as I have been re-learning JAVA. Yes, the old programming paradigm that I once rubbed off my shoulder was once again at the doorsteps, knocking at ME to learn about it.

Now that JAVA is OpenSource, I am still a bit skeptic about what can be done with it.

There must be a reason why I am now shifting most of my time to JAVA and not with Python,PHP and C++ which is what I commonly use.

Just to keep you hanging and of course, not to spoil the company's plan, I would not discuss the details of what I have been doing the last 2 months. I have a month more of development for this so I'm going to keep my fingers shut until it is the time to divulge the great secret.

After which, I will be blogging about the pain, the hardships and all the fuzz that happened before, during and after development.

Thanks for reading.

14.1.09

Installing APACHE 2.2, PHP 5.2 and MySQL on Windows XP that works

1.) Get apache 2.2 from http://httpd.apache.org I prefer that you download the one with ssl
2.) Next, get PHP from http://ph.php.net/get/php-5.2.8-Win32.zip/from/a/mirror. I am downloading PHP 5.2.8.8 windows binaries in ZIP file not the installer
3.) Next get mysql from http://dev.mysql.com/downloads I got mysql 5.1 community edition essentials
4.) wait for them to finish
5.) Install apache normally first. I installed mine on C:\apache you can use the default
6.) Next install MySQL you would want to configure the root password
7.) extract PHP somewhere, I did mine in C:\PHP
8.) add this to httpd.conf that is in C:\apache\conf:

LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php

PHPIniDir "C:/php"

9.) restart apache
10.) create this as index.php in your C:\apache\htdocs folder:

phpinfo();
?>

11.) open a browser and point to: http://localhost/index.php
12.) in the line: Loaded Configuration File you will find that there is none loaded so in your c:\php directory rename php.ini-recommended to php.ini. open the file and uncomment the line extension=php_mysql.dll it's around line 681. also, don't forget to change the extension_dir around line 542 to read :

extension_dir="C:/php/ext"

13.) restart apache again
14.) check again http://localhost/index.php as you can see, mysql is not included in there.
15.) to enable mysql in php:
I. copy the file libmysql.dll from the directory where you install mysql usually in C:\Program Files\MySQL
to C:\php
II. you need to put mysql's bin path to the PATH environment variable the same with C:\php
III. at this point you need to restart
IV. check again at http://localhost/index.php and you should see mysql already there
16.) Edit again c:\apache\conf\httpd.conf the line:
DirectoryIndex index.html
should now read:
DirectoryIndex index.php index.html

17.) Restart apache and now you are done!

10.11.08

Science Centrum is back!

It's nice to hear that our beloved Philippine Science Centrum can once again be experienced by everyone! Yes. The Science Centrum that we grew up with, enjoyed and the one that sparked our CURIOSITIES is relived, albeit in another place. You can check the link ( http://www.science-centrum.ph/ ) and it would be much better if you can experience it for yourself!

The Philippine Science Centrum, now in Marikina Riverside, will be opened to public on November 22, 2008. I will be there, my wife will be there, hopefully, I can see all of you there also!

We really are winners of cosmic lottery...

6.11.08

Recovering lost network connection on VMWARE Image

I found this really helpful! Thanks to the author. VMWare is cool! (http://www.vmware.com). Qemu is cool too! (http://www.qemu.com)