Jan
24
2008

Idiots Guide to Installing PHP



Posted in Programming and Technology

If you have hosting with Dreamhost or any other host which gives you a shell account, you can install your own custom version of PHP. I needed to compile PHP with GMP support for the OpenID login plugin for WordPress, so I spent the whole day tweaking trying to get everything working. There's a page on Dreamhost's Wiki which has a script, but it still took me hours to get right. I've written a quick guide to help avoid the mistakes which slowed me down.

  1. The first thing you need to do is download Putty and set it up to connect to your host.
  2. We're going to create a few shell scripts to install PHP and all the other packages it requires. It's probably easiest to make your edits in notepad or another text editor, then copy and paste them into Putty by right-clicking. If you just create the files then upload them, there tend to be problems with line breaks and the script doesn't work.
  3. Start by downloading the preparation script and the installation script. Open them with a text edtitor and change the line export DOMAIN="yourdomainhere.com" to match the domain you're installing the CGI script on. This should be the directory the domain is served from. Eg: If your site serves files from /home/someone/xyz.com, use xyz.com. The version information may need updating, because I won't be updating this script.
  4. The first script we need to set up will download the different packages and extract them. Once you're done editing, hit CTRL+A in your text editor, then copy everything to your clipboard. Create a new file by typing nano php_prep.sh at the command prompt.
  5. Paste the contents of your clipboard into the new file by right clicking in Putty, then hit CTRL+O to save the file, then CTRL+X to exit nano.
  6. In *nix you need to make files excutable before you can run them. Do this by typing chmod +x php_prep.sh
  7. Now we need to set up the script which does the installing. Create a new file by typing nano php_inst.sh at the prompt, then copy and paste the contents of your edited php_inst.sh file by right clicking the terminal. Hit CTRL+O, Return, then CTRL+X to save and exit.
  8. Make the file executable by typing chmod +x php_inst.sh
  9. Now that everything's set up, we can run the first script by typing ./php_prep.sh at the prompt. It might take a while but if there are no errors you should eventually see "Done downloading and unpacking prerequisites".
  10. Run the installation script using ./php_inst.sh . This might take a while to complete, so start solitaire or something.
  11. When everything's finished, you should see "INSTALL COMPLETE!" and have a shiny new custom version of PHP installed.
  12. If you don't already have one, create a .htaccess file at the root of your domain. You can do this by typing nano .htaccess. Add the following lines:
    Options +ExecCGI
    AddHandler php-cgi .php
    Action php-cgi /cgi-bin/php.cgi
  13. That should be it. If there were no errors, you can test your installation by viewing a PHP file on your site. Hopefully you'll either see no change, but it's possible you'll see a load of errors.

If you have problems installing, the Dreamhost forums might be a good place to ask for help.

Jan
10
2008

Java Methods for TreeNodes



Posted in Programming

Two pretty useful Java methods. They're both related to JTrees, but should have been included as built in methods really.

The first returns a treepath given an object. Once you have a JTree, you may need to get the path to the node that contains that object (to scroll the JTree to that object for example). It's a recursive function so it doesn't matter how many levels your JTree contains.

    private TreePath getPathToNode(DefaultMutableTreeNode node, Object obj) {
	System.out.println("Looking for "+obj.toString()+" in "+node.toString());
        if(node.toString().equals(obj.toString())) {
            return new TreePath(node.getPath());
        } else {
            for(Enumeration theChildren = node.children(); theChildren.hasMoreElements();) {
                DefaultMutableTreeNode thisNode = (DefaultMutableTreeNode)theChildren.nextElement();
                if(thisNode.toString().equals(obj.toString())) {
                    System.out.println("Found node at "+new TreePath(thisNode.getPath()));
                    return new TreePath(thisNode.getPath());
                } else if(thisNode.getChildCount()>0) {
                    for(Enumeration grandChildren = thisNode.children(); grandChildren.hasMoreElements();) {
                        DefaultMutableTreeNode grandChild = (DefaultMutableTreeNode)grandChildren.nextElement();
                        TreePath n = getPathToNode(grandChild, obj);
                        if(n != null) {
                            return n; // if the call returns anything but null, we've found the node
                        }
                    }
                }
            }
            System.out.println("Node not found");
            return null;
        }
    }

