This is my post about XML transformer. A PEAR extension that could work just great (apparently) in creating custom PHP tags. Here in this post I'll discuss my greviances in trying to deploy this.
Firstly, I wanted to install this. There was a catch here. I didn't want to do a normal PEAR installation, because it looked rather cumbersome and I wasn't in a mood to try out all the commands. So I copied the files and placed it in a new folder called XML. (This is only for XML_Transfermer though). The heirarchy was something like:
XML
- transformer.php
- util.php
/ transformer
/ and all other XML folders.
Now all I had to do was:
set_include_path('.'.PATH_SEPARATOR.'../'.PATH_SEPARATOR.'/AppServ/www/tmp/lib');
?>
This would set an additional include path to /lib which contained /XML. So far so god. I took nearly an hour to figure this out.
Now I was stuck with a mega huge problem of 'how the hell do I get this to work'. There is so little documentation available about XML_Transformer on the internet that its really bad. So I have decided to create a documentation of XML_transformer once I actually understand how to get it to work...
June 24, 2009
June 08, 2009
.NET and PHP
So I have experienced a lot of PHP and a lot more of .NET lately. And what do you know... they are now being packaged together by Microsoft. Those microsoft bastards are one of the best minds in the software market!
PHP is like untouchable by .NET, Ruby on rails (which is like the coolest MVC architecture by the way), JSP, CGI (grubby old technology)... none of these can shake PHP. With new CMS tools like Mambo, Joomla, WordPress, Drupal, and many many more, PHP is everybody's favorite when it comes to developing a quick and sexy sites. The new object oriented model in PHP 5.5 is just awesome.
Microsoft knowing that their .NET bomb cannot shake PHP, have decided to make it a part of the package they are shipping out with Visual Studio 2010. I think some hardcore PHP guys may not be very comfortable with this. It'll be like an Indian guy eating Upma (Uppit) with chopsticks. But for me, this is a great thing. I think they are going to include PHP hosting support with the new release of IIS. That just one server for both my areas of expertise. (Maybe expertise is a strong word... for now). No more switching between services to free my port 80.
Microsoft has actually done a good thing with this. PHP afterall is an opensource engine, and combining it with .NET would just be great. I would really look forward to a .NET CLR level code compatibility between PHP and ASP.NET someday. Or maybe that will never happen, as PHP is way too easy compared to ASP.NET with C#/VB. What the hell is J# i sometimes wonder!
Anyway... That's my update. Im really looking forward to user Visual Studio .NET with .NET 4.0. The SuperPreview is another sexed out application they are releasing. Oh by the way... all these are available as free downloads also. Microsoft is definitely going to get big. Silverlight is still a baby in a fish market.
PHP is like untouchable by .NET, Ruby on rails (which is like the coolest MVC architecture by the way), JSP, CGI (grubby old technology)... none of these can shake PHP. With new CMS tools like Mambo, Joomla, WordPress, Drupal, and many many more, PHP is everybody's favorite when it comes to developing a quick and sexy sites. The new object oriented model in PHP 5.5 is just awesome.
Microsoft knowing that their .NET bomb cannot shake PHP, have decided to make it a part of the package they are shipping out with Visual Studio 2010. I think some hardcore PHP guys may not be very comfortable with this. It'll be like an Indian guy eating Upma (Uppit) with chopsticks. But for me, this is a great thing. I think they are going to include PHP hosting support with the new release of IIS. That just one server for both my areas of expertise. (Maybe expertise is a strong word... for now). No more switching between services to free my port 80.
Microsoft has actually done a good thing with this. PHP afterall is an opensource engine, and combining it with .NET would just be great. I would really look forward to a .NET CLR level code compatibility between PHP and ASP.NET someday. Or maybe that will never happen, as PHP is way too easy compared to ASP.NET with C#/VB. What the hell is J# i sometimes wonder!
Anyway... That's my update. Im really looking forward to user Visual Studio .NET with .NET 4.0. The SuperPreview is another sexed out application they are releasing. Oh by the way... all these are available as free downloads also. Microsoft is definitely going to get big. Silverlight is still a baby in a fish market.
November 01, 2008
Low level encryption in PHP
I was creating this site ih PHP where in there are lots of configuration details. Details like DB username and password, site theme information, etc. The site would be installed and used by an unknown person who would become the site admin. Now, if the admin is not so computer savvy and wanted to change some of the configurations, he could easily edit the configurations which could screw up several things. To correct the data, the admin will have to reinstall the whole site. In order to prevent this from happening, I wanted to encrypt the config data.
I used a simple conbination of hex conversion and binary packing to do this. Here is the code I used for this:
A brief explanation on the above code: The normal.txt file contains the ACSII data. This would be converted to a non-human readable format and stored in club.cfg file. My site is a club of sorts, so the name "club". Anyway, the first part of encryption is to convert the data to hex. Then pack it to a binary format. The reason why im converting it to hex first is to make the code platform independent. I am storing each configuration detail in a seperate line. So I can reference the data by the line number. The second foreach loop reads thils encrypted file and displays the data. The hex2bin function was created by someone else. (Ref + credits: http://us.php.net/bin2hex).
So a simple conbination of hex conversion and binary packing is good enough to create and easy low level data encryption in php.
Peace ..V,
I used a simple conbination of hex conversion and binary packing to do this. Here is the code I used for this:
function hex2bin($h)
{
if (!is_string($h)) return null;
$r='';
for ($a=0; $a<strlen($h); $a+=2)
{
$r.=chr(hexdec($h{$a}.$h{($a+1)}));
}
return $r;
}
$config_data = file ("normal.txt");
$CFGSTR = "DO NOT EDIT THIS FILE";
foreach ($config_data as $n_str)
{
$hex_str = bin2hex ( $n_str );
$bin_str = pack ('h*', $hex_str);
$CFGSTR = $CFGSTR."\n".$bin_str;
}
$fp = fopen ("club.cfg", "w+");
fwrite ($fp, $CFGSTR, strlen ($CFGSTR));
fclose ($fp);
$cfg_data = file ("club.cfg");
echo "<hr>CONFIG DATA: <br>";
for ($i=1; $i<23; $i++)
{
$cfg_arr = unpack ('h*',$cfg_data[$i]);
$cfg = "";
foreach ($cfg_arr as $c)
$cfg = $cfg.$c;
$cfg = hex2bin ($cfg);
echo "$cfg <br>";
}
A brief explanation on the above code: The normal.txt file contains the ACSII data. This would be converted to a non-human readable format and stored in club.cfg file. My site is a club of sorts, so the name "club". Anyway, the first part of encryption is to convert the data to hex. Then pack it to a binary format. The reason why im converting it to hex first is to make the code platform independent. I am storing each configuration detail in a seperate line. So I can reference the data by the line number. The second foreach loop reads thils encrypted file and displays the data. The hex2bin function was created by someone else. (Ref + credits: http://us.php.net/bin2hex).
So a simple conbination of hex conversion and binary packing is good enough to create and easy low level data encryption in php.
Peace ..V,
October 18, 2008
Color chooser with PHP
I made this color chooser in PHP which is a rather simple code. It displays a table of known colors with RGB values ranging from 0 to 255. The table cell onclick property is used to redirect back to the same page by passing the color value through GET.
Here is the code:
The output will be something like this:

Peace ..V,
Here is the code:
<table cellspacing="0" cellpadding="0">
<?php
$inc = 255/5;
for ($r=0; $r<=255; $r+=$inc)
{
echo "<tr>";
for ($g=0; $g<=255; $g+=$inc)
{
for ($b=0; $b<=255; $b+=$inc)
{
$cstr = sprintf ("%02X%02X%02X", $r, $g, $b);
echo "<td width="5px" height="5px" bgcolor="#$cstr"
onclick="window.location='hello.php?g_cstr=$cstr'">n";
echo "</td>n";
}
}
$cstr = sprintf ("%02X%02X%02X", $r, $r, $r);
echo "<td width="5px" height="5px" bgcolor="#$cstr"
onclick="window.location='hello.php?g_cstr=$cstr'">n";
echo "</td>n";
echo "</tr>";
}
?>
</table>
The color you picked was:
<table> <tr>
<?php
$sel_col = $_GET['g_cstr'];
echo "<td width="25px" bgcolor="$sel_col"></td>n";
echo "<td>$sel_col</td>";
?>
</tr> </table>
The output will be something like this:

Peace ..V,
September 16, 2008
Simple bar graph in java
Here's a simple program in Java that reads integer values from a file and graphs it. This program is written in three files. The code is shown below.
File: drawGraph.java
File: Create Graph.java
File: GraphComponents.java
Peace ..V,
File: drawGraph.java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
public class drawGraph
{
public static void main( String args[] )
{
JFrame frame = new JFrame( "Graph" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
CreateGraph createGraph = new CreateGraph();
createGraph.setBackground( Color.WHITE );
frame.add( createGraph );
frame.setSize( 640, 480 );
frame.setVisible( true );
}
}
File: Create Graph.java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class CreateGraph extends JPanel
{
public int x (int tx)
{
return (tx + 5);
}
public int y (int ty)
{
return (400 - ty + 5);
}
public void paintComponent( Graphics g )
{
super.paintComponent( g ); // call superclass's paint method
this.setBackground( Color.WHITE );
GraphComponents graphComponents = new GraphComponents();
graphComponents.openFile();
graphComponents.readRecords();
graphComponents.closeFile();
g.setColor( Color.BLACK );
g.drawLine( x(0), y(0), x(620), y(0) );
g.drawLine( x(0), y(0), x(0), y(460) );
g.setColor( Color.BLUE );
for (int i = 0; i < graphComponents.getMaxYCount(); i ++)
{
g.fillRect( x(i*50+10), y(graphComponents.getYValues(i)*20),
40, graphComponents.getYValues(i)*20 );
}
File: GraphComponents.java
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class GraphComponents
{
private Scanner input;
private int yValues [];
private int yCounter;
public GraphComponents ()
{
yValues = new int [10];
yCounter = 0;
}
public void storeYValues (int val)
{
yValues [yCounter++] = val;
}
public int getYValues (int index)
{
return yValues[index];
}
public int getMaxYCount ()
{
return yCounter;
}
public void openFile()
{
try
{
input = new Scanner( new File( ".\\graphvalues.txt" ) );
yCounter = 0;
}
catch ( FileNotFoundException fileNotFoundException )
{
System.err.println( "Error opening file." );
System.exit( 1 );
}
}
public void readRecords()
{
try
{
while ( input.hasNext() )
{
storeYValues (input.nextInt());
System.out.println (yValues[yCounter - 1]);
}
}
catch ( NoSuchElementException elementException )
{
System.err.println( "ERROR: Unable to read file (No such element)" );
input.close();
System.exit( 1 );
}
catch ( IllegalStateException stateException )
{
System.err.println( "ERROR: Unable to read file (State exception)" );
System.exit( 1 );
}
}
public void closeFile()
{
if ( input != null )
input.close();
}
}
Peace ..V,
September 13, 2008
Creating round corners using CSS
In a website, menus and small rectangular regions with round corners look impressive. It can be seen in several sites. But as a web designer I found that creating round corners are not as easy as it looks. Here is one method I found to make things easy:
First a preview of that you're gonna read about:

The HTML code:
The CSS used along with this is:
The images cBL, cBR, tTL, cTR refer to the four corners. The size of these should be atleast 15px X 15px. Otherwise there will some strange vertical alignment problems. They are images that are rounded at the corners that will be placed at each corner. Here's a sample:
I've used .png images as they allow transparency. The above corners are perfect for a white background. Oh yes, the images must match the background. Should be careful about that. You can save those images and use it if you need them. They're not copyrighted... ;)
The above method can also be modified to include all the images in the CSS and not have any img tag at all. The advantage of doin this is the images will be at the background. When you try to select contents of the page, the corners will not get selected. In better words, the corners will look more merged with the background. But another disadvantage of this is you'll have to have 4 div tags and 4 classes. But the final output is the same.
CSS rocks!
First a preview of that you're gonna read about:

The HTML code:
<div class="windowFrame">
<div class="windowTopBar">
<img src="Images/cTL.png" class="imgL" />
<img src="Images/cTR.png" class="imgR" />
</div>
<div class="windowContentFrame">
Lorem ipsum... and other similar crap!
</div>
<img src="Images/cBL.png" class="imgL" />
<img src="Images/cBR.png" class="imgR" />
</div>
The CSS used along with this is:
.windowFrame {
width: 100%;
background-color: #BBBBFF;
margin-bottom: 10px;
text-align: center;
}
.windowTopBar {
width: 100%;
background-color: #0000FF;
height: 25px;
}
.windowContentFrame {
padding: 10px;
text-align: left;
}
.imgL {
float: left;
}
.imgR {
float: right;
}
The images cBL, cBR, tTL, cTR refer to the four corners. The size of these should be atleast 15px X 15px. Otherwise there will some strange vertical alignment problems. They are images that are rounded at the corners that will be placed at each corner. Here's a sample:
![]() ![]() ![]() ![]() |
I've used .png images as they allow transparency. The above corners are perfect for a white background. Oh yes, the images must match the background. Should be careful about that. You can save those images and use it if you need them. They're not copyrighted... ;)
The above method can also be modified to include all the images in the CSS and not have any img tag at all. The advantage of doin this is the images will be at the background. When you try to select contents of the page, the corners will not get selected. In better words, the corners will look more merged with the background. But another disadvantage of this is you'll have to have 4 div tags and 4 classes. But the final output is the same.
CSS rocks!
January 06, 2008
Introduction to Flash
Lately I've been addicted to flash. Its like I feel flash is the answer for everything. My first work-study project was to design a web-site. That's when the craze hit me. I first thought of doing and ASP.net site, but i realized its just a dumb site and there aren't any serverside functions to worry about. All I needed was a nice and flashy look that conveys the message.
Flash to the rescue.
Flash uses vector graphics and it is a very convenient tool for vector based animations. I first thought it might have a lot of support for drawing, but it doesn't. To get graphics into flash, you need to do it through photoshop (my all time favourite). So once you've done drawing something in photoshop just import it to your library or to the stage in Flash (Im using Flash MX, but it really doesn't matter).
In flash layers matter a lot. In fact its a good practice to make use of layers in everything. Both Flash and photoshop. Create distinct parts of whatever it is that you're doing on different layers and name those layers. Definitely helps when you're doin something big.
Once you've got all your images on the stage, its time to tween them and move them and make components out of them. The graphics part in flash is just one half of it. The second half is the actionscripting part. This is a lot like javascript. Also flash is event based - functions are called when an event occurs.
This is my introduction to flash. Also Its good to have dreamweaver 8.0.2 update if you want to use flash with decently in IE. IE has some irritating properties (Click to activate this control thing) and we need to use a bit of javascript to overcome this. The dreamweaver update does this automatically.
Im still a newbie in Flash. And I'll post whatever I learn on this blog. Hope it helps.
Flash to the rescue.
Flash uses vector graphics and it is a very convenient tool for vector based animations. I first thought it might have a lot of support for drawing, but it doesn't. To get graphics into flash, you need to do it through photoshop (my all time favourite). So once you've done drawing something in photoshop just import it to your library or to the stage in Flash (Im using Flash MX, but it really doesn't matter).
In flash layers matter a lot. In fact its a good practice to make use of layers in everything. Both Flash and photoshop. Create distinct parts of whatever it is that you're doing on different layers and name those layers. Definitely helps when you're doin something big.
Once you've got all your images on the stage, its time to tween them and move them and make components out of them. The graphics part in flash is just one half of it. The second half is the actionscripting part. This is a lot like javascript. Also flash is event based - functions are called when an event occurs.
This is my introduction to flash. Also Its good to have dreamweaver 8.0.2 update if you want to use flash with decently in IE. IE has some irritating properties (Click to activate this control thing) and we need to use a bit of javascript to overcome this. The dreamweaver update does this automatically.
Im still a newbie in Flash. And I'll post whatever I learn on this blog. Hope it helps.
Subscribe to:
Posts (Atom)



