My Blog

contains PHP and other web related content. (Sometimes there are some off topic things - don't freak out!)

Archive for April, 2009

IE JS Error: Expected identifier, string or number

Thursday, April 30th, 2009

I just ran into this a bunch – works fine in FireFox … of course.

Well apparently, Internet Explorer won’t allow you to have a trailing comma in a array or object definition. Let me show you:

?View Code JAVASCRIPT
1
2
3
4
functionCall({
        options: {1,2,3},
        others: {1,2,3},
});

The trailing comma after the other’s line is making IE expect another identifier. So, just strip it out so that line is now:

?View Code JAVASCRIPT
1
        others: {1,2,3}

And you should be golden!

Now, if only IE told me what line the error was on ;)

(For those who need a tip, I loaded up the site in firefox with jsview extension – and went to view all js. Then do ctrl-L to jump to a line – and type in the line number that IE mentions… see if there is something around there that looks like this scenario)

Flash of Unstyled Content – in FireFox 3

Tuesday, April 28th, 2009

So I’ve heard of the Flash of Unstyled Content before – but never really had this problem. I always use a LINK tag for my stylesheets.

However, I just ran into it today – in FireFox even with a LINK tag…

Fixing Flash of Unstyled Content in Firefox

Simple really – I was loading way too much javascript before my stylesheet (not my fault on the large amount of js!!) – and the delay was causing the flash. I moved the link to the very first part of the content – and presto – good to go.

So, instead of

1
2
3
4
5
6
7
<head>
<script src="#"></script>
<script src="#"></script>
<script src="#"></script>
<script src="#"></script>
<link href="#" type="text/css" rel="stylesheet" />
</head>

Just move it to the top:

1
2
3
4
5
6
7
<head>
<link href="#" type="text/css" rel="stylesheet" />
<script src="#"></script>
<script src="#"></script>
<script src="#"></script>
<script src="#"></script>
</head>

… next battle, getting rid of sooo much js ;)

Licensing of Code

Friday, April 24th, 2009

Up until now, I have not licensed my code properly. I’m going to try to do so from now on.

How is this code licensed?

The BSD license is how I’m going to proceed: http://creativecommons.org/licenses/BSD/

Elgg Development Tools – Elgg Plugin

Friday, April 24th, 2009

After working some with the open source Community building application Elgg, I found some settings to be irritating. I had to keep hacking my plugins to get these settings activated the way I wanted. Also, I really wanted to put useful settings in the same location.

Enter The Elgg Development Tools Plugin

This plugin has the following functionality:

  • Integrates FirePHP
  • Quick option to turn off view caching
  • Changes Error Reporting/Display
  • Copies other useful dev settings to one place

More about this after the file download:
Elgg Dev Tools

Integrates FirePHP

The package includes the latest distribution of FirePHP. When you enable FirePHP in the admin control panel under the Dev tools option, you can now use the FirePHP functionality in your plugins. Sometimes coders remember to turn off the functionality later, but forget to remove all of the FirePHP calls. A mock FB class is created to handle this – it basically accepts any method call and logs an error in the error log that you still have that line in there.

Turn off View Caching

Normally, you have to either run the update.php script or enable/disable your plugin. During development, this got super irritating. Instead, enable this option. It will make the site run a bit slower, but you won’t have to keep enabling/disabling the plugin when you add new views.

Display Errors

By default, Elgg hides the errors in the .htaccess file. This will turn them back on without editing the elgg installation.

Other Useful Dev Settings

I always forgot where simple cache options were. I copied the setting to the plugin as well. It basically does the same thing as under site admin. I find it useful to have all of these settings in one place.

Any feedback is greatly appreciated.

When PHP’s dirname() saved the day

Thursday, April 23rd, 2009

Now, I won’t bore you with the actual details of how I came across this – lets just skip to the explanation and example:

First, even when it makes ’sense’, you should not be using relative paths in your command line PHP scripts. I am so used to writing web PHP that I fell into this bad habit.

Show Me Why dirname() is your hero

Imagine a directory structure on windows like this:

C:\DEVELOPMENT\local>dir
 Volume in drive C has no label.
 Volume Serial Number is 1122-45E1

 Directory of C:\DEVELOPMENT\local

04/23/2009  08:40 PM              .
04/23/2009  08:40 PM              ..
04/23/2009  08:37 PM              includes
04/23/2009  08:40 PM              testdirname
               0 File(s)                    0 bytes
               4 Dir(s)  67,484,995,584 bytes free

We have two files:
testdirname/script.php

1
2
require_once '../includes/include.php';
print "I've done ran, ya'll.";

includes/include.php

