Tuesday, July 2, 2013

Installing PHP on Windows 7

Installing PHP on Windows 7

Microsoft have released the first public beta for their upcoming Windows 7 operating system. To me it looks surprisingly similar to Vista (which is a good thing and a bad thing ;-)), so I thought that installing PHP on it should be easy, as well. Actually, it was really easy, but since yesterday two people indenpendently from each other asked me how to do it, I thought I'd write down the required steps.
First of all, you need PHP (obviously). Go to the PHP download page and grab the latest non-thread-safe ZIP archive for Windows. As of writing this, the package is called "PHP 5.2.8 Non-thread-safe zip package". Unzip the archive to a folder on your hard disk (I use C:\php5) and create a copy of php.ini-recommended (or php.ini-production in recent PHP versions) called php.ini. There, add the following configuration setting:

cgi.force_redirect = 0

This is the minimum setting you need to change to make PHP work with IIS. You may also want to use cgi.fix_pathinfo = 1fastcgi.impersonate = 1, and setextension_dir appropriately.

Then it's time to install IIS. You need at least the "Business" version of Windows 7, but the currently available beta 1 is Windows 7 Ultimate anyway. Go to Start/Control Panel/Programs/Turn Windows Features on or off and check on the Internet Information Services entry. Activate the World Wide Web Services/Application Development Features/CGI node and also Web Management Tools/IIS Management Console (the latter not shown in the figure).



Now, start the IIS Management Console; just open up the start menu, enter inetmgr and hit Enter. There, navigate to the Sites/Default Web Site/Handler Mappings node and double-click on the "Handler Mappings" entry.



As a result of this, the Actions panel on the right hand side changes. You now see an option called Add Module Mapping. Clicking on it opens up a dialog which you fill out as you can see in the following figure (you may need to adapt the path used to your local system).



If you do not see the FastCgiModule entry, you probably forgot to check the CGI node when installing IIS. Otherwise, close the Add Module Mapping dialog by clicking on OK. You need to confirm that you want to create a FastCGI application; click Yes.



Finally, create a .php script and put it in the root folder of the IIS site (by default C:\Inetpub\wwwroot; note that you may need additional rights to write into that directory), e.g.phpinfo.php with a simple phpinfo() call in it. Call this script using http://localhost/phpinfo.php, and you are done!


Wednesday, May 15, 2013

Connect your computer to a domain



A domain is a collection of computers on a network with common rules and procedures that are administered as a unit. Each domain has a unique name. Typically, domains are used for workplace networks. To connect your computer to a domain, you'll need to know the name of the domain and have a valid user account on the domain.
  1. Open System by clicking the Start button Picture of the Start button, right-clicking Computer, and then clicking Properties.
  2. Under Computer name, domain, and workgroup settings, click Change settingsAdministrator permission required If you're prompted for an administrator password or confirmation, type the password or provide confirmation.
  3. Click the Computer Name tab, and then click Change. Alternatively, click Network ID to use the Join a Domain or Workgroup wizard to automate the process of connecting to a domain and creating a domain user account on your computer.
  4. Under Member of, click Domain.
    Picture of the Computer Name/Domain Changes dialog boxThe Computer Name/Domain Changes dialog box
  5. Type the name of the domain that you want to join, and then click OK.
    You will be asked to type your user name and password for the domain.
    Once you are successfully joined to the domain, you will be prompted to restart your computer. You must restart your computer before the changes take effect.

Thursday, May 9, 2013

Cross domain Ajax request



The only (easy) way to get cross-domain data using AJAX is to use a server side language as the proxy as Andy E noted. Here's a small sample how to implement that using jQuery:
The jQuery part:
$.ajax({
    url: 'proxy.php',
    type: 'POST',
    data: {
        address: 'http://www.google.com'
    },
    success: function(response) {
        // response now contains full HTML of google.com
    }
});
And the PHP (proxy.php):
echo file_get_contents($_POST['address']);
Simple as that. Just be aware of what you can or cannot do with the scraped data.

Monday, April 29, 2013

java command-line input

import java.io.*;

public class ReadString {

