PHP


Another good example of a PHP “quirk” is the way PHP handles constants. It was one of the major factors affecting performance. Just removing all the constants allowed us to improve the performance by almost 2x (we left one constant to be precise).

From The Need for Speed.

That’s right - PHP is up to 2X faster if you don’t use constants. You know, that means hardcode values in…

View Comments (2)   RSS Feed for Comments on this Post

I never thought I’d manage to find a job coding in python for a living. But that is what my full-time job is, right now, anyway.

I can’t really talk about the work I’m doing, since it is a commercial enterprise, but I can talk about what sort of things I am coding. I have spent the last couple of weeks rebuilding a server in python that uses SOAP to communicate with the outside world (well, a client application, anyway) over SSL connections. Python is used so it is easily extensible, without having to recompile. Eventually it will be dynamic, where new modules can be added to a database, and depending on the userid of a request, a different function will be called. It’s really quite exciting.

I’ve come across a couple of new software programs - one of which is NX (nomachine) Client, which is a remote tunnel for X windowing. I can remote in via this to work from home, as well as ssh or sftp. Which is fairly cool. Speedier than VNC, since I think the local X-Windowing system is responsible for some of the drawing tasks. Feels about the same over ADSL as ARD does over WLAN.

In my “free” time I’ve been doing a couple of other things, both programming tasks. The first is a web application for an art gallery to create HTML and PDF invitations and newsletters. Originally I planned to use a web app so that it could eventually be rolled out as a blog-alike - in fact originally it was just going to be a WordPress installation with some minor modifications. It turned out to be easier to rewrite it from scratch. I have learned from this process that PHP is crap: it’s never clear about the way to do stuff, and many functions have weird names. count_chars, for instance, doesn’t really count the characters, unless you decide that things like #@! aren’t characters. In which case you want strlen. Which had me tricked for some time, since I stopped looking once I had found count_chars. Python and len(anything) is much better.

Speaking of python (again), I’ve also been working on a Regular Expression helper - similar to the one that comes with Komodo IDE. I started (and pretty much finished, in a matter of hours, to the extent it solved my first use problem) this after having to load up Komodo just to get a visual representation of which bits of a text block were being matched by a regex. Still some kinks to work out - I need to figure out how to put stuff into an outline view, so I can see more than just matches, but match groups. Then it will be all good.

In the process of my work job, I downloaded SOAP Client, a freeware tool for testing SOAP packets. It was all good until I tried sending HTTPS requests, which it fails unfathomably on (cannot connect to endpoint…). I emailed the author, and he then promptly released the source code. I’ve snaffled that from Google Code, and I’ll try to hack through it a bit to implement SSL connections. Not sure how to go about it at this stage - dunno if it is with WebKit or something else I need to do. I also plan to add in the ability to edit the SOAP request manually before it is sent off to the server.

I start Uni in a couple of weeks - I’m doing an introductory Java course in intensive mode, which I expect to be fairly easy. I’m really only doing it so I can do the meatier sounding subjects, like Programming Language Concepts and Systems Programming. I really think I’m going to enjoy this course. I will be interested when I come to the Internet Computing subject, since I’ve been doing a fair bit of that in various forms over the past few years. Be interesting to see what the academics think it means.

Well, that’s been my life over the time period since coming back from the beach for a 10 day holiday over New Year. Apart from squeezing in a few games of Touch Football here and there, I’ve pretty much been chained to my laptop.

And loving it.

View Comments (0)   RSS Feed for Comments on this Post

Doesn’t seem to be working properly.

View Comment (1)   RSS Feed for Comments on this Post

Well, I’ve moved over from Blogsome to NearlyFreeSpeech.net

It’s very cool, and looks to be pretty cheap. I might have a high bandwidth bill for the last two days as I had to keep uploading SQL dump files (much faster than editing using nano over ssh!).

When I imported all of my comments, the posts weren’t updated with the number of comments they each had, so I needed to run the following PHP script:

<?php
require_once('admin.php');
echo "Approving comments...";
// Approve all comments
$wpdb->query("UPDATE $wpdb->comments SET comment_approved = '1'");
echo "Updating post counts...";
// Populate comment_count field of posts table
$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
if( is_array( $comments ) ) {
foreach ($comments as $comment) {
$wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID'" );
}
}
echo "Done.";
?>
View Comments (0)   RSS Feed for Comments on this Post

I’ve commented before on how people use my template conversion, and remove the attribution to myself, and more importantly to Patricia, the original person who did all of the work on the template for vanilla wordpress.

What is quite funny is that they remove the tags that attribute me, but usually leave in the AdSense code. Which means anyone clicking on ads on their blog will be doing me a favour.

Not that I’ve ever got anything from AdSense. I can’t even log in, since there is a clash between my original AdSense login and my new hosted domain google account. Which they haven’t fixed, last time I checked.

Perhaps I should write into the code that attribution needs to be left in. I must check…

View Comments (7)   RSS Feed for Comments on this Post

