Mysql table types

As of MySQL 4.1, the list of table types is available directly through the SHOW TABLE TYPES statement:

| Type   | Support | Comment                                                   |
| MyISAM | DEFAULT | Default type from 3.23 with great performance             |
| HEAP   | YES     | Hash based, stored in memory, useful for temporary tables |
| MERGE  | YES     | Collection of identical MyISAM tables                     |
| ISAM   | YES     | Obsolete table type; Is replaced by MyISAM                |
| InnoDB | YES     | Supports transactions, row-level locking and foreign keys |
| BDB    | YES     | Supports transactions and page-level locking              |

Creating a Windows service

For this I used Daniel Berger’s win32-service package. This is a great package that does literally everything for you to enable you to create a nice Windows service. Just install the gem like this:

gem install win32-service

I used examples/daemon_test.rb as the base template to make my Windows Service. This piece of code contains all that is needed to run the code snippet above as a service. In this file you will find a class called Daemon that has a number of methods necessary for running a Windows service. Put in the necessary requires and place your ActiveRecord initialization code at the beginning of the code. Then under service_main, while the status == RUNNING, put in the main processing code, minus the loop. Your code could possibly look something like this (don’t cut and paste this code, just use it as a reference):

require 'rubygems'
require 'logger'
require 'active_record'
require 'c:/myrailsapp/app/models/message' # remember to put in the absolute path here
require "win32/service"
include Win32

:adapter  => "mysql",
:host     => "localhost",
:username => "xxx",
:password => "xxx",
:database => "mydatabase"

# I start the service name with an 'A' so that it appears at the top
SERVICE_NAME = "MyProcess Service"

if ARGV[0] == "install"
svc =
svc.create_service{ |s|
s.service_name = SERVICE_NAME
s.display_name = SERVICE_DISPLAYNAME
s.binary_path_name = 'ruby ' + File.expand_path($0)
s.dependencies = []
puts "installed"
elsif ARGV[0] == "start"
# do stuff before starting
puts "Ok, started"
elsif ARGV[0] == "stop"
# do stuff before stopping
puts "Ok, stopped"
elsif ARGV[0] == "uninstall" || ARGV[0] == "delete"
# do stuff before deleting
puts "deleted"
elsif ARGV[0] == "pause"
# do stuff before pausing
puts "Ok, paused"
elsif ARGV[0] == "resume"
# do stuff before resuming
puts "Ok, resumed"

if ENV["HOMEDRIVE"]!=nil
puts "No option provided.  You must provide an option.  Exiting..."

class Daemon
logger ="c:/myprocess.log")

def service_stop "Service stopped"

def service_pause "Service paused"

def service_resume "Service resumed"

def service_init "Service initializing"
# some initialization code for your process

## worker function
def service_main
while state == RUNNING || state == PAUSED
while state == RUNNING

# --- start processing code
messages = Message.find :all,
:conditions => ['sent = (?)', 0], # check if the message has been sent
:limit => 20 # retrieve and process 20 at a time

# array of threads
threads = []

# iterate through each message
for message in messages do
# start a new thread to process the message
threads < < do |message|
# process the message here ...
message.sent = 1

# don't finish until all threads are done
threads.each do |t|
# join the threads when it's done
rescue RuntimeError => e
# do some rescuing
puts “Failed: #{e.message}”

# — end processing code

if state == PAUSED
# if you want do something when the process is paused
rescue StandardError, Interrupt => e
logger.error “Service error : #{e}”

d =

end #if

Important to note that you need to put in the absolute path in the require as the service wouldn’t be starting at the Rails app.

Now you can install and start the Windows service (assuming the code is written in a file called ‘message_service.rb’:

c:/>ruby message_service.rb install
c:/>ruby messag_service.rb start

You can also control it from your Windows Services MMC console. What you have now is a Windows service that loops around until there is a message record in your database that is not sent (sent = 0). If there are, it will retrieve up to 20 messages at a go and process them with a thread each (parallelizing the processing to make it faster). Once it is processed, it will indicate the meesage has been sent (sent = 1) and loop again. Now you can happily create messages from your Rails app and stuff them into the database, while your message processor will process them separately.

AJAX Login Demo

Here’s a demo of a login system built using Ajax. This is a cool implementation which allows a user to login, without having to refresh the page. Here are some advantages of the noted by author of the code:

  • User does not need to refresh the page to login.
  • User is notified instantly on incorrect username/password combination.
  • Overall user experience is more seamless.
  • Password is not sent in plain text ever (more secure than traditional system).
  • Javascript convenience with server-side security (uses PHP/MySQL).
  • Uses one-time use random seed to hash the password before sending (making interceptions useless)

Source code for the login form is also available on the site.

Link: ≈ AJAX Login System Demo

Usability for Rich Internet Applications

Here’s a good article on design patterns for RIA.
“Rich Internet applications (RIAs) can provide opportunities to design much better user experiences. They can be faster, more engaging and much more usable. However, this improvement is not without its downside—RIAs are much more difficult to design than the previous generation of page-based applications. The richer interaction requires a better understanding of users and of human-computer interaction (HCI). Although there is a lot of HCI material and research available, it can be difficult to determine how it applies to this new environment.”

Link: Usability for Rich Internet Applications