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.

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…

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!).

SpawEdit

March 6th, 2007 in Rants - No Comments

When I first wrote Authware I needed a WYSIWYG editor. I wanted one written in PHP that was basically drag and drop.

I couldn’t find a basic TinyMCE-PHP implementation back then. FCKEditor (it’s come a long way in the last two years) gave me a lot of bad code. By chance I came across Innovastudio‘s editor. It did everything it said it would — the problem was, it wasn’t free.

After some more scouring I came across Solemtra’s Spaw Editor. It gave me some pretty bad HTML code but I wrote a simple regexp matching function that converted all the uppercase tags (a la IE) to lowercase and did some font to span tag conversion.

Looking back now, am I glad I made the decision? You bet!

For one, it gives very very XHTML-compliant code now (no FONT tags + lowercase characters), works in Opera 9 (surprise!) and still has a nifty PHP class I can instantly plug in.

I’m off to look for a PHP Word to HTML parser. I need one badly :(.

Ethical Freelancing

March 5th, 2007 in Rants - No Comments

I’ve getting some extra pocket change for a while now by picking up freelance jobs. So far, I’ve been most successful with Scriptlance.

From an ethical viewpoint how do you respond to a [fishy] project that asks you to create 100 fake MySpace profiles or these ones that ask you to spam blogs, forums and social networks? On the one hand you’re making your cool money and on the other you’re contributing to problems.

Heck, I deal with spam everyday on my blogs. I wouldn’t want to help someone write a script that’d pass my own filters and hit my own blog.

Here’s the final clincher: a script to achieve higher appeal than MySpace between $100 and $500. If I had such an idea, I sure wouldn’t develop it and sell it for such a measly price.