1
print "I'm an include!\n";

Now, let’s run the script as it is:

C:\DEVELOPMENT\local\testdirname>php script.php
I'm an include!
I've done ran, ya'll.

Not too bad – but note how we’re actually in the script.php’s working directory. What if we wanted to run it in a different directory?

C:\DEVELOPMENT\local>php testdirname\script.php

Warning: require_once(../includes/include.php): failed to open stream: No such file or directory in C:\DEVELOPMENT\local\testdirname\script.php on line 2

Well this makes sense because I programmed with that relative path.

Instead, change the require line in script.php to this:

1
require_once dirname(__FILE__) . '/../includes/include.php';

This way, it always gets the full directory of the file itself (__FILE__ constant) – and THEN you can path to the file any which way you’d like.

Let’s check the output:

C:\DEVELOPMENT\local>php testdirname\script.php
I'm an include!
I've done ran, ya'll.

Yep – I KNOW – Simple. Its embarrassing to say it bit me – but it did :)

Form Submit: Internet Explorer behaving badly

Tuesday, April 14th, 2009

I just want to make a micro blog here. Just a tiny lil blog.

Internet Explorer Does Not Submit Form on Enter

Correct! Instead, I load my page with this jquery

1
2
3
4
5
6
    $('input').keydown(function(e){
        if (e.keyCode == 13) {
            $(this).parents('form').submit();
            return false;
        }
    });

Button Element Not Submitting in Internet Explorer

Correct! Mainly because I was lazy.

But in FireFox

Remove Internet Explorer Button Border

Thursday, April 9th, 2009

Internet Explorer provides an additional border to any BUTTON element in the page if you don’t explicitly assign a 0px border to it. i have a bunch of buttons on a design that I’d like to have a 1px #fff border on. Unfortunately, with the additional border that IE adds, it looks horrible.

The solution was to add a span around the button:

1
2
3
4
5
6
button { 
border: 0px;
}
.button {
border: 1px solid #fff;
}
1
<span class="button"><button>My Button</button></span>

Quick Reference: Simple MySQL Performance Monitoring

Tuesday, April 7th, 2009

There are a few quick ways to monitor MySQL performance. This isn’t much of an in-depth reference, just a quick reminder. Lets look:

mysqladmin status

Shows a quick status:

mysqladmin status
Uptime: 102594  Threads: 1  Questions: 39  Slow queries: 0  Opens: 12  Flush tables: 1  Open tables: 0  Queries per second avg: 0.000

mysqladmin processlist

Show the active processes and what they’re doing:

mysqladmin processlist
+----+------+----------------+----+---------+------+-------+------------------+
| Id | User | Host           | db | Command | Time | State | Info             |
+----+------+----------------+----+---------+------+-------+------------------+
| 25 | root | localhost:3185 |    | Query   | 0    |       | show processlist |
+----+------+----------------+----+---------+------+-------+------------------+

mysqladmin extended

This is short for extended-status, which shows you pretty much everything you want to know about the current system.

mysqladmin extended
+-----------------------------------+----------+
| Variable_name                     | Value    |
+-----------------------------------+----------+
| Aborted_clients                   | 0        |
| Aborted_connects                  | 8        |
| Binlog_cache_disk_use             | 0        |
| Binlog_cache_use                  | 0        |

| Threads_connected                 | 1        |
| Threads_created                   | 1        |
| Threads_running                   | 1        |
| Uptime                            | 102658   |
+-----------------------------------+----------+

Add iterations or relative comparisons with ‘-i’ and ‘-r’. For example, the following updates the list every 10 seconds with relative numbers (shows change well).

mysqladmin extended -i10 -r

Other Resources

MySQL.com’s explanation of some performance monitoring options
MyTop – top clone for mysql

Eclipse PDT2 won’t jump to functions/classes on ctrl-click: solved

Wednesday, April 1st, 2009

I am using the new PDT2 based off of Eclipse 3.4. The one thing I noticed as an issue for me was the building. I created a project based off of a checkout using SVN. After I had built the PHP project, I could not ctrl-click any of the functions that were part of my project. It just wouldn’t find them.

The solution for me was to configure the build path to include the project itself.

1. Right click on open project.
2. highlight build path
3. click on Configure build path…
4. Click Add Folder… button.
5. Put a check mark next to your project.
6. Click OK.

If necessary, click the project menu and choose the ‘clean…’ option to rebuild.

  • twitter loader

Follow me on twitter: @aaronsaray

The views on this website are my own and do not reflect the opinions of my employer or clients.
Creative Commons License Home | Open Source | Book | Music | Art | Bio | Resume | Contact
My Baby