About redirects

The web change constantly and content moves around. This article gives a brief overview of the various different options available to you, to make a redirect. Redirects come in two major flavors - clientside and serverside.

Client side

Clientside redirects reside within the HTML documents on the server. There are three basic ways of making these:

  • Manual (or user driven) redirects.
  • Meta headers.
  • Javascript redirects.

Manual

The manual redirects most often used when you really, really wants the users to know, that the page has moved. Instead of doing an automatic redirect, you create a common html page, which informs the user that the page has moved, and provide a link to the new page. In some cases, this redirect-type exists in combination with a timed auto-redirect that upon timeout do the redirect.

Weekly Review

It’s that time of the week again, and since my list for the weekly review was pretty slim, I thought I’d share one of my productivity gems. As the name suggest it’s a weekly process where the activities of the past week as well as the coming week is reviewed and processed.

The goal

Like a few of my other habits this one is an adoption of the Getting Things Done. It’s probably not following the recipe from the official GTD methodology, but it works for me. It’s a way to try to gain some control of the daily life and have a little stress-less workday.

The big nothing

So, I was actually using Microsoft Windows for quite a while. My first windows was Windows/286 which was nothing like the current Windows, but it was okay somehow. Today I just realized that I haven’t really been using Windows on any of my own machines and even though Vista was released three months ago, I haven’t seen it yet. It is sort of funny, but since switching to a Mac, I’ve been spending less time keeping the machine running – debugging, tweaking and doing other odd stuff – and more time doing actual fun work at the computer – like expanding my portfolio at istockphoto.

Comment spam

I hate comment spammers. I really do. The SCode captacha works, but the load the evil spammers create is pretty bad in itself. The comments were disabled a few hours, but they’re back now, after some counter measures has been applied.

Mysql: Change account password

Through the mysql client:

update mysql.user set password=password('NEW_PASSWORD') where user='USERNAME' and host='HOSTNAME';
flush privileges;

Through the command line:

mysqladmin -u USERNAME -p CURRENT_PWD password NEW_PWD

Replace USERNAME, CURRENT_PWD and NEW_PWD with appropriate values.

Mysql: Delete orphan records

Finding records that do not match between two tables.

          CREATE TABLE bookreport (
            b\_id int(11) NOT NULL auto\_increment,
            s\_id int(11) NOT NULL,
            report varchar(50),
            PRIMARY KEY  (b\_id)

          );

          CREATE TABLE student (
            s\_id int(11) NOT NULL auto\_increment,
            name varchar(15),
            PRIMARY KEY  (s\_id)
          );

          insert into student (name) values ('bob');
          insert into bookreport (s\_id,report)
            values ( last\_insert\_id(),'A Death in the Family');

          insert into student (name) values ('sue');
          insert into bookreport (s\_id,report)
            values ( last\_insert\_id(),'Go Tell It On the Mountain');

          insert into student (name) values ('doug');
          insert into bookreport (s\_id,report)
            values ( last\_insert\_id(),'The Red Badge of Courage');

          insert into student (name) values ('tom');
 To find the sudents where are missing reports:
          select s.name from student s
            left outer join bookreport b on s.s_id = b.s_id
          where b.s_id is null;

              +------+
              | name |
              +------+
              | tom  |
              +------+
              1 row in set (0.00 sec)
 Ok, next suppose there is an orphan record in
 in bookreport. First delete a matching record
 in student:
       delete from student where s_id in (select max(s_id) from bookreport);
 Now, how to find which one is orphaned:

       select * from bookreport b left outer join
       student s on b.s_id=s.s_id where s.s_id is null;

     +------+------+--------------------------+------+------+
     | b_id | s_id | report                   | s_id | name |
     +------+------+--------------------------+------+------+
     |    4 |    4 | The Red Badge of Courage | NULL | NULL |
     +------+------+--------------------------+------+------+
     1 row in set (0.00 sec)
To clean things up (Note in 4.1 you can’t do subquery on same table in a delete so it has to be done in 2 steps):

Mysql: Dump data in XML or HTML

Assume you have the table “exams” in the database “test”.Then, the following will give you XML output if executed from the shell prompt with the “-X” option. For html output use the “-H” option.

mysql -X -e "select \* from exams" test

Mysql: Dumping data to a file

To dump data into a comma separated file use this:

  SELECT * INTO OUTFILE 'tablename.csv'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY 'n'
  FROM tablename;

Replace tablename with the tablename of the table you which to dump to a file.

Mysql: Loading data from file

Loading Data into Tables from Text Files.

Assume you have the following table.

            CREATE TABLE loadtest (
                pkey int(11) NOT NULL auto\_increment,
                name varchar(20),
                exam int,
                score int,
                timeEnter timestamp(14),
                PRIMARY KEY  (pkey)
               );
And you have the following formatted text file as shown below with the unix “tail” command:

    $ tail /tmp/out.txt
    'name22999990',2,94
    'name22999991',3,93
    'name22999992',0,91
    'name22999993',1,93
    'name22999994',2,90
    'name22999995',3,93
    'name22999996',0,93
    'name22999997',1,89
    'name22999998',2,85
    'name22999999',3,88
NOTE: loadtest contains the "pkey" and "timeEnter" fields which are not
present in the "/tmp/out.txt" file. Therefore, to successfully load
the specific fields issue the following:
         mysql> load data infile '/tmp/out.txt' into table loadtest
                  fields terminated by ',' (name,exam,score);