Updated Theme and Comments

I ran across this skin while looking for new ones for a different blog. It happened to look similar to what I was hoping to create someday so I thought I would use it for a while. I’ve already modified a few small things to get it to look a little more to my liking, but it was overall very nice.

A while ago I posted about using Haloscan for a commenting system. There were many reasons I didn’t want to use it on here so I tested it out on a project site . A few weeks later, I heard about Disqus and it seemed to do everything I could ask for. I’ve implemented their system on Code Spatter to see how I like it. The best thing is I can stop using it and go back to wordpress comments with no hassle since they are stored in my database as well as on the disqus server.

A New, Simple Way to Salt your Hashes

Maybe I’m not the first to think of this, but it just came to me. Instead of using a single string to season a whole site or saving each new salt with the salted hash, try using this method for simplicity. Take the string and concatenate itself after it. This way, both the value being encrypted and the salt are never known and it’s still simple to validate input. Might be helpful if you actually fear someone building new dictionaries for each salt… or quantum computers.

And Why I Love Comments

Smart people keep you from doing something you didn’t think through. So, don’t use this.

Careful with Numeric Data Types in MySQL

TINYINT can be set to length of 4, but that doesn’t mean the max value is 9999. A tiny int will always have the same range no matter what size you specify since that isn’t what it is for with integers. It is the display width for the command line output.

This is what I was able to find in the MySQL manual:

The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column.

Reading the manual for things like this isn’t something people normally do. I had no idea about this until recently and I’ve been using MySQL for a long time.

Reference Chart for Max Signed Integers

TINYINT 127
SMALLINT 32767
MEDIUMINT 8388607
INT 2147483647
BIGINT 9223372036854775807

However, CHAR and VARCHAR work as expected with these limits.

Conditions on Count or Sum in MySQL

When selecting count, sum, or some other aggregate function, the value isn’t determined until after the WHERE clause so a condition can’t be placed there. There is still syntax for specifying a condition for this, it is to use HAVING.

The following example is to count all of the logs an active user has made only if they have more than two logs.

SELECT users.user_id, count(logs.log_id) AS count
FROM users
JOIN logs
ON users.user_id = logs.user_id
WHERE user.deleted = 0
GROUP BY user.user_id
HAVING count > 2

It works the same for sum. Example shows users who have logged less than an hour of time.

SELECT users.user_id, sum(logs.log_time) AS sum
FROM users
JOIN logs
ON users.user_id = logs.user_id
WHERE user.deleted = 0
GROUP BY user.user_id
HAVING sum < 60

Common aggregate functions this works with:

  • AVG
  • COUNT
  • MAX
  • MIN
  • STD
  • SUM

For More MySQL Tips

Check out these other posts:

Implementing HaloScan Powered Comments

For some time now, I’ve been using a Magic the Gathering card database for a testing bed for various things. Earlier today I learned about a service that will provide commenting functionality for your website. HaloScan was easy to set up even for a non-blog type website. It only required a few lines of pasted JavaScript code in two places to get it going.

My test page shows what the free service has to offer (rating, comments, trackbacks). With a small donation more services would be available, which might be something I would consider if I ever take the mtg website seriously.

This quick-to-set-up service will be another tool to help those that are trying to get webservices up quickly, like a few articles I’ve read recently.