Reference vs. Instance variables in java

Java is a mature language, so posting an article about it would not make sense. However,

Imagine you have following two classes:

public class TheParent{ public doParentThing(){} } public class TheChild extends TheParent{ public doChildThing(){}
public doParentThing(){} //overrride

Ok, now lets instantiate TheChild :

TheChild obj=new TheChild;

it's ok to invoke two methods:
obj.doParentThing(); //TheChild version invokes

now, instantiate it polymorphically:

TheParent obj=new TheChild();

if we try to invoke doChildThing() we get a compile error and when we invoke:


the TheChild's doParentThing() override invokes.

This is true when we get a reference to an interface that the instance variable's class implement. in such a case, we can ONLY invoke the methods blueprinted by the interface.

Changing the Foundation and a word about XML

After a long time, i could find some spare time and fix my website's problems. I changed the foundation of website to a XML based template system.

Today, more and more companies are adopting XML. Software developers use xml instead of value-pair configuration files, web designers use XHTML instead of HTML, users now consume rss and atom feeds, blogging websites use XML templates instead of old, error prone HTML templates, organizations use SOAP to exchange data (which is XML-based), and large corporations encourage developers and users to include XML in their everyday life!

XML is awesome. ;)


New Server

Finally, I moved to this server.
Thanks to my dear friend Ehsan.


Starting J2me

The semester exams are nearly finishing and i can take a break for three months. I am about to start learning j2me.


Difficult issues in programming