Internet Explorer has some interesting foibles. And by interesting, I mean annoying.

For instance, if I’ve visited a page on my site, such as:

http://schinckel.blogsome.com/wp-admin/

Internet Explorer seems to remember it as

http://schinckel.blogsome.com/wp-admin

Notice that the trailing slash is missing. Blogsome will report that “Page Does Not Exist”, or if it looks like a Post page, “No posts made”.

With access to the HTTP server, this would be easy to fix (just create a rule in the relevant place that allows for URLs of this form), but on Blogsome this is a bit harder. You need to be able to check the last character of the URL string, and if it isn’t a /, append one. This should work fairly well in all cases, since every reader visible URL ends in a /.

So how to do this? Getting the URL is easy: {$smarty.server.REQUEST_URI}. However, getting the last character is a bit more difficult. Or so it appears. But Smarty allows for accessing strings as an array, so {$smarty.server.REQUEST_URI[0]} will get the first character. To get the last is a therefore possible. {$smarty.server.REQUEST_URI[-1]} fails, so I’ll need to get the length of the string.

{$smarty.server.REQUEST_URI[$smarty.server.REQUEST_URI|count_characters ]}

also fails, but

{$smarty.server.REQUEST_URI[smarty.server.REQUEST_URI|count_characters ]}

works.

Now, we just need to test if this value is “/”, and if it isn’t, then reload the page with that added.

Which I can’t seem to figure out how to do with Smarty…

Of course, doing the same with JavaScript is a piece of cake:

if (document.URL[document.URL.length-1] != “/”)
    document.location = document.URL + ‘/’

View Comments (0)   RSS Feed for Comments on this Post

Thanks to some simple Smarty capture and comparisons, it’s possible to have custom error pages in Blogsome.

Read about how to do it at : About How to customize a 404 error page in your free Wordpress blog November 2006 - WebTips

See it in action at /404/

View Comments (0)   RSS Feed for Comments on this Post

…on such a Winter’s Day.

California Dreamin’ • “Room Service” • José Feliciano ★★★

Okay, that’s just a silly lead-in to what I’m going to post about.

For some time, I’ve been trying to get Category Pages to handle a bit nicer in Blogsome. I needed to be able to get a Category ID from a Category name, and I hadn’t figured out how to. I’d basically given up.

Then I found my new best friend, {get_cat_ID cat_name='Cat_Name'}. He allows me to do this. And much easier than I thought it would be, too.

{if $smarty.server.REQUEST_URI|truncate:10:'':1 == '/category/'}
    {capture name=cat}{single_cat_title}{/capture}
    {capture name=catID}{get_cat_ID cat_name=$smarty.capture.cat}{/capture}
{/if}

Now, how do we use this to get child categories?
{list_cats optionall='0' list='false' child_of='$smarty.capture.catID'}

This appears to not work, as it continues to get all of the categories. I think there is an issue with child_of, at least on Blogsome.

{get_category_children id=$smarty.capture.catID}
Only generates the IDs of the child categories. Useful, but not excellent for my uses.

However, there exists also a function called {wp_list_cats}, which allows for arguments in the for &arg=value.

{wp_list_cats args=“&child_of=`$smarty.capture.catID`”}

Notably, you must use double quotes when trying to embed a variable inside an argument.

Final code (not counting CSS, that’s up to you - or look in my StyleSheet):

{if $smarty.server.REQUEST_URI|truncate:10:'':1 == '/category/'}
    {*Category Index Page*}
    <div class=“catNav”>
        {capture name=cat}{single_cat_title}{/capture}
        {capture name=catID}{get_cat_ID cat_name=$smarty.capture.cat}{/capture}
        Currently browsing {get_category_parents category=“`$smarty.capture.catID`” link=“1” separator=“&raquo;”}</em>, which has sub-categories <ul class=“inlineCatList”>{wp_list_cats args=“&&list=0&children=0&child_of=`$smarty.capture.catID`”}</ul>
    </div>
{/if}

And, thanks to minimalnet, since because of the post in the forums [How can i show the Dashboard Blog Stats in my blog?], I began scouring the source code again.

Summer The First TimeBobby GoldsboroRoom Service

View Comments (0)   RSS Feed for Comments on this Post

Eugenia (who used to write for BeOS sites, back in the day) wanted to know how to stop comments from being posted on posts that are over 10 days. I’ll generalize this to X days, just for completeness.
(more…)

View Comments (4)   RSS Feed for Comments on this Post

I’ve been racking my brain thinking about how to get child categories of a specific category.  And I think I’ve just figured it out.

Examine all of the other categories in a complete list, and grab all of them that have the current page’s URL at the start.  The next word will be the sub-category .

Of course, knowing how to split stuff in Smarty is a bit difficult.  I was thinking in JavaScript…

It Don’t HurtSheryl CrowThe Globe Sessions ★★½

View Comments (0)   RSS Feed for Comments on this Post

Next Page »