The second returns a DefaultMutableTreeNode given an object. It recursively searches the JTree until it finds the object matching the one you pass to it, then returns the node containing that object.

    private DefaultMutableTreeNode getNodeFromName(DefaultMutableTreeNode node, Object obj) {
        // Used to scroll the JTree to the current account
        for(Enumeration theChildren = node.children(); theChildren.hasMoreElements();) {
            DefaultMutableTreeNode thisNode = (DefaultMutableTreeNode)theChildren.nextElement();
            if(thisNode.toString().equals(obj.toString())) {
                return thisNode;
            } else {
                if(thisNode.getChildCount()>0) {
                    for(Enumeration grandChildren = thisNode.children(); grandChildren.hasMoreElements();) {
                        DefaultMutableTreeNode grandChild = (DefaultMutableTreeNode)grandChildren.nextElement();
                        DefaultMutableTreeNode n = getNodeFromName(grandChild, obj);
                        if(n != null) {
                            return n; // if the call returns anything but null, we've found the node
                        }
                    }
                }
            }
        }
        System.out.println("Node not found");
        return null;
    }
Dec
20
2007

in_array() and implode() for Java



Posted in Programming and Technology

I'm still getting to grips with Java, but there a few functions I miss coming from PHP. in_array lacks a Java equivalent, as does the implode function. Here are the equvalent methods in Java:

implode()

static String implode(String[] ary, String delim) {
    String out = "";
    for(int i=0; i<ary.length; i++) {
        if(i!=0) { out += delim; }
        out += ary[i];
    }
    return out;
}

in_array()

private boolean in_array(DefaultListModel haystack, String needle) {
    for(int i=0;i<haystack.size();i++) {
        if(haystack.get(i).toString().equals(needle)) {
            return true;
        }
    }
    return false;
}
Dec
9
2007

Limit and Offset clauses in MSSQL



Posted in Programming and Technology

Until SQL server 2008's released, there’s no easy way to page reults or only show the first n results. I searched around for a while until I found this on MSDN.

SELECT TOP limitnumber
    FROM (
        SELECT TOP (limitnumber/ offset) * limitnumber) * 
        FROM tablename 
            AS T1 
            WHERE clauses 
            ORDER BY sortfield DESC) 
        AS T2 
        ORDER BY sortfield ASC;

The LIMIT and OFFSET values are the same as in PostgreSQL or MySQL. limitnumber is the number to show per page, and offset is the starting row.

MSDN Article

Nov
27
2007

More Space on Your iPod Touch



Posted in Technology

I bought a shiny new iPod touch, and after unlocking it to install custom applications, I soon filled the 300Mb applications partition. If you need more than 300Mb for apps (which you more than likely will if you install more than a couple), you can create a sym link to the music partition.

  1. SSH into your iPod using a client such as Putty with the iPod's IP address, user: root, password: alpine.
  2. Move the applications folder to /private/var/Applications by typing mv /Applications /private/var/Applications
  3. Change directory to / by typing cd /
  4. Create a link to the new applications directory: ln -s /private/var/Applications Applications
  5. Now when you list the directory using ls -la, you should see something like lrwxr-xr-x 1 root admin 25 Oct 12 22:31 Applications -> /private/var/Applications
  6. Reboot your iPhone and fill up yet more space with useless applications!

[Via: MacRumours]

Nov
14
2007

Inserting Multiple Rows with MSSQL



Posted in Programming and Technology

I've been working on adding support for Microsoft SQL Server to iZeit, and there are a few things I've noticed. Firstly, whereas you can addin multiple rows in MySQL or Postgres by using

INSERT INTO tablename (field1,field2,field3) VALUES (r1c1, r1c2, r1c3), (r2c1,r2c2,r2c3)