Sometimes, when we are learning a new subject, there are something that we can't understand at that time.
About three or four months ago,when i was still at web programming, i encountered such a subject in my learning process. I was about to create a template for oscommerce(a popular e-commerce cms. Friends at devnetworks.net are creatin' a better equivalent for oscommerce called devenetstore. I am one of the group, but i'm an sleepin' member!!) but i couldn't figure out how.
When i was new to programming, I couldn't understand Exceptions immediately. The key to understand this difficult issues are the following steps:
1. break up
2.drink a hot tea
3.start a new subject
4.come back to the difficult subject after one or two weeks


Java....Another Cup

I'm Still proceeding with Sun's Java Tutorial. That's  awesome.
I got netbeans. I like netbeans more than jbuilder but i believe that jbuilder is more pow'ful.


After a long time

hmm, i couldn't update for a while. sorry.
I have started the java tutorial by Sun. I think that's a good point to start from. I bought borland jbuilder 2005 enterprise last night. Some developers say that netbeans is better than jbuilder but i haven't tried netbeans yet. downloading it right now...



I enabled commenting to this blog.

Goodbye PHP

Dear PHP,

I started learning you with no programming experience. Actually, I learned programming with you. I have a lot of memories with you. I remember the nights i spent doing projects with you. You gave me a lot of money too.
But now, I wanna leave you. Because i have learned you and i need a good programming language. I am switching to Java.
But you can be certain that i won't create web applications with jsp.



PHP Architecht's Guide To PHP Design Patterns Book Review

Finally, I finished this book in the subject of design patterns. It helped me in the subject of design patterns. However, we can not compare it with Eric Gamma's book or Martin Fowler's. They are a must-read not only for every programmer, but for every computer engineer.
Jason Sweat (the author) put a great effort on this book. But TDD programming is overused. You can't get the most out of this book without knowing SimpleTest php|architect expressed this as a feature but in my opinion it is a weakness and not a feature.
UML diagrams are used reasonably and help the reader to understand the subject conceptually.
Appendix A, Pattern Quick Reference is very quick and efficient providing external sources and a brief description about each pattern.
The most important thing you should consider is that unfortunately you can not master design patterns just with reading a single book (Eric Gamma's book is an exception). You should implement the patterns in the real world with a good OOP language such as Java, C# or even PHP (PHP5 and not PHP4).
In my opinion and due to my experience, Factory Method, Singleton, Observer, Registry, MVC and Strategy play more important rules in programming than other programming languages.


Where are the Ebooks?

Yes, I deleted all of the e books. There were about 110 e books . But i don't want my personal blog to become an e book repository. Additionally, this is illegal. So, i deleted all of them.
Now, I only publish my own articles and some other stuff.


Fun Pic


Fun Pic


Funny Pic


funny pic

Funny Pic


New Project

I am joining a new project. An enterprise and extremely professional project.

Fun Pic


Moving to a new server

I am moving to my original server. www.danrah.com


Busy On Learning

Currently, I am busy on learning flash and photoshop.
new updates coming.


Busy on Work

Sorry. Busy on Work right now. New Updates Coming


Fun Pic


13 Signs Of Falling In Love

1. While reading this, there was one person on your mind the whole time.....

2. You would do anything for them...

3. You realize that you're always smiling to yourself when you think about them...

4. You get high just from their scent...

5. They become ALL you think about...

6. You start listening to slow songs, while thinking of them...

7. When you look at them, you can't see the other people around you... all you see is him/her...

8. You smile when you hear their voice...

9. When you think about them, your heart beats faster and faster...

10.You feel shy whenever you're with them...

11.You walk really slow when you're with them...

12.You read their ----s over and over again...

13.When your on the phone with them late at night and they hang up...but you miss them already when it was just two minutes ago



After Translation an article about regex and two about databases to persian(Which I published them to blog), Now I am working on an article about Ado.net .

Fun Pic


fun pic


fun pic


Funny Pic


Toilet,cats game,love (Fun Pic)

click to enlarge



Encoding Cookies in JavaScript

soruce: teach yourself javascript1.1 in a week by Arman Danesh
the information stored in the name-value pair of a cookie cannot contain any spaces. This poses something of a limitation because many applications will need to store complete phrases or strings containing spaces in cookies.

The solution to this lies in encoding the illegal characters in a cookie. Netscape suggests using an encoding scheme such as that used in URL strings.

However, any coding scheme will work. For instance, alternative characters such as % or + could be used for spaces and a similar approach could be taken for other illegal characters, such as semicolons.

Any script that is going to build cookies using white spaces and other illegal characters, or that is going to read similar cookies, will need to include methods for dealing with these characters.

JavaScript provides the escape() and unescape() methods, which take a string as an argument. escape() returns the string encoded like an URL and unescape() translates it back from this encoding.

An easier recipe for cookies.
It should be clear now that some type of standardized method for creating new cookies, reading existing cookies, and encoding cookies would make writing scripts much easier.
Just as he wrote the hIdaho Frameset, Bill Dortch has developed a set of freely available functions to perform all these tasks. The functions are available at
The source code is reproduced on the CD-ROM:

The source code should be included in the header of any document that includes scripts that work with cookies.
Although Dortch has done a good job of documenting each of the functions in the comments of the source code, we will run through them all in the next few sections.
The getCookieVal() function.
This function is an internal function called by GetCookie(). Given the index of the first character of the value of a name-value pair in a cookie, it returns the value as an unencoded string.
The function uses the unescape method to decode the value.
The GetCookie() function.
The getCookie() function is used to retrieve the value of a particular cookie. It takes the name of the cookie as an argument and returns the value. If the cookie doesn't exist, the function returns a null value.
The SetCookie() function.
This function can be used to create a new cookie or to update an existing cookie. The function requires two arguments and can take several optional arguments:
where expires, path, domain, and secure are optional parameters, and name and value are required. Name, value, path, and domain should be strings. expires should be passed as a Date object and secure should be a Boolean value.
The order of the arguments is important, so if you want to leave out a particular value in the middle of the order, you should pass the null value as a placeholder.
The DeleteCookie() function.
This function does just what the name suggests: deletes the cookies specified by a name argument. The cookie is deleted by updating it with an expiry date equal to the current date and time.


Fun Pic 4 U


Funny Pic


PHP, COM, .NET and asp

I wanna start a topic about Com, .NET and PHP.
First, What is COM?

All About COM
COM stands for component object model. We will start our look at COM with an overview of the two basic components of COM: a component and an object.

What Is a Component?
A component can be described as a piece of code that can be shared by other programs. For example, you might write a spell-checker component that could be used by a word processing package or email software.

What Is an Object?
An object can be described as code that is reusable. This sounds like a component, and indeed, a component can be made of objects. Perhaps your spell-checker has a dictionary object for checking words, a custom dictionary object for storing custom words, and an object for running through words and checking them against the dictionaries.

What Is COM?
COM is a model for creating components from objects. COM is a binary specification. In other words, it is not programming-language-bound. But all languages that support the creation of COM components must create the components to the same specification. In this way, COM components created in one programming language (such as ActiveState and Perl) can be reused in another COM-supported programming language (such as VB).

COM is still the cornerstone of Windows development. Almost everything that Microsoft does is based on COM. Windows is COM-based, Office is COM-based, Microsoft VB can create and interface with COM components? the list is endless.

Server-Side or Client-Side COM
COM components are often divided into client-side or server-side components. Although they serve different purposes, they fundamentally serve the same purpose?forming a reusable block of code in an application. A spell-checker component is an example of a client-side component, and a tax component for an e-commerce web site is an example of a server-side component. Server-side components can take advantage of newer elements for COM: Microsoft Transaction Server (MTS) and Microsoft Message Queue (MMQ). Client-side components can also be GUI components that can be used to make up a GUI for an application (such as a button).

A Brief History of COM
This section looks at how COM developed, from its early days as a way of sharing data to its current incarnation as a fully featured component system.

Dynamic Data Exchange (DDE) was developed in the late 1980s to allow Windows applications to share data (text and graphics) from the Clipboard. However, because DDE was available only to Microsoft applications, it was not a widely used or popular solution for transferring data between applications.

To resolve this problem, Microsoft developed OLE (Object Linking and Embedding), now called OLE 1. OLE 1 allowed you to insert a document from one application into the document of another. An example would be embedding a spreadsheet into a word processing package. Because the spreadsheet was linked, if you updated it, the update would appear in the embedded spreadsheet in the word processing document as well. OLE 1 was slow and suffered from bugs. However, Microsoft realized this and began developing OLE 2.

It was during the development of OLE 2 that Microsoft saw how OLE caused problems for applications. Different applications used different methods to allow the embedding of applications within themselves. OLE required many function calls and parameters that most applications achieved in different ways. Put another way, one problem lay in getting two applications to find a common way of communicating. COM was developed as a part of OLE 2 to overcome this problem.

After COM was born, it gave applications a common way of communicating. If the applications used COM, either built using COM objects or by using COM for an external interface, all COM applications would have a common way of communicating. COM applications could be COM objects themselves or could be made of COM objects.

Distributed COM (DCOM) was developed later to allow COM objects to communicate over a network (rather than the same computer). It's often described as "COM with a long wire."

Microsoft began a concentrated effort to allow developers to use COM as a way to build applications from components. With the arrival of COM support in ASP and DCOM, Microsoft saw how developers were building applications from COM components that were housed on several different computers.

To build on this, Microsoft added Microsoft Transaction Server (MTS) and Microsoft Message Queue (MSMQ) to the Windows NT 4 service pack.

MTS added transaction services that COM objects could call on, and MSMQ allowed messages between COM objects to be stored in a queue. If a message could not get through, it could be stored and forwarded later.

With the arrival of Windows 2000, however, Microsoft developed a version of COM to integrate MTS and MSMQ within COM so that natively it had DCOM, transaction, and messaging services available. Microsoft called this version COM+.

What Makes Up a COM Object?
In its simplest form, a COM object consists of one or more classes, as shown in Figure 7.1. Each class consists of a collection of methods, and within these methods is the code that makes up your object. Methods can be private, meaning that they can be used only by other methods within the same class. Methods can also be public, meaning that they can be used by all methods and are exposed to the outside world (and thus are the only kinds of functions you can use when calling a COM object).

COM has a lot more to it than what I have described. However, because an in-depth discussion of COM's internals is beyond the scope of this book, I recommend the books listed in the next section for further information.

How Are COM Objects Created?
COM objects can be created in any programming language that supports the COM binary specification. All Microsoft programming tools (such as Visual Basic and Visual C++) support COM, as do ActiveState programming tools (Perl, Python,TCL) and Borland programming tools (such as Delphi), to name just a few.

If you are interested in learning more about COM's internals and COM development, I suggest the following books:

Appleman, Dan. Dan Appleman's Developing COM/ActiveX Components with Visual Basic 6. Sams Publishing, 1998.

Brill, Gregory. Applying COM+. New Riders Publishing, 2000.

Creating a Server-Side COM Component in VB 6.0
Creating a COM object in VB is very straightforward. First, open VB and select ActiveX DLL, as shown in Figure 7.2.

Figure 7.2. Selecting an ActiveX DLL project type inVisual Basic.

Call the project php4winbook and name the class Examples

Next, add the following code to the examples:

Option Explicit
Public Function HelloFunc(ByRef uname As Variant) As Variant
HelloFunc = "hello " & uname
End Function
Note that you have created a single function called HelloFunc; this will become important to remember later in this chapter.

Finally, compile the component. This gives you php4winbook.dll. Because you have built your COM component from within VB, it is registered for use on the system you built the COM component on. If you want to use the COM component on another system, you must register it using the following command:

RegSvr32 php4winbook.dll
Also note that if you create COM components in VB that use the ByRef statement, they might not work in PHP 4.0.4. This appears to be because of an issue with the ByRef statement and PHP. This has been resolved in PHP 4.0.6.

How Are COM Objects Referenced?
Programming languages have different ways of referencing COM objects, but they all call the COM component's name. The call to the COM component's name is passed to Windows, which looks up the name in its Registry. After the name is found, Windows looks up the COM component's location (stored in its Registry entry) and loads it into memory. The memory location of the COM object is then passed back to the calling application. When the calling application has finished with the COM object, it should pass this information back to Windows so that Windows can unload the COM object from memory (to preserve system resources). Most languages support an automatic feature that does this for them. Nevertheless, it is a good practice to include this in your code when using COM components.

When working with the Microsoft IIS web server, it is possible to create your own memory space for your web site (Microsoft calls them web applications) so that all COM components you use are created by Windows within that memory space. It's important to note, however, that IIS holds that COM component in memory space until the web application or web server is stopped. This increases the speed with which IIS can pass COM objects back to calling applications, but it does mean that you must unload them from the web application if you want to change or recompile your COM object (or Windows will hold them as locked).

Interfacing with a COM Component in Classic ASP
As an example, we can look at how classic ASP (called ASP in the rest of this chapter) handles COM components. ASP supports the interfacing of COM, not the creation of COM objects. However, its main scripting languages, VBScript and JScript, can both be exposed as COM objects.

Let's start with some ASP code:

<% set test = Server.CreateObject("php4winbook.Examples") hellmes = test.HelloFunc ("Andrew") set test = nothing Response.write hellmes %>
In this code, ASP loads into memory the php4winbook COM component you created a moment ago.

Let's look at each line of the code:

set test = Server.CreateObject("php4winbook.Examples")
Note that you have interfaced with the Examples class. COM can interface with only one class of a COM component in any one recall. Different applications can call on different classes of the same component, but in one call it's one class only.

hellmes = test.HelloFunc ("Andrew")
This line says to pass some information to the HelloFunc function of the Examples class and store its return result in hellmes.

That result is then printed to the screen, as shown in Figure 7.4.

Figure 7.4. The output of your COM object from ASP.

Note that you also unload the COM component from memory:

set test = nothing
How Does PHP Handle COM?
Like ASP, PHP supports the interfacing of COM, but not the creation of COM objects. In other words, it can interface with any COM object, but you cannot yet create COM objects with PHP code.

PHP's COM Functions
PHP has featured COM support since PHP 3.03. These same functions are still available in PHP 4. You can interface with your php4winbook COM component in the following way:

Let's look at some of these code lines:

$comobj = com_load("php4winbook.Examples");
This line loads the COM component into memory. Note that, as in the ASP example, you can do this on only a single class level.

You then set the value of the HelloFunc function to the value Andrew:

com_set($comobj, "HelloFunc", "Andrew");
You then obtain the return result of the HelloFunc function:

$hellmes = com_get($comobj, "HelloFunc");
Although you are guaranteed backward compatibility between versions of PHP, the syntax can become messy. PHP 4 has a shorthand version for using COM components:



Let's look at a couple of these code lines:

$comobj = new COM("php4winbook.Examples");
This loads the COM component into memory. What happens here is that when you call the COM component using PHP's COM class, you create a link between the COM component and PHP. Note that when you call the PHP component, you can do so at only a single class level and access public functions in that class. So when you call a function of the COM component, PHP translates that call into data that the COM component can understand (such as changing data types). Note the different syntax for loading the COM component into memory between ASP and PHP.

$hellmes = $test->HelloFunc("Andrew");
Next you pass some information to the HelloFunc function and store its return result in $hellmes. This is a better method of setting and getting the value of functions, because you can do so in one line of code and don't need to use PHP functions. PHP makes the function call within the COM component for you. Note the PHP forward notation.

If you think there is very little difference between the way the ASP and PHP code works, you are right. Both languages must load the COM component into memory, where they then call its functions. This also demonstrates one of the beauties of using COM. You wrote the COM component in VB and accessed it in both ASP and PHP. And you could rewrite the COM component in C++?it makes no difference to your ASP or PHP code.
Now that we have examined COM, we will finish with a look at Microsoft .NET.

What Is Microsoft .NET?
It is important to remember that .NET is not COM, and vice versa. .NET is a brand-new strategy from Microsoft. As mentioned at the start of this chapter, COM is the cornerstone of the current Microsoft platform. .NET, however, is the cornerstone of future Microsoft development. .NET applications run not only on Microsoft platforms but on any device (your PC, your WebTV, your handheld, and so on).

.NET is a combination of things. Largely, it's a framework that encompasses a Common Language Runtime (CLR, discussed in a moment) and common class set (also covered in a moment). It also gives application developers new ways of working with the platform they are targeting and creating the applications they want to deploy. As we will see, .NET is a far more powerful way of working than COM and is decidedly COM's successor.

What Makes Up Microsoft .NET?
Microsoft .NET is a broad concept that Microsoft splits into four terms:

.NET framework

.NET development tools

.NET OSs and servers

.NET services

.NET Framework
This is how .NET applications are created; they use the CLR and a common class set. Microsoft provides the .NET framework SDK to allow you to do this.

The .NET framework also gives you several new languages that make use of the CLR and common class set:Visual Basic .NET, a new version of Visual Basic; C# (pronounced "C sharp"), a language with the control and power of C and C++ but with the rapid application development capability of a language like Visual Basic; and J# (pronounced "J sharp"), which is a version of Java for the .NET framework.

.NET Development Tools
Microsoft offers Visual Studio .NET for easy .NET development. You don't need Visual Studio .NET to create .NET applications, but it has been developed to aid in this process.

.NET OSs and Servers
Microsoft has rebranded most of its product line to use the .NET name. However, Microsoft OSs and servers don't yet use the .NET framework. (However, plans are underway to include the CLR in future versions of Microsoft Server 2000 and to allow the creation of stored procedures in C# for SQL Server.) Microsoft also plans to release the next version of Windows 2000 as Windows .NET. This OS won't be based on the .NET framework, but it will contain parts of the .NET framework.

.NET Services
Web services (discussed in Chapter 9, "PHP and Web Services") are a big part of Microsoft .NET. They are very easy to build and deploy using Microsoft .NET. To aid in this sort of development, Microsoft is building a set of web services called Microsoft MyServices to allow your web service applications to connect to Microsoft services such as Microsoft Passport and HotMail.

What Makes Up the .NET Framework?
The .NET framework is split into two parts: the CLR and the common class set.

The Common Language Runtime (CLR) is the runtime of the .NET framework. In a .NET language (such as Visual Basic .NET or C#), the compiler compiles the code to something called MSIL (Microsoft Intermediate Language). MSIL can then be run on any CLR. The CLR itself can be targeted at any platform (Windows, Linux, Solaris, UNIX, and so on), so instead of your having to rewrite your .NET application to suit the platform, all the platform needs is a suitable CLR. In theory, this means that your applications can target any application that has a suitable CLR.


The CLR is to be ported to the FreeBSD UNIX platform by Microsoft and to Linux by several third parties.

This approach might be familiar to Java developers. In the case of Java, the common runtime is called the Java Runtime Environment (JRE).

Common Class Set
The .NET framework provides a common class set that a .NET-compatible language can use. The common class set provides you with classes for many things, from handling data such as strings and variables to working with the Win32 API. The class set handles much of the functionality that was often difficult, such as working with databases with ADO (now called ADO.NET).

.NET Applications
.NET applications can be several different things, from conventional Windows GUI applications to console applications, web services, Windows services, and .NET components (which is the .NET equivalent of COM components).

All .NET applications can make use of something called an assembly. Microsoft .NET assemblies allow a .NET application to package itself into a single compact unit. For example, an assembly can contain an application's .exe file, any related component (DLL) files, and graphics files. The assembly spells the end of "DLL hell," in which different versions of the same DLL could be installed to a computer, causing compatibility problems. Now an application needs to look no further than its assembly.

Assemblies can be of two types: private and shared. In a private assembly, the assembly's contents are available only to the application within that assembly (any DLL files in that assembly can be used by that assembly's application). A shared assembly can be accessed by files (applications, DLLs, and so on) in other assemblies. A shared assembly is stored in the GAC (Global Assembly Cache), which you can view under C:\WINNT\Assembly\ if you have the .NET framework installed. You can use the shfusion.dll (a Windows shell extension that comes with the .NET framework) to obtain more information about the GAC.

Obtaining the .NET Framework
The .NET framework currently is in version 1.0. It is available for Windows XP, Windows 2000, and Windows NT 4.0 platforms only. You can download the .NET framework from http://www.gotdotnet.com. You can also order it on a CD for free (there is a small shipping charge).

.NET and PHP
PHP currently does not support .NET natively. You can access .NET libraries, but PHP has no support for the CLR. Daniel Beulshaushen of php4win.com has developed a version of PHP and a related PHP extension that can access .NET libraries. However, this is currently in beta and cannot be used with standard PHP extensions. However, you can access .NET libraries and other features by wrapping them into .NET components and exposing such components to PHP using a feature of .NET called COM Interop.

COM Interop lets you create a COM wrapper around your .NET components. The .NET component remains a .NET component, but it uses the CLR and is built using the .NET framework. However, it is built in such a way that Windows thinks it's a COM component and makes it available to all calling COM clients.

In this way, you can make a .NET component available to PHP via the same COM features of PHP discussed earlier. To use a .NET component with PHP successfully, you must make sure that you place your .NET component in the GAC. Unlike COM, .NET does not use the Registry to find components; it uses the GAC. In order for your PHP script to find your component, you must place it in the GAC.

Creating the .NET Component
The first step is to create the .NET component. You could use Visual Studio .NET for this, but all you need is the .NET framework installed. As such, you will use a simple text editor (Notepad is fine) and the command line.

Creating the examples.vb File
Create the file examples.vb using the following code:

Namespace php4winbook

Public Class examples

Public Function showname(ByVal name As String)
Return "hello " & name

End Function

End Class

End Namespace
This is Visual Basic .NET code, but you can use any .NET language you choose (such as C#). Save the file as examples.vb.

Creating a Key File
Every component in the GAC must be versioned and signed. To do this, you will use a cryptographic key. You create the key from the command line by typing the following:

sn -k key.snk
This creates a cryptographic public key (a private key to encrypt and a public key to decrypt) called key.snk. To create this key, the CLR uses the contents of the assembly using a private key it creates itself. Anyone can use the public key to decrypt the assembly. It helps ensure that the assembly has not been tampered with. (If the assembly's contents have changed, the public key would be different.)

Creating a Reference File
You must now add a reference to the component and use that reference to sign the assembly. Create the file AssemblyInfo.vb and add the following:

Imports System.Runtime.CompilerServices

Note that you need to use the Imports statement and that

must point to the directory containing the key.snk file (in case it's in the same directory as the VB.NET files).

Compiling a Reference File
You must now compile the reference file with the following:

vbc /t:module /out:AssemblyInfo.dll AssemblyInfo.vb
Compiling examples.vb with a Reference File
Now that you have the compiled reference file, you can use it when you compile the examples.vb file. This indicates to the CLR that you have a reference file and that it can be used to sign the assembly.

The following line creates the assembly file examples.dll:

vbc /t:library /addmodule:AssemblyInfo.dll examples.vb
A Shortcut for Creating a Signed Assembly File
You can add the reference file directly to the VB.NET code:

Imports System.Reflection
Imports System.Runtime.CompilerServices

Namespace php4winbook

Public Class examples

Public Function showname(ByVal name As String)

Return "hello " & name

End Function

End Class

End Namespace
You can compile with this:

vbc /t:library examples.vb
However, if you have many components in your assembly, you might want to keep the reference file and the code for various assembly contents separate (thus making changes to the reference file code easier to make), as you did in the first example.

Adding examples.dll to the GAC
You must now add the signed assembly file to the GAC using the following:

drive letterProgram Files\Microsoft.NET\FrameworkSDK\Bin\gcutil /i
If you open the GAC in Windows Explorer (drive letter\WINNT\Assembly\), you should see the entry for your component

Adding the Assembly to the Registry
In order to complete the process of fooling Windows, you must create a type library (TLB) file for your assembly. COM requires TLB files so that it can gather the information it needs about the component to access its public functions correctly (that is, what data type the function is and what data type it needs to send and receive from those functions).

Regasm examples.dll /tlb:examples.tlb
Remember that Windows looks for COM components in the Windows Registry, but .NET components reside in the GAC. Regasm fools Windows by adding information to the Registry about your component, but instead of loading the COM component from the file system, it loads from the GAC.

Creating the PHP File
Create the file testcode.php with the following code:


Notice that you have used the same syntax as the COM example you built earlier in this chapter. As far as PHP is concerned, you are using a COM component.

Running the PHP File
If you now run the testcode.php file, you should see the result printed to the screen


Funny Pic 4U

Sperms and Lawyers

What does a lawyer and a sperm have in common?
Both have about a one in 3 million chance of becoming a human being.

The Microsoft Borg

In the wake of the emergence of the free Linux operating system a quick look into the future.
"Star Trek Lost Episodes" transcript:
(Picard)"Mr. LaForge, have you had any success with your attempts at finding a weakness in the Borg? And Mr. Data, have you been able to access their command pathways?"
(Geordi)"Yes, Captain. In fact, we found the answer by searching through our archives on late Twentieth-century computing technology."
(Geordi presses a key, and a logo appears on the computer screen.)
(Riker looks puzzled.)"What the hell is 'Microsoft'?"
(Data turns to answer.)"Allow me to explain. We will send this program, for some reason called 'Windows', through the Borg command pathways. Once inside their root command unit, it will begin consuming system resources at an unstoppable rate."
(Picard)"But the Borg have the ability to adapt. Won't they alter their processing systems to increase their storage capacity?"
(Data)"Yes, Captain. But when 'Windows' detects this, it creates a new version of itself known as an 'upgrade'. The use of resources increases exponentially with each iteration. The Borg will not be able to adapt quickly enough. Eventually all of their processing ability will be taken over and none will be available for their normal operational functions."
(Picard)"Excellent work. This is even better than that 'unsolvable geometric shape' idea."
.. . . 15 Minutes Later . . .
(Data)"Captain, We have successfully installed the 'Windows' in the command unit and as expected it immediately consumed 85% of all resources. We however have not received any confirmation of the expected 'upgrade'."
(Geordi)"Our scanners have picked up an increase in Borg storage and CPU capacity to compensate, but we still have no indication of an 'upgrade' to compensate for their increase."
(Picard)"Data, scan the history banks again and determine if there is something we have missed."
(Data)"Sir, I believe there is a reason for the failure in the 'upgrade'. Apparently the Borg have circumvented that part of the plan by not sending in their registration cards.
(Riker)"Captain we have no choice. Requesting permission to begin emergency escape sequence 3F . . ."
(Geordi, excited)"Wait, Captain I just detected their CPU capacity has suddenly dropped to 0% !"
(Picard)"Data, what do your scanners show?"
(Data)"Apparently the Borg have found the internal 'Windows' module named 'Solitaire' and it has used up all the CPU capacity."
(Picard)"Let's wait and see how long this 'solitaire' can reduce their functionality."
.. . . Two Hours Pass . . .
(Riker)"Geordi, what's the status of the Borg?"
(Geordi)"As expected the Borg are attempting to re-engineer to compensate for increased CPU and storage demands, but each time they successfully increase resources I have set up our closest deep space monitor beacon to transmit more 'Windows' modules from something called the 'Microsoft fun-pack'.
(Picard)"How much time will that buy us?"
(Data)"Current Borg solution rates allow me to predict an interest time span of 6 more hours."
(Geordi)"Captain, another vessel has entered our sector."
(Data)"It appears to have markings very similar to the 'Microsoft' logo."
(Data)"The alien ship has just opened its forward hatches and released thousands of humanoid shaped objects."
(Picard)"Magnify forward viewer on the alien craft."
(Riker)"Good God, Captain! Those are humans floating straight toward the Borg ship with no life support suits! How can they survive the tortures of deep space?!"
(Data)"I don't believe that those are humans,sir. If you will look closer I believe you will see that they are carrying something recognized by Twenty-first Century man as doe skin leather briefcases, and they are wearing Armani suits."
(Riker and Picard together, horrified) "Lawyers!!"
(Geordi)"It can't be. All the Lawyers were rounded up and sent hurtling into the sun in 2017 during the Great Awakening."
(Data)"True, but apparently some must have survived."
(Riker)"They have surrounded the Borg ship and are covering it with all types of papers."
(Data)"I believe that is known in ancient vernacular as 'red tape'. It often proves fatal."
(Riker)"They're tearing the Borg to pieces!"

PHP on Mac OS X

source: apple.com

PHP 4.3 is an exciting release for web programmers working on Mac OS X. Previous versions ran on Mac OS X, but not without some difficulty. Installation was especially challenging, and most opted for a binary release, like the one distributed by entropy.ch.

But PHP 4.3 offers full support for Mac OS X. Thanks to some very hard work by members of the PHP development team, anyone familiar with UNIX installations should be able to get PHP up and running. In this article I’ll show you the basics of Mac OS X installation, then demonstrate PHP’s flexibility by describing three distinct ways to parse XML files.

Installation Choices

PHP offers many installation options, far more than I could cover in this article. You can install it as a stand-alone binary, for example, or get it to run as an Apache module. Plus there are dozens of APIs that can be added to PHP, and most require additional libraries to be downloaded and installed.

For the purposes of this tutorial, I’ll assume you’ll be installing PHP as an apxs module that works with the Apache server that shipped with Mac OS X. I’ll show you how I installed a few modules that were of particular interest to me, though other modules can be installed using similar methods.

Initial Steps

First, get the most recent source code of PHP. There may be a later version since the time of this publication. Download the file to a convenient directory. (I’ve created a directory called /apps for PHP and other UNIX applications I need to install.) Decompress the downloaded file with the following commands:

shell> gunzip php-4.3.4.tar.gz
shell> tar xf php-4.3.4.tar

You’ll now have a directory called /apps/php-4.3.4. At this point you can do a basic, no-frills PHP installation:

shell> cd php-4.3.4
shell> ./configure --with-apxs
shell> make
shell> sudo make install

As you add more modules to your installation, you’ll also need more flags in the ./configure command. For example, if you followed Apple Internet Developer’s instructions for installing MySQL or PostgreSQL, you could add either of the following flags to ./configure to make PHP aware of your preferred database:

shell> ./configure --with-mysql=/usr/local/mysql \

(Note that PHP assumes most libraries will be in /usr/local. In the above command, I had to make PHP aware that MySQL was not installed in the default directory.)

I decided to add three other modules to my installation: the GD modules for image processing, the XPAT module for XML processing, and the DOM XML module for XML parsing through the Document Object Model.

The XPAT module is a piece of cake. All you need to do is add the — with-xml flag. The required libraries are already available.

The GD image processing module is a bit trickier, however. The GD libraries are bundled with PHP 4.3, but GD is dependent on a few other libraries: zlib, libjpeg, libpng, and libtiff. You could go through the process of downloading, configuring, and compiling these yourself, but, if you’re using Fink, there’s really no need. Fink automates the installation of dozens of UNIX packages and is extremely easy to work with.

Follow these instructions and you’ll end up with a new directory called /sw with a great deal of software in it. You can now use Fink to install libraries with a single command. For example, here’s how you install libjpeg, libpng, and libtiff:

shell> sudo /sw/bin/fink install libjpeg
shell> sudo /sw/bin/fink install libtiff
shell> sudo /sw/bin/fink install libpng

(Note that Fink uses a base directory of /sw for all its installs.)

At this time, Fink can’t install zlib on Mac OS X 10.2, which is needed for GD to run. For that you’ll need to compile from the source. But that’s no big deal—start by downloading the source. Then decompress it:

shell> gunzip zlib-1.1.4.tar.gz
shell> tar -xf zlib-1.1.4.tar

After you cd into the directory, you can install zlib with just two commands:

shell> cd zlib-1.1.4
shell> make
shell> sudo make install

Now you can configure PHP with everything you need to run GD:

shell> cd /apps/php-4.3.4
shell> ./configure --with-zlib-dir=/usr/local \
--with-libjpeg=/sw \
--with-libtiff=/sw \
--with-libpng=/sw \
--with-gd \
--with-pgsql=/usr/local \
--with-mysql=/usr/local/mysql \
--with-xml \

I also want to add the XML DOM API, which requires the GNOME XML library, libxml2. Conveniently enough, Fink can handle that, too:

shell> sudo /sw/bin/fink install libxml2

The Fink install of libxml2 didn’t work with PHP at first, however. I had to change line 30 of /sw/include/libxml2/libxml/encoding.h to the following:


After this change, the following commands installed PHP with everything I needed:

shell> cd /apps/php-4.3.4
shell> ./configure --with-zlib-dir=/usr/local \
--with-libjpeg=/sw \
--with-libtiff=/sw \
--with-libpng=/sw \
--with-gd \
--with-pgsql=/usr/local \
--with-mysql=/usr/local/mysql \
--with-xml \
--with-dom=/sw \

shell> make
shell> sudo make install

To finish the installation, you need to add the following line to your /etc/httpd/httpd.conf file:

AddType application/x-httpd-php .php

Then copy your php.ini to the /usr/local/lib directory:

shell> sudo cp /apps/php-4.3.4/php.ini-dist /usr/local/lib/php.ini

Parsing XML Files

To show how PHP can parse XML files on Mac OS X, I decided to work with the XML file that holds information on iTunes songs and playlists. You can find this file in ~/Music/iTunes/iTunes Music Library.xml. The PHP files I created to work with the XML are included in this tar file.

To work with the XML file, you can make a symlink of it to your web tree. I copied the file directly into my webserver’s directory:

shell> mkdir /Library/WebServer/Documents/itunes
shell> cp ~/Music/iTunes/iTunes\ Music\ Library.xml

Here’s an excerpt of the file:

Major Version
Minor Version
Application Version


Track ID
Baby Goes To Eleven
Last Call For Vitriol
Alternative & Punk
MPEG audio file
Total Time
Disc Number
Disc Count
Track Number
Track Count
Date Modified
Date Added
Bit Rate
Sample Rate
File Type
File Creator

File Folder Count
Library Folder Count

Track ID
I Can't Wait
Last Call For Vitriol
Alternative & Punk
MPEG audio file
Total Time
Disc Number
Disc Count
Track Number
Track Count
Date Modified
Date Added
Bit Rate
Sample Rate
File Type
File Creator
File Folder Count
Library Folder Count

iTunes stores similar information for each song in the library between a set of tags. My immediate goal in PHP is to turn the provided XML into a PHP structure. I’ve opted to turn this data into a two-dimensional array that will look like this:

[0] => Array
[Track ID] => 115
[Name] => Baby Goes To Eleven
[Artist] => Superdrag
[Album] => Last Call For Vitriol
[Genre] => Alternative & Punk
[Kind] => MPEG audio file
[Size] => 4828597
[Total Time] => 241319
[Disc Number] => 1
[Disc Count] => 1
[Track Number] => 1
[Track Count] => 12
[Year] => 2002
[Date Modified] => 2003-01-08T13:55:19Z
[Date Added] => 2003-01-08T13:53:18Z
[Bit Rate] => 160
[Sample Rate] => 44100
[File Type] => 1297106739
[File Creator] => 1752133483
[File Folder Count] => 4
[Library Folder Count] => 1

[1] => Array
[Track ID] => 120
[Name] => I Can't Wait
[Artist] => Superdrag
[Album] => Last Call For Vitriol
[Genre] => Alternative & Punk
[Kind] => MPEG audio file
[Size] => 3978043
[Total Time] => 198791
[Disc Number] => 1
[Disc Count] => 1
[Track Number] => 2
[Track Count] => 12
[Year] => 2002
[Date Modified] => 2003-01-08T13:56:20Z
[Date Added] => 2003-01-08T13:55:24Z
[Bit Rate] => 160
[Sample Rate] => 44100
[File Type] => 1297106739
[File Creator] => 1752133483
[File Folder Count] => 4
[Library Folder Count] => 1

PHP has a powerful set of array functions, so once you have this type of structure, you’ll be able to sort and lay out the iTunes data on a webpage any way you want.

I’m going to present three methods for moving the XML into the array. To make things easy on myself, I created a few functions that will work with the array I create. These functions are in the parse_itunes_functions.php file.

I want to be able to sort the data by any category—song name, artist name, album name, or any array key available. For that, I’ll use PHP’s usort() function, which takes two arguments: the array to be sorted, and the name of a user-defined function that the array will be sent to. Here’s my array sorting code:

function cmp ($a, $b) {
$sort = !empty($_GET["sort_by"]) ? $_GET["sort_by"] : "Artist";
return strcmp($a[$sort], $b[$sort]);

usort($songs, "cmp");

The cmp() function looks in the GET values for a sort_by variable. If one exists, the array will be sorted by that value. The default sort_by value is “Artist.”

Once an array is sorted, you’ll need to lay it out on a webpage. The array_to_table() function takes care of that:

function array_to_table($array, $printable)
//expects multi-dimensional array, all with the same keys
$str = "\n";
$str .= "\n";
foreach($array as $elem_key=>$element){
foreach($header_items as $header){
if(in_array($header, $printable)){
$str .= "\n";
$str .= "\n";
$str .= "\n";
foreach($element as $k => $v){
if(in_array($k, $printable)){
$str .= "\n";
$str .= "\n";
$str .= "
" . $header
. "
" . $v . "
return $str;

Note that the second argument, $printable, expects an array of key names that you want included in the table. The following two lines would print out a table with four columns:

$printable= array("Name", "Artist", "Album", "Size");
echo array_to_table($songs, $printable);

Using this code, your webpage will look something like this:

iTunes webpage using php

Clicking on the header items will sort the table by that item.

Preparing to Parse the XML

The format of the iTunes XML file is not the easiest thing to work with. Life would’ve been a little easier if the tags looked something like this:

Funk with XML
Tech band

My Blue Heaven
Lovely Sounds Around

But in the XML format that iTunes uses (see the above excerpt), the tag names themselves are not terribly descriptive. For example, elements appear in several contexts: surrounding every element in the file, each major segment of the file (e.g., library items and playlists), and each song within the library. To get a list of the songs in the library, the script needs to examine everything between the third opening tag and its matching closing tag, which happens to immediately precede the tag.

The tags for individual library items don’t offer much information. They alternate between and a variable type (string, integer, date). PHP isn’t a strictly typed language, so this kind of information isn’t particularly useful here. As the script parses the file, the value within the tag will need to become an array key, and the value of the next element will become the array value.

Parsing with PCRE

PHP has outstanding text handling abilities, and the first method I’ll use for parsing XML uses one of the handiest text handing function sets available in PHP, the Perl Compatible Regular Expression (PCRE) functions. The code for my PCRE example is included in the pcre_parse.php file in the tarball.

PCRE offers nearly all the power that Perl scripters have grown to expect from their regular expressions. They’re faster than the standard PHP regular expression functions and they offer features like non-greedy matching, which you can’t use with the ereg() functions.

Here’s a quick function that moves each library item into an array with the structure I described above:

function parse_via_pcre($contents)
//get everything between the and
//tags, which will include each library element.
$contents, $whole_match);

//the text between each tag will be a library item
$whole_match[1], $items);
//$j is a generic counter.
foreach($items[1] as $value){

//this function creates two needed arrays
//$elements[1], which stores the values within
//the tags, and
//$elements[2], which stores the values within
//the tags that follow
", $value, $elements);

//for each element assign a key and value to $songs array
for($i=0; $i < key="$elements[1][$i];" value="$elements[2][$i];">

Three reasonably simple regular expressions is all it took to get at the needed information. To use this function, all you need to do is open the file and pass it a string containing the file contents:

$fp=fopen("library.xml", "r");
$contents=fread($fp, filesize("library.xml"));

Parsing with XPAT

The next approach to parsing the file uses the XPAT functions. XPAT is a SAX (Simple API for XML) parser, an event-based parser that can be told to perform an action when a particular condition is encountered. For instance, when the parser comes across an opening tag, that’s an event. Other events include encountering a closing tag or processing instructions. What happens when these events occur is entirely your business; in PHP, these events will trigger functions that you’ll have to write yourself.

Here’s some code that opens a file, creates a parser, and sets the needed callback functions (You can find this code in the xml_parse.php file):

$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_set_element_handler($xml_parser, "start_element", "end_element");
xml_set_character_data_handler($xml_parser, "character_data");

if (!($fp = @fopen($file, "r"))) {
return false;

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",


This created a new parser with the xml_parser_create() function, and then defined some callback functions to run when events occur. In this example, I’ve indicated that the user-defined functions start_element(), end_element(), and character_data() will run when opening tags, closing tags, and character data are encountered, respectively. You’ll need to use these functions to create your internal PHP data sturcture.

Working with the callback functions can be a bit tricky. It’ll be easiest to begin by looking at the start_element() function:

function start_element($parser, $name, $attribs) {
global $current_element, $number_dicts;
if ($number_dicts>2){

From examining the iTunes library file, I know that I only want contents of elements that start after the third opening , where the song listing begins. So I keep a counter which tracks the number of opening s encountered. I only begin tracking element names when the counter indicates it has reached the third one. It’s important to note that the counter and the element name both need to be available as globals. The values need to be available to this and the other callback functions as the parser calls them.

The character_data() function doesn’t have to do much. It sets an element’s contents to a global variable and stays on the lookout for an element value of “Playlist.” When that value turns up, we know we’re done processing the song library:

function character_data($parser, $data) {
global $number_dicts, $current_data, $end_of_songs;
if($data=="Playlists") {

Now let’s look at the end_element() function, where most of the heavy lifting is done. As you can see from the brief code below, all it takes is a few lines to construct the array of songs:

function end_element($parser, $name) {
global $songs, $current_element, $current_data;
global $number_dicts, $array_key, $end_of_songs;
if(!empty($current_element)) {

XML processing with XPAT can get pretty complicated if your XML files are more sophisticated or if you need to track additional information. But the previous example should provide a basic introduction to working with XPAT.

XML Processing with DOM XML

The Document Object Model, or DOM, is a W3C standard that maps the structure of an XML document into a series of objects. You can access the document’s structure or manipulate the XML with a series of methods and properties. For example, working with the DOM, XML’s root element is considered a node, and from the root you can get a list of immediate children, add a child element, or remove a specific child. DOM methods also allow you to traverse an XML tree with great specificity, letting you get to the exact area of the document that you’re interested in.

Unlike the EXPAT functions, the DOM does not require you to build an internal data structure to store your XML—the structure of your XML tree is available within the DOM.

In my opinion, the DOM functions are easier to work with, though they do require more resources than the very lean XPAT functions. The function set is also very new; the PHP online manual urges caution when using this API.

It took very little code to manipulate the iTunes playlist with the DOM functions. (You can find this code in the dom_parse.php file.)


//$dicts will contain an array elements

//I'm interested in everything within the second dict tag
//that's where the entire music library is
//$childs will contain an array of .
//The sub-elements of each contain all song data.

$song_nodes = $dicts[1]->get_elements_by_tagname("dict");

// get the first "dict" object (the first object with song data)
$song_node = $song_nodes[0];

// now iterate through the song objects and their data
// using the next_sibling() method to move
$i = 0;

while ($song_node){
$data_node = $song_node->first_child();
if($data_node->node_name() != "#text") {
if($data_node->node_name() == "key"){ // found a key
}else{ // found the value for the current key
// now advance to the next data node
//at this level (within a song)
$data_node = $data_node->next_sibling();
// advance to the next song node
$song_node = $song_node->next_sibling();

Once you’ve run through this code, you can send $songs to the array processing functions shown earlier.


PHP is an easy-to-learn and flexible language. With dozens of extensions to choose from, PHP can provide all the power you need to create web applications on Mac OS X. And now that version 4.3 is here, it’s even easier to get PHP up and running on your system.


H appy Birthday GNU (Today In History)

LOTR; Fellowship enters Moria
• Twelfth night
1913: -50 degrees F (-46 C) in Strawberry, Utah
1940: FM radio demonstrated to FCC
1946: Producer, director, and Oscar winning actress Diane Keaton born Diane Hall in Los Angeles, California
1984: Richard Stallman begins GNU


Physics Exam Passed

I passed it. Now IMO the only difficult exam remaining is geometry.


Physics Test. TOMORROW

Tomorrow I have physics exam. I think physics is the most difficult lesson around the world even more difficult that calculus. However, I must pass this exam. Pray 4 me.
P.S: I wanna take a 3*4 portrait from myself which I'd upload that here.

فردا،از سلسله امتحانات ترم اول به امتحان فیزیک خواهیم رسید. بنا به نظر حقیر، فیزیک حتی از حسابان نیز سخت تر و مشکل تر می باشد.یا شاید برای من این گونه تداعی شده است. علی أی حال، امتحان باید گذرانده شود. ـ
در ضمن در صدد تهیه ی پرتره ای سه در چهار هستم که در اسرع وقت در وب نوشت نهاده خواهد شد.

You are Makin' me mad!!



There are some movies, which are mostly saddam's execution till right before his death. but his execution is not shown. Download this film to see his execution completely.
Sorry, This film is not appropriate for children under 16 years.
The extension is 3gp.
Download Complete Movie

Last Sunset of 2006 (photo)

I have taken these pictures on 31/12/2006, The Last sunset of 2006. Second is from through a binocular(click to enlarge):


What will happen in IT in 2007?

source: http://blogs.zdnet.com/Murphy/?p=763 by:Paul Murphy

Obviously the predictable stuff is predictable:

  1. Vista will make billions for Microsoft - driven by the warm embrace of those who hated the MacOS X interface when Microsoft didn't sell it;

  2. Itanium will continue on life support while Compaq, operating as HP, negotiates a way out with Intel;

  3. By the end of the year, the super computer listings will be entirely dominated by products built using IBM's cell processor -and the business applications performance benchmarks will be equally dominated by Sun's second generation CMT/SMP technologies.

  4. By the end of the year the OpenSolaris community will be widely recognised as larger and more active than the Linux community -and every competing OS developer community except Microsoft's will have copied the key ideas including its organisational structure, the core provisions in the community development license, and Solaris specific technologies including ZFS and Dtrace.

It gets more interesting when you step beyond the safe ground of the obvious stuff: for example, it's obvious that increasing public concern over the availability of identity information will, particularly in the United States, produce demands for political action - but it's not at all obvious what direction this will take or what the implications will be for IT management.

The big problem here, of course, is that in both the United States and most of Europe all the legislation needed is already on the books, what's missing is any willingness to enforce the law - sending, for example, the senior partners in an accounting firm to jail when some junior loses a laptop stuffed with pseudo-protected client data.

What's needed is first for someone in the United States to launch a national class action on behalf of the people affected by one of these "incidents," and secondly for the jury involved to vote substantial damages mainly on the basis of expert testimony to the effect that using Microsoft's client-server technologies to store and access identity related data is an industry dumbest practice. Completely obvious, of course, but also not likely to happen, so my guess is that a bad situation will simply continue to get worse during 2007.

Unfortunately whether an expected explosion of state level data management legislation will drive a corporate exodus to more failure friendly jurisdictions off shore to both Europe and the United States, or have the opposite effect - ending offshoring in favor of more local centers - will depend mostly on judicial interpretation of the initial legislation - and, as a coffee drinker, I have no tea leaves in that game.

What's obvious about some of 2006's hottest trends - SOA, Web 2.0 googlemania - is that these are acronyms covering contentless commentary and that neither the lack of substance nor the cheering will change as much as the acronyms do in 2007. In fact it's the cheering that's the point - something that's nicely echoed in "web 2" applications like YouTube and blogging where the essential emptiness of the nth echo chamber variation on a tiny set of common themes wears very thin, very quickly.

In that context, therefore, I'm going to predict that 2007 will see the beginnings of true structural convergence - meaning web based delivery of materials selected, controlled, and presented in traditional ways. Look, for example, for someone to offer a traditionally hosted "best of the web" video series comparable to TV's original "Real People" series, but presented in TV, multicast, and custom packaging.

Bottom line: you know what's going to be the best thing about IT in 2007? I do - it's that I don't have a clue how some of this stuff is going to play out. Will google go bye bye? will Linux resurge? will Apple license the PPC development rights for MacOS X to Microsoft? will Intel produce a credible product? will some HP executives finally go to jail? will Sun stop sabotaging Sun Ray? I have no idea - but you and I both have ring side seats - so bring it on already!

Happy New Year

Image from http://jeffline.jefferson.edu/
Finally, 2006 ended with its pros and cons. And now we are in the Year 2007.
Happy New Year