Considering all the trouble I had to go through to get this working, I wouldn’t wish the same on anyone else.

http://www.mediafire.com/?5j1eem1zwhvpi5t

I first did this with CongreGATE.

Assumptions

1. You are using WordPress permalinks with mod_rewrite or a similar option.
2. You don’t have register_globals() turned on. Turn it off to ensure WordPress’s global variables don’t get removed by Kohana.

Renaming

First, you need to rename the __() function in Kohana. Say, you rename it to __t(). You’d need to replace it everywhere it appears, which if you use an editor like Netbeans that can find usages of a function or method is pretty easy.

Hierarchy

The next decision you need to make is whether you want to load WordPress inside Kohana or Kohana inside WordPress. I prefer the latter, which I’m documenting below.

I put the kohana directory in my theme directory.

In your functions.php file of your theme, simply

include TEMPLATEPATH . '/kohana/index.php';

SQL

April 26th, 2010 in Coding - 2 Comments

My ugliest SQL query — for posterity.

SELECT `wp_category`.`id` AS `category:id`, `wp_category`.`name` AS `category:name`, `wp_category`.`created` AS `category:created`, `wp_category`.`modified` AS `category:modified`, `wp_lib_items`.* FROM `wp_lib_items` LEFT OUTER JOIN `wp_lib_borrowers` ON (`wp_lib_items`.`id` = (SELECT `wp_b`.`id` FROM `wp_lib_borrowers` AS `wp_b` WHERE `wp_b`.`item_id` = wp_lib_items.id ORDER BY `wp_b`.`status` ASC LIMIT 1)) LEFT OUTER JOIN `wp_congregate_members` ON (`wp_lib_borrowers`.`member_id` = `wp_congregate_members`.`id`) LEFT JOIN `wp_lib_categories` AS `wp_category` ON (`wp_category`.`id` = `wp_lib_items`.`category_id`) ORDER BY IFNULL(NULLIF(`wp_lib_borrowers`.`due_date`, '0000-00-00'), '3333-33-33') DESC, `wp_lib_items`.`title` ASC LIMIT 10 OFFSET 0

Now I’m off to tango with PHP’s SplPriorityQueue.

Thanksgiving code

November 28th, 2008 in Coding, Rants - 1 Comment

I needed a script to loop through the letters of the alphabet and put this in an array: a-z, aa-zz, aaa-zzz, aaaa-zzzz, etc. Through a very rough approach, I’ve satisfied conditions 1-3, but not anything after (source code below).

[syntax,alg.phps,php]

So, all my problems are from the function get_items(). Basically, I don’t want to loop through the $used array to find out what values have a particular length. So based on my analysis, we have a theoretical function f(x, y) which gives the following when run:

f(1, 26) = 0	
f(2, 26) = 26	
f(3, 26) = 702
f(4, 26) = 18278

ie, the set {0, 26, 702, 18278, …}

f(2, 26) - f(1, 26) = 26      = 26 ^ 1
f(3, 26) - f(2, 26) = 676     = 26 ^ 2
f(4, 26) - f(3, 26) = 17576   = 26 ^ 3

Okay, now I see it clearly. Here goes:

[syntax,alg2.phps,php]

So, why do I need this? I have to do a test on an PHP-Ajax newsletter WordPress plugin. On a site I’m working on, we need to send emails to 70000 subscribers, and the current plugin loops through all the records in the database in one go. Of course the max execution time passes before then. I needed to generate a test database of 70000 emails @localhost.com to help me test while I rewrite the plugin.

Well, onto the actual rewrite.

Algorithms for Dummies

November 7th, 2008 in Coding, Rants - 2 Comments

I’m taking my second algorithm class this semester. So far, I think I understand a lot of the algorithms discussed in theory. The problem is translating them to code. Most of the algorithm textbooks I’ve come across are so technical, I haven’t the foggiest idea how to actually go on.

The biggest problem, I think is that I cannot even implement the most basic structure needed — a binary tree — not to talk of directed and undirected graphs. Not knowing doesn’t necessarily translate to not wanting to know, and the fact that I can’t write a simple Insertion-Sort algorithm kind of makes me feel down.

