Software
How not to design a database
by pompo500 on Oct.02, 2010, under Software
I’ve come across quite a few horrible database designs. Here are a few tips on how to build a better database world.
Drupal is a great example of this. It’s database design offends most of these rules I consider that make a good database.
COLUMN NAMES
This is actually the most imporant one in my opinion, where almost everybody gets this wrong.
Always prefix your column names with the table name, and with camelcase. Makes everything more readable.
Consider tables “products” and “categories”.
Products have
- ID
- Name
- Category ID
Categories:
- ID
- Name
If your tables are designed poorly then you have columns named products.ID and categories.ID. How do you SELECT products along with their category names? You have to say category = categories.id. First off, the name “category” suggests it refers to “categories” table, but in fact it references “products.category”. That’s dumb and un-intuitive.
Why not prefix your columns with their table name? Like ProductID, ProductName and so on.
SELECT * FROM products INNER JOIN categories ON ProductCategory = CategoryID
SELECT * FROM products INNER JOIN categories ON category = category.id
Which looks better? And the first saves you from column ambiquity errors. And if the database schema changes and introduces a new column name that exists in two tables and a JOIN would happen to get data from both, without table prefix. Shit hits the fan and your application breaks.
COLUMN TYPES
Choose the right data types that fit the content you are storing. If your columns are spec’d as varchar(100) then something is probably wrong.
There are many and justified cases to use variable length columns, but if the table does not specifically need it, fixed length rows are much faster to seek to. It’s only a simple multiply operation on fixed-length rows.
What’s a variable length row? It’s when a table contains at least one column whose data type is variable length. (varchar / tinytext / mediumtext / blob / ..)
CONTENT
What to store in the database? Only the data that that concerns you business logic. Not anything else, supporting functions for example.
Drupal is a great example of this. Drupal has 7 (seven) tables for caching purposes. Database should not handle cached data, rate limiter counts or anything of that nature.
INDEXES
Index the right stuff.
I won’t be explaining indexing here. Should not know of it enough, there are many guides and sites that explain it better and more wisely than I could. Go Google it.
CASCADES
Don’t use any “ON UPDATE CASCADE, ON DELETE CASCADE” magic. They may be of convenience but there are some cases where you really need handle more complex logic when deleting something that simple cascades couldn’t handle.
And anyways database should be just a stupid entity that stores the data you tell it to. It should not contain any business logic. And CASCADES just make things a bit more confusing, and software is quite complex as is already.
You might think they’re cool and you know them when you implement them, but when a new developer comes to the project they have to study the foreign references with great concentration to get to know how the database behaves on certain events. Like I said, database should be dumb and act just like you want it to (= only do things you are told to).
STORED PROCEDURES
Don’t use stored procedures. Same as previous, database is not part of your business logic, except only in the sense of storing your data. Unnecessary complexity. Harder to debug on errors. Vendor lock-ins. Database should be a dumb entity that can be switched if needed.
Don’t store images, files or serialized data inside your DB. It’s not cool. Filesystem is for images and files. Serialized data? You are probably doing something wrong already.
A bug in Drupal affecting installations transferred from Windows to Linux
by pompo500 on Sep.15, 2010, under Software
Should you have a case like I had, where you worked on a Drupal installation with your Windows development environment, and then transferred your Drupal installation to client’s server running Linux, Drupal may spit out a message saying “C:\Windows\Temp” was created.
How nice.
I don’t exactly know how much of Drupal’s functionality that disrupts since I fixed it immediately, but at least it makes C:\Windows\Temp directory under your Drupal installation. Yes you heard it, it makes “/drupal/C:\Windows\Temp/” directory.
Should you want to repair it, run this SQL against your database:
UPDATE variable SET value = “s:4:\”/tmp\”;” WHERE name = “file_directory_temp”
Note: if you have used a table prefix with your Drupal installation, you should prefix the “variable” text accordingly.
Anyways. Hope this helps somebody.
Change file type icons easily in Windows 7 / Vista
by pompo500 on Aug.26, 2010, under Software
In Windows 7 / Vista changing the file type is next to impossible; you have to fire up regedit.exe and do some inhuman things.
Luckily, NirSoft has developed this wonderful and FREE program to handle just this case. Get FileTypesMan here.
Short tutorial is here, if you don’t find it simple enough. It should be though.
Remember, Windows only understands .ICO files; so should you need to convert .PNG or other formats to .ICO, I recommend Icon Sushi (free program) or converticon.com (free web service)
Facebook profile picture sync to GMail and phonebook
by pompo500 on Aug.24, 2010, under Software
How would you like to see your friends’ Facebook profile pictures in your phone’s phonebook? Or GMail’s contacts? For free! Note: this only works with contacts you already have on your GMail’s contact list. For importing Facebook’s contacts to your contact list first, see this link.
Interested? Here’s a how-to.
What you need:
- Facebook account, obviously
- GMail or Google Apps account (if you don’t know what Google Apps is, don’t worry; this doesn’t concern you)
- You should have your GMail contacts by their full names. E.g. “John Smith” instead of just “John”. This application only works with full names. “John Smith IBM inc.” works though, because it searches for the Facebook full name in GMail’s contact list.
- Windows
- .NET framework 3.5
How do I know if I have the .NET 3.5 framework? If you have Windows Vista or 7 or you frequently update or XP, you should have it. If you want to check you can go to Windows’ “Add or Remove Programs” to check if it’s mentioned there. If you need to install it, you can grab it easily from here.
Instructions
- Download FacebookGmailPhoneSync.xslabs.zip, unpack it somewhere, e.g. desktop or C:\Program Files\FacebookGmailPhoneSync
- Run FacebookGmailPhoneSync.exe
- Enter your GMail or Google Apps account details, click “Sync”
- Log in to Facebook
- It doesn’t have a progress bar, it just quietly runs a while
- After it’s done, it pops up “Done.”
- That’s it, it may take a few minutes for the pictures to update into your GMail, and if you’ve set up GMail <-> Cell phone sync, to your phone!
If there’s any error, please check the “What you need” section again, and please note that XS Labs does not offer any support for this, since this software is not originally ours and it’s free anyways.
Is it safe?
Yes, XS Labs has reviewed the source code, and it does not save or send your private information anywhere.
Should you want to see it for yourself, see the “Source code” section.
Source code
If you don’t know what source code means, you don’t need to download this. You only need to follow the “Instructions” section. Source code is intended for developers who want to modify this program.
Download FacebookGmailPhoneSync.xslabs-source.zip
What you need to compile FacebookGmailPhoneSync from source code:
- Microsoft Visual Studio, preferably 2008 or newer version. Search xs.fi for “dreamspark” and see if you’re eligible for the free version.
- The FacebookGmailPhoneSync.xslabs-source.zip mentioned above, unpacked somewhere
- Google Data API Setup (1.6.0.0) or newer from http://code.google.com/p/google-gdata/downloads/list
Credits
GoogleContactSync was not developed by XS Labs. Original credits go to www.koushikdutta.com
However, XS Labs has modified the program a bit (the source code in it’s current form didn’t work and relied on having Microsoft Office installed).
Changes made in MainForm.cs:
- deleted “using Microsoft.Office.Interop” lines.
- commented out “Microsoft.Office.Interop.Outlook.ApplicationClass app = new ApplicationClass();” and following three lines.
- replaced “match.Google.PhotoEditUri” with “match.Google.PhotoUri”
Changes made in Facebook API (Entity/User.cs):
- Added enum “Widowed” to User.RelationshipStatus, that was causing Exceptions with people who had widowed friends
10 Questions From Modern Web Designers: Answered
by pompo500 on Aug.24, 2010, under Software
- What New Technologies Should I Focus on Most?
- What Types of Things Should I Invest Money In?
- The Big One: Should I Go Freelance / Stick With A Firm?
- As a Web Designer, Do I Need to Code If I Don’t Want To?
- With All The Hype, Should I Learn How to Make WordPress Themes?
- What is the Most Effective Way to Market Myself in This Industry?
- What’s a Good Balance Between Spending Time on My Own Stuff vs. Client Projects?
- What Are The Best Places to Find Web Design Resources?
- For Web Design Projects, Should I Use a Fixed Price or Charge Hourly?
- Are Bigger Clients Necessarily Better?
Read the article here (via onextrapixel.com)
Coders’ reference
by pompo500 on Aug.23, 2010, under Software
XS Labs has compiled a reference for the benefit of coders’ frequently needed information. Included:
- Data Types
- SQL Numeric Types
- HTTP Codes
- Common Ports
- PHP Reference
- ASCII & Hex tables
- Bitwise Operations
- Web Notes
- CSS Reference
- Binary permutations
Java’s visual appeal is zero
by pompo500 on Aug.20, 2010, under Software
Today the visual appeal of software means more than ever. Just take a look at Windows’ history: Windows 3.1, Windows 95, Windows 2000, XP, 7..
Every release of Windows has been more visually appealing than the previous version. Today it matters how your software looks.
If your installer looks like this, you’re going to think less of the entire product right before even using it. It’s incredible how Java has had this butt-ugly grey default dialogs from since, 1990?
Get with the times, Oracle.
This is why PHP rocks
by pompo500 on Aug.19, 2010, under Software
PHP lets you concentrate on the most important part of software development: the problem itself. If you manage to put together hig-level APIs that do most of the work for you, then it’s easy as this.
The previous function GetMatchDuration() would be implemented without this library somewhat like this:
$SQL = ‘SELECT MINUTE(MatchEnds – MatchStarts) FROM matches WHERE MatchID = ‘.mysql_escape_string($MatchID);
if(!($Query = mysql_query($SQL)))
return false;
if(!($Row = mysql_fetch_row($Query)))
return false;
return $Row[0];
Quite a lot prettier in the picture, huh?
PHP effin’ rocks.
jQuery UI’s datepicker adds extra empty space at bottom of the page
by pompo500 on Aug.18, 2010, under Software
There seems to be a small bug in jQuery UI’s datepicker component that adds empty space at the bottom of the page, which looks pretty nasty with layout like the one in the picture. I don’t know if this concerns other themes, but at least the default one (“UI lightness”)
The added space is marked with a red circle in the picture.
Luckily there’s an easy fix to it, just add the following code to jQuery UI’s theme CSS file, at the bottom:
#ui-datepicker-div { display:none }
I’ve submitted a bug report to jQuery UI, hope it’ll be fixed in future releases. :)
Tip: HTML template for starting new pages quickly
by pompo500 on Aug.01, 2010, under Software
This tip is particularly useful for us webheads.
Ever been frustrated when typing the same <html><head><title>..</title><link>…</link></head><body><div>.. stuff over and over again?
Wouldn’t it be wonderful by just right-clicking on the desktop or inside a folder and just picking “New -> Firefox Document”, then Windows creating a fresh template for you with the most frequently used tags already typed in?

