Hadoop Streaming with PHP

I’ve started my journey with Hadoop, and the first thing I wanted to try was Streaming, so I could run the mapper and reducer methods with PHP programs.

The first thing I did was setup an alias:

alias stream='/usr/local/hadoop/bin/hadoop jar /usr/local/hadoop/contrib/streaming/hadoop-0.18.3-streaming.jar'

Read the rest of this entry »

IPv6 Presentation, Introduction to IPv6

I am doing a presentation on IPv6, at my company’s TechFest.  This is a day event with keynote speakers, and break out sessions.  The purpose of TechFest is to give the developers and engineers a break from their day to day activity and get a view of what’s going on around the company and in the industry.

In this article, I’m copy/pasting my slide deck, and stripping out the company specific information, making this a generic Introduction to IPv6.

The Agenda for Today:

What is IPv6? (~10 minutes)
DNS (~10 minutes)
Getting Started (~10 minutes)
Web Application Development (~10 Minutes)

Read the rest of this entry »

My first chess video

I might get around to making a series of Chess videos. First, I set out to figure out how. I found that I can record my desktop with the free Windows Media Encoder. I used this site http://bhccvb.blogspot.com/2007/10/how-to-make-chess-videos-on-your-pc.html to learn how. The result of my first stab at this is below. I have a couple problems:
1. Microphone – I need a good one. The one I have sucks.
2. I need Fritz 11 software. I used WinBoard – which is OK, but Fritz is better.
3. Video dimensions. Winboard is rectangular, but taller than it is wide. I need to find a way to make a frame that is ideal for youtube.

Here is the video:

Read the rest of this entry »

Solutions to the ORDER BY RAND() problem.

Just getting them in there, these are not original ideas, I got them from someone else, just wanted to post them on my blog for convenience sakes:


* Run a query to determine the MAX ID number in the table.
$MAX = SELECT COUNT(*) FROM tbl

/* Use PHP to generate a random number between 1, and the max
$ID = RAND(1, $MAX)

/* Run a last query to select the ID that is >= the random one.
SELECT * FROM tbl WHERE id >= $ID LIMIT 1

Another possible solution would be a heavy modification to that query. This solution is likely the best.

New Query:

SELECT *
FROM `tbl` AS `l1`
JOIN
(SELECT (RAND() * (SELECT MAX(`id`) FROM `tbl`)) AS `id`) AS `l2`
WHERE
`l1`.`id` >= `l2`.`id`
ORDER BY
`l1`.`id` ASC
LIMIT 1;

tar pipe ssh

I always have to look this up when I need it, so storing on my blog, so I can look it up faster. This is way faster than “scp”, for deep directories or directories with lots of files.


tar cf - whatever | ssh remotehost " ( cd /some/path ; tar xf - ) "
ssh remotehost "( cd /somewhere ; tar cf - something ) " | tar xf -

Using tmpfs for MySQL tmpdir setting

This is incredible, by the way. Any time MySQL needs to use a tmp table on disk, you can make it use RAM disk instead.

WARNING: if the tmpfs partition you make isn’t big enough, MySQL will not be able to complete queries. Make sure you have enough RAM to do this.


mkdir /tmp/mysqltmp
chown mysql:mysql /tmp/mysqltmp

id mysql
# example:   uid=502(mysql) gid=503(mysql) groups=503(mysql)

#to set up on server restart, put in fstab something like (replace gid, uid with number from above)
tmpfs    /tmp/mysqltmp    tmpfs   rw,gid=503,uid=502,size=2G,nr_inodes=10k,mode=0700 0 0

mount /tmp/mysqltmp

# you don't need this:
# mount -o size=2g,gid=520,uid=518,nr_inodes=10k,mode=0700 -t tmpfs tmpfs /tmp/mysqltmp

#edit my.cnf, adding
tmpdir=/tmp/mysqltmp/

restart mysql

Read the rest of this entry »

DbTable and all its glory

The example: http://www.koopman.me/dbtable/

I got the concept of the class, DbTable, from a book called PHP5 Professional. The idea is we have a class, this abstract class, that allows us to quickly make a new class out of any database table. Database tables make good objects. We often make them names of objects, like Shopper or Product. It makes sense to create classes that represent these objects, and to have a clean, consistent way to manipulate the data in the table. It also abstracts the database layer from application logic. If you just looked at example.phps, you’d have no idea if the database was flat file, MySQL, postgreSQL, or if it was even a database at all. Abstraction is a good thing, and one of the principles of object oriented programming.

Read the rest of this entry »