I’m dusting off my old C++ book and starting over again from arrays and linked lists. 🙁

If you happen to know where a poor coder-wannabe can get a simple algorithms book — with code examples — I’d be very grateful.

Code Profiling

April 27th, 2007 in Coding - No Comments

While running some tests on my local machine, I discovered a certain content item on Authware took between 2.5 and 2.9 seconds to load — when nearly every other one got loaded in less than 0.7 seconds. There were some basic references to clone — especially when determining the book name for a certain content item and discovering the book was it’s own parent — and I naturally erroneously assumed the overhead arose in those sections. Doing a manual copy of all the elements I needed instead of cloning changed nothing.

Something about code profiling from George Schlossnagle’s Advanced PHP Programming came back to me, and the hunt began. I must have been typing in the wrong stuff because only commercial products kept coming back until I got a Sitepoint article on XDebug.

Downloaded it, got WinCacheGrind and spotted the problem in less than a minute. That ‘nifty’ html_2_xhtml function I wrote sometime before when I was just starting out with regular expressions did a lot of arcane stuff with the e modifier of preg_replace.

Solution: swipe the wpautop and wptexturize functions from WordPress. The slow content item runs in less than 0.6 seconds now, and the other items take between 0.1 and 0.3 seconds to process. And er, the PHP website warns about using strstr just to determine if a needle exists in the haystack. Replacing it with strpos in my own version of wptexturize saw an increase in response times (by about 17 milliseconds).

Let’s hope I don’t keep profiling away instead of doing some real coding in the next few weeks.

So far

February 17th, 2007 in Coding - No Comments

We’re coming along nicely aren’t we?

Authware Screenshot

Hello world!

December 20th, 2006 in Coding - 1 Comment

At last, I shall be free to rant in peace. I’ll hopefully be moving most of my code section over here.

The old links to my page content will still work. I set up 301 redirects to the new content.

Working

October 22nd, 2006 in Coding - 5 Comments

I’ve already mocked up a design for Authware and tweaked the database layer — I was able to communicate successfully with PostgreSQL, MySQL and SQL Server. Hopefully, any other developer interested should be able to write a layer for mySQLite or some other obscure database. I used PHP 5’s Interface feature — the classes only have to implement it. I only have to work on the admin area and the different modules — it’s going to be tougher this time because I’m using pluggable functions like WordPress, a detailed permissions system, and perhaps XML-RPC.

I’ve been spending a while working with PHPBB3 Olympus, working on some obscure site for some [rich] clients (you may take this tongue-in-cheek). Without Zend Studio to help me explore the code, I daresay I’d have been truly doomed. What confounds me now is duplicating the registration and login codes to work out of the PHPBB concept without lumping together all the core PHPBB code together. So far, I’ve been chasing my tail running through myriads of functions that each make their contribution the the complexity of the code. The annoying thing is that since it’s in beta, there’s no code documentation — I have to make guesses and keep trying. What’s that joke — the last thing a coder wants to do is code.

Flex looks like one of those necessary evils — I remember PHP was when I had to give up ASP and recode a crazy site entirely in PHP. Ikezi’s been bombarding me with Flex UIs to no end but I guess what finally did the trick was Ms Dewey. Talk about a pretty girlish yet sophisticated bot who pouts and winks to no end at you, or looks out of the corner of her eye while doing something silly. As a search engine, it fails — as a seductive marketing ploy, well…

i55 ScreenshotI’m in charge of overhauling a site (http://www.i55.org) and moving it to Joomla. Here’s the test site [before it goes live].

I’ve been slaving away at this site for quite a while, rewriting components to fit the design I was given as much as possible. I proffer my work to the client, and he’s quite satisfied but what happens with the designer?

He’s angry I didn’t give the exact stuff shown in his PSD design. For one, I had considerably slimmed the site down from the former developer’s work, and tried to follow his design as best as I could, rewriting some components in some cases to make them fit. I’d originally been told by my client to ignore the styling if it wasn’t feasible.

Was this my punishment for trying to match the design I was given? Designers can be such a royal pain…