   public static void main (String[] args) {

      //  prompt the user to enter their name
      System.out.print("Enter your name: ");

      //  open up standard input
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      String userName = null;

      //  read the username from the command-line; need to use try/catch with the
      //  readLine() method
      try {
         userName = br.readLine();
      } catch (IOException ioe) {
         System.out.println("IO error trying to read your name!");
         System.exit(1);
      }

      System.out.println("Thanks for the name, " + userName);

   }

}  // end of ReadString class

Monday, April 22, 2013

Raster Data and Vector Data


Raster and vector are the two basic data structures for storing and manipulating images and graphics data on a computer. Major GIS and CAD (Computer Aided Design) software packages available today are primarily based on one of the two structures, either raster based or vector based, while they have some extended functions to support other data structures.

Raster images come in the form of individual pixels, and each spatial location or resolution element has a pixel associated where the pixel value indicates the attribute, such as color, elevation, or an ID number. Raster images are normally acquired by optical scanner, digital CCD camera and other raster imaging devices. Its spatial resolution is determined by the resolution of the acquisition device and the quality of the original data source. Because a raster image has to have pixels for all spatial locations, it is strictly limited by how big a spatial area it can represent. When increasing the spatial resolution by 2 times, the total size of a two-dimensional raster image will increase by 4 times because the number of pixels is doubled in both X and Y dimensions. The same is true when a larger area is to be covered when using same spatial resolution.

Vector data comes in the form of points and lines that are geometrically and mathematically associated. Points are stored using the coordinates, for example, a two-dimensional point is stored as (x, y). Lines are stored as a series of point pairs, where each pair represents a straight line segment, for example, (x1, y1) and (x2, y2) indicating a line from (x1, y1) to (x2, y2).

In general, vector data structure produces smaller file size than raster image because a raster image needs space for all pixels while only point coordinates are stored in vector representation. This is particularly true in the case when the graphics or images have large homogenous regions and the boundaries and shapes are the primary interest. Besides the size issue, vector data is easier than raster data to handle on a computer because it has fewer data items and it is more flexible to be adjusted for different scale, for example, a projection system in mapping application. This makes vector data structure the apparent choice for most mapping, GIS and CAD software packages. Also, topology among graphical objects or items are much easier to be represented using vector form, since a commonly shared edge can be easily defined according to its left and right side polygons. On the other hand, this is almost impossible or very difficult to do with pixels.

Wednesday, April 3, 2013

Pushing Negation Inward


DeMorgan's Theorem

DeMorgan's Theorem has to do with negating conditions whose main operator are conditional AND and conditional OR. This is && and ||.Let's think about DeMorgan's Theorem. Suppose I say "I am going to buy you ice cream AND I am going to buy you cookies". When would I be lying? That is, when would the negation of what I say be true?
Suppose I just bought ice cream. Then I'd be lying, since I told you I'd also get cookies. Similarly, if I bought just cookies, then I didn't buy ice cream. Certainly, I'm lying if I don't buy you anything. Thus, I am lying if "I don't buy you ice cream OR I don't buy you cookies".
This OR is considered inclusive.
If I had said "I am going to buy you ice cream OR I am going to buy you cookies", I could also buy both.
Now let's consider the negation of the OR statement. When would I be lying?
Suppose I just bought ice cream. That's OK, because I said I'd buy one or the other. Suppose I bought cookies. That's fine too. Suppose I bought both ice cream and cookies. Well, you can't say I lied, right? What if I didn't buy either? Then, I'm lying.
So the negation of the OR statement is "I am not going to buy you ice cream AND I am not going to buy you cookies".
Both these equivalences make up DeMorgan's Theorem.
  • ! ( exprleft && exprright ) is equivalent to ! exprleft || ! exprright )
  • ! ( exprleft || exprright ) is equivalent to ! exprleft && ! exprright )
We didn't get rid of the !, but we did move it closer to the expression. If the expression contains a relational or equality operator, we can use the rules above to negate them. If they contain logical operators, we can apply DeMorgan's again. Eventually we get rid of the !.

Pushing Negation Inward

One way of looking at DeMorgan's Theorem is that it pushes negations inward. Initially, we had the ! operator applied to a large expression, then we pushed it to a smaller subexpression. We also flip AND to OR, and OR to AND.Now, DeMorgan's Theorem is an equality, which means that we can push negations outwards too (just do the reverse). However, mostly you push negations inward.