MSSQL fails and throws an error. Instead, you have to use UNION ALL, which I always thought was more resource intensive.

INSERT INTO tablename (field1,field2,field3) SELECT (r1c1, r1c2, r1c3) UNION ALL SELECT (r2c1,r2c2,r2c3)

The second major annoyance is that MSSQL doesn't like ORDER BY clauses with text fields. Understandably you can't sort a field containing an image, but why can't it sort a text field alphabetically? One thing I still haven't found a workaround for is the LIMIT and OFFSET clauses, which MSSQL doesn't support.

Nov
5
2007

Britons Send 4Billion Texts per Week



Posted in Latest news and Technology

Britons are now sending more then 4 billion texts weekly. That's more than were sent in the whole of 1999 and 25% more than one year ago. In September, 4.8 billion texts were sent, about 4,000 per second!

That’s some furious texting. People would be better off with Blackberrys though…

Read More [BBC News]

Oct
17
2007

Quid: The New Space Currency



Posted in Latest news and Technology

Quid space currency

Scientists have devised a new currency to be used in space. The Quid 'coins' are made from a polymer which unlike credit cards or regular coins, have no sharp edges which could damage space suits.

The Quid is expected to be used in the upcoming inflatable space hotel and aboard Virgin's SpaceShipTwo.

The current exchange rate is about 1 Quid to £6.25.

Read more [BBC News]

Oct
4
2007

Film references in The Simpsons



Posted in Funny

Nothing makes you feel more like a telly-addict than when someone makes a geeky reference to a Sci-fi show and everyone knows exactly what they mean. This site has a list of Simpsons scenes and which films they came from. It looks like Matt Groening's even more of a telly-addict than me.

Simpsons References

Source [Via: nodomain.cc]

Oct
1
2007

8k for a Paintball Panzer



Posted in Funny and Technology

Paintball Panzer

It might seem like a lot of money, but when you think you could have your own road-legal panzer to protect you from the agony of being hit by paintballs, £8,000 doesn't seem that much. It also has a working paintball cannon.

I Want One of Those [ Via: Gizmodo]

Sep
23
2007

Dell XPS M1330 Review



Posted in Site news

I've just finished my review of Dell's XPS M1330. The wait time was longer than I expected, but it was worth it.

Read the full review

Sep
14
2007

Grab some Firethreads



Posted in Internet

Mozilla has opened a new store selling all sort of Firefox goodies. It’s bordering on overly-geeky, but isn't it worth sacrificing your dignity to support open source?

MozillaStore

The Mozilla Store [Via: UneasySilence]

Sep
8
2007

Visualise site popularity with TouchGraph



Posted in Internet

TouchGraph lets you see a visual spider diagram for any keyword or site. Interesting to see who’s linked to you and from where, and which of your pages are most popular.

TouchGraph

TouchGraph

Sep
7
2007

Creating a Bootable USB Flash Drive



Posted in Technology

I spent hours yesterday trying to get my laptop to boot from a USB key. I could probably have burnt 100 bootable CDs with the files on, but I wanted a USB key. So here's how to create one.

  1. Download and extract these files. Included are files for a bootable floppy and a copy of the HP USB disk format utility.
  2. Using the HP format utility (HPUSBFW.exe), check "Create a DOS boot disk" and browse to where you extracted the "DOS files" directory.
  3. That's it!. Automated commands can be run using autoexec.bat
Aug
17
2007

Restart Windows without rebooting



Posted in Internet

Something I've never known. You can restart windows without waiting 30 seconds for your BIOS to finish loading

Windows Vista: Select Start, then hover over the arrow to the right of the padlock icon until the pop-up menu appears. Hold down the SHIFT key while clicking "Restart".

Windows XP: Select Start, then "Shut Down…". Change the drop-down box "Restart". Hold down the SHIFT key while clicking OK

You could probably do the same in Windows 3.11 by dropping to a DOS shell and typing "win".

[Via: CodeJacked]



18 Pages«12345»...Last »