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.

CakePHP

April 23rd, 2008 in Journal - No Comments

I’m rewriting Authware at the moment using CakePHP.

I figured I had to learn something about MVC sometime, but here I am doing so — and it isn’t funny.

Ruby (on Rails)

February 3rd, 2008 in Rants - 1 Comment

Back when I still had a print subscription to Linux Journal, I read an interview of David Hansson, creator of rails and thought, ‘wow, this is cool!’

My friend Kwame had a book on Ruby which I perused and found the language was relatively simple. Now for such a simple, amazing language — and framework — one would think the install process was just as easy. Well, it isn’t 00 at least not to me.

I read tutorials on the arcane of the arcane, built it myself and whatnot and in the end couldn’t get it to run on my Windows machine — not that it was present in the online repositories to get it for my Fedora machine.

My answer? Screw rails. If I need a framework I’ll go for Cake — but we all know I won’t. After all, I’m very egotistical and want to try writing everything out myself.

Isn’t there some way to disable this or move it further down in Firefox? Why does it have to be at the top? Everytime I righ-click a link, I intend to open it in a new tab. I hate new windows!

The crazy context menu item just keeps getting in my way…

This would have been one of the coolest additions to SQL. Programmers are lazy, always looking for a way to avoid writing more code and I suppose this is one area I fit the norm. I need to select all the fields from a 20-column table… except one.

Doing a Google search, it’s apparent I’m not the only one who’s looking for such a feature. I know, I know. I could have written the column names manually during the time I typed this.

I’ve been tearing out my hair trying to figure out how to have persistent sessions on the client. Okay, I’ve done it before on several projects but those ones didn’t use a database-based session handler.

I’ve called session_set_cookie_params to no avail everywhere in my code — the time in the db’s correct, but the session always expires when the browser is closed. Setting the session cookie myself gives a different problem — it gets invalidated on the next page load.

Arrrrrrrgh! I hope it really is because I’m running it on a local domain. If it isn’t, I just might get angry, download the PHP source, learn C and rewrite PHP in no particular order (I wish!).