Categories
Funny Programming

And I was coding… and stumbled upon AI

Well, I decided I would take a stab at AI (Artificial Intelligence). I always found it mind blowing that people are actually trying to do that with technology. Just amazing. So I thought I’d try and simplify AI down to 1 function. Since I believe that essentially life can be made into 1 function.

< ?php
function analyzeReproduction($person) {
  if ((sizeof($person[‘penis’]) < 5) || $person[‘job’] == "programmer"){
    unlink("/usr/local/bin/sex");
    exec("/usr/local/bin/masturbate");
    $resultVar = 0;
  } else {
    exec("set SEXLIVE=true");
    exec("set GREATSEX=true");
    exec("set HOTGIRLS=true");
    exec("/usr/bin/woohoo");
    exec("/usr/bin/ahh");
    $resultVar = 1;
  }
  return $resultVar;
}
?>

Anyone want to guess how it returned when I ran it?

Categories
Programming

How do you code your DB calls?

Well, I’ve got a few options that I see, so I open it up to see what others do. For this discussion, we shall be referring to a mySQL table with the following columns:

FirstName | LastName | Address | Address2 | City | State | Zip | Email | Comments | Sex | Food | Age | HotOrNot

Now we access this table several dozen times for various reasons. Each time, we need different things. Sometimes, only the first name of one individual, sometimes several things, sometimes all data for an individual, or a list of individuals.

Now… we want to be fast and efficient. But want clean and manageable code.

Say for examples sake, we need to get all fields for all users for one particular page of the site. For another, we only need a certain 3. For another, only a certain 2.

What is the best method to do this? Create a separate DB query for each option? Create 1 function that dynamically creates the query based on what fields you want? Just select all data that matches the query, and use what you want?

The reason this comes up is I was working on something similar the other night, and discussing this recently. Here were the basic points:

  • Many DB calls is tough to maintain. Say you want to change DB’s, or update the code for whatever reason. That’s lots of changes.
  • You can just select all data for the query. But then you have lots of data being selected. Not good for a giant database.
  • Generating a DB call can be messy, complex, and of course slow, depending on how complex they can get.

I”ve seen it done all ways. Do people to generate the SQL ‘on demand’? Hard code all of it? Or just select every column in the query, and use what you want?

I’m curious what people choose, and most importantly, why? What makes that option outweigh the others? Alternative methods welcome of course πŸ˜‰

I’m mainly referring to PHP and mySQL, but if you want to bring in Perl, JSP, or other DB’s like Oracle, feel free.

Yes, this is an uber-geeky, perfectionist, strongly geek opinionated conversation. I’m sure some will feel there is one, and only one way to do this. And all others are extremely wrong. But debate is a good thing. Just keep it under control, I hate moderating.

Categories
Programming

Robert’s Book Club: PHP Books

Well what PHP books do you recommend for someone who wants to enhance already pretty solid understanding of the language? I’ve got a rather good level of experience, but want some reference, and good tips on getting better (there’s always room to improve).

MySQL, Second Edition

Programming PHP

PHP Cookbook

Web Database Applications with PHP & MySQL

Advanced PHP Programming

I can’t decide, they all look pretty interesting. Anyone read any of these? Good? Bad? Recommend another?

This ain’t no Opera’s Book Club. πŸ˜‰

Categories
Programming

vLIB rules

If your a PHP developer, and you don’t know about it yet, check out vLIB. I’ve worked quite a bit with templating for a few years now. I think this is the best library for implementing templates in a PHP application I’ve seen. It’s got a good amount of flexibility, and it’s easy to implement. Not to mention is’s nice and fast.

I’ve written several very crummy templating systems for my own stuff over the years. And they stink compared to this. Honestly. I’ve decided to throw them out and port over to vLIB.

I hate PHP Apps with HTML all over. Eventually they are doomed to become impossible to maintain. At least with templating, it’s easy.

Categories
Programming

PHP Class to prevent automated signups

If anyone knows of a good PHP class (must be open source license) that will display one of those CAPTCHA images with text that must be entred to deter bots (like what Network Solutions does for whois), I’d greatly appreciate it.

Categories
Programming

A day in the code

Well, I did get stuff done today. Some project aquarius work (all HTML I might add, as much as “love” it). Tomorrow I think I can finish this front end stuff and get back to my beloved backend.

Also nearing the end of bug 217149. I think this last edit should do it.

Also many thanks to those who sent me an email/comment over yesterday’s post on securita. It will be a few days before I can give this some attention again, but I am slowly working towards something.

Categories
Programming

Open Sourcing some goodies

Over the years, I’ve written quite a few scripts, and other fun goodies. Some are used, some I’ve got in production for years, and literally forgot about. And some have never been used. I’m looking in my vault of code, and have quite a few of these little things hanging about.

I’m seriously considering publishing what I have for all who want to use (mostly under a typical Mozilla Tri-license scheme).

Biggest problem is that some need some cleanup, and a few could be written a bit better. So it is a time investment. Perhaps when I get some free time and feel like coding a bit, I’ll put them all together.

Also look for a new XHTML version of this site to come soon. I’ve been lazy, and never finished it after I started, but I do think I”m going to get to it sooner than later. A lot slimmer. And that’s what we all like. Not to mention I want to add some new alternative stylesheets.

Categories
Programming

XHTML is coming

Turning this website to be XHTML compliant.

Preview here

It’s not done, but take a look, and let me know what you think. So far it’s a direct port. Though expect some new stylesheets when done.

Categories
Programming

To much recursion

After dealing with a teacher who has a sickening love for recursive:

Recursion Error

πŸ˜€

Categories
Programming

My accomplishments for these past few weeks

I’ve been off, but what have I accomplished?

  • Patch for Mozilla Bug 94787.
  • Learned a bit of Javascript, and some XUL (hopefully more Mozilla work soon).
  • Some updates to blog templates/atom feed/other blog stuff.
  • Patch for SpamAssassin Bug 2889.
  • Installed Mantis Bug Tracking system for MacVillage.net.
  • Benderupdates some stats hourly to this webserver.
  • Remastered master HTML template for MacVillage.net, cutting several KB off of pagesize, and hopefully HTML 4.01/Transitional Valid.
  • Wrote several hundred lines of PHP for backend systems (vast majority of my time).