Monthly Archive for August, 2008

Running Total

Edwin: 10

Sam: 7

Charlie: 2

Joe: 2

Joel: 1

Thanks, Microsoft!

Where in the world is Charlie Hamdiego?

Fun City, USA. That’s where.

I need a new laptop. Powerbook’s getting a bit creaky.

Also: Who installed the “Hello, Dolly” Wordpress plug-in?

Like I need to ask.

A 20-Post Celebration

It’s been almost a month since Sector 930 was launched and we’re now up to 20 posts, an impressive accomplishment.

I just upgraded the blog to Wordpress 2.6.1, and all went swimmingly.  I’m hoping everyone *cough* CHARLIE *cough* takes advantage of the new Flickr photo gallery plugin, which allows a summary of photos from a Flickr album to show up RIGHT IN THE BLOG!  Charlie has been posting his images of his road trip to his Flickr account, and it’d be great to have the site jazzed up a little bit more.

Btw, props to Jim Groom’s post listing the plugins used on Bavatuesdays for giving me some direction as to which Flickr plugin would be the most useful.  As I’m sure he’ll tell you, if it ain’t on the Bava, it ain’t the best.

Future enhancements include my playing with the K2 CSS in an effort to make our blog tabs stand out better against our image headers, as well as adding drop shadows to parts of the headers to make the title of the blog stand out more consistently.

Other features I’m looking into right now: arcade930.  If I’m not posting, I might as well be kicking ass in Pac-Man.  HURR…

Also I’ll see if I can make an effort to post more often.  lulz.

Home-Nas: A Revisit

Whenever I think about building a system, there comes a point where I doubt whether I need it or not, or if there are better things I could be doing with those funds. I hit that point last week as I was spec’ing it out in more detail on Newegg. First of all, there are other things I could do with the money than buy another computer. Like, save for retirement, or …buy food. I was able to quell such thought with the following rationalization: It will help me in my job. In building this system, I will undoubtedly learn something that will come in handy, maybe in a job interview! Also, this specific system would be used in making backups, which could potentially save money and frustration in the long term.

But now I’m torn between building this one and building a Linux workstation. To make this decision harder, FreeNAS is on the verge of a fairly large update, which will include many new features, including full ZFS support. Ideally, I would like to wait for this update, rather than using what is current now, and having to upgrade, potentially having to start over. I have read up on ZFS, but its benefits over what I was going to use did not jump out me. So I call upon our faithful readers to help me out here. What are the biggest benefits to waiting for ZFS? Performance? Redundancy? Nerd cred?

Note: From what I could gather, ZFS is included by not fully supported, correct? This system is going to be in a “production” environment, and I would rather wait for the big update than take my chances now.

I still need to do a post about NASes, RAID schemes, and other associated technologies. Maybe you guys can give a blurb about ZFS?

One more thing to consider. I found out today that our house is in a “High-Risk Flood Zone.” Two years ago, my entire street flooded, and most of the houses in the neighborhood were damaged. While I would rather not get flooded, my data is far more valuable to me than my hardware, especially when I have insurance. So this thing takes a slightly highter priority than the linux workstation. And it’s going upstairs.

My co-workers re joking me about my basement flooding. I am already thinking about how to design the network in order to survive a flood. Sounds like a good post!

A SQL Sequel

Duh?

Now, let’s recover from that terrible start to a blog post. And by recover I mean put up this lame educational post a day after Charlie’s awesomely nerdy post from South Dakota.

For the second part of this pointless series on SQL, I’ll continue my discussion on select statements. This time around I’ll cover the ORDER BY clause, the GROUP BY clause, and the SUM function. If you need to get caught up, here’s Part 1.

ORDER BY

You can use the ORDER BY clause to sort your results by a certain field. Going back to my Babe Ruth example Part 1, we can order the results by the number of home runs in each season.

mysql> select playerID,yearID,HR
    -> from Batting
    -> where playerID='ruthba01'
    -> order by HR desc;
+----------+--------+----+
| playerID | yearID | HR |
+----------+--------+----+
| ruthba01 |   1927 | 60 |
| ruthba01 |   1921 | 59 |
| ruthba01 |   1928 | 54 |
| ruthba01 |   1920 | 54 |
| ruthba01 |   1930 | 49 |
| ruthba01 |   1926 | 47 |
...

Here, I’ve used HR in the ORDER BY clause and set it to DESC (descending). You can also use ASC (ascending), but that is the default behavior of ORDER BY.

Using ORDER BY, we can also see the greatest single season home run totals across history.

mysql> select playerID,yearID,HR
    -> from Batting
    -> order by HR desc
    -> limit 10;
+-----------+--------+----+
| playerID  | yearID | HR |
+-----------+--------+----+
| bondsba01 |   2001 | 73 |
| mcgwima01 |   1998 | 70 |
| sosasa01  |   1998 | 66 |
| mcgwima01 |   1999 | 65 |
| sosasa01  |   2001 | 64 |
| sosasa01  |   1999 | 63 |
| marisro01 |   1961 | 61 |
| ruthba01  |   1927 | 60 |
| ruthba01  |   1921 | 59 |
| foxxji01  |   1932 | 58 |
+-----------+--------+----+
10 rows in set (0.33 sec)

Notice the end of the statement where I use the LIMIT clause. We can use this to only show the first few fields. Here, I have shown the first ten.

GROUP BY

A lot of times, the tables that you work with contain a lot of raw data. Each record might represent some small piece of the puzzle. But you might be interested in the bigger picture or a more summarized form of the data. The GROUP BY clause is one way to deal with this. We can choose a field in the table to group all the rows around. However, GROUP BY in itself is not very useful. We have to combine it with another function. Here is an example that uses the COUNT(*) function.

mysql> select playerID, count(*)
    -> from Batting
    -> where playerID='bondsba01'
    -> group by playerID;
+-----------+----------+
| playerID  | count(*) |
+-----------+----------+
| bondsba01 |       22 |
+-----------+----------+
1 row in set (0.02 sec)

This query shows us how many season Barry Bonds played (or has played so far, but that’s still up in the air), since one row in the Batting table represents one player-year*.

SUM

Another function that we can use with GROUP BY is the SUM function. Here, I will use GROUP BY to find the top ten career home run totals of all time.

mysql> select playerID, sum(HR)
    -> from Batting
    -> group by playerID
    -> order by sum(HR) desc
    -> limit 10;
+-----------+---------+
| playerID  | sum(HR) |
+-----------+---------+
| bondsba01 |     762 |
| aaronha01 |     755 |
| ruthba01  |     714 |
| mayswi01  |     660 |
| sosasa01  |     609 |
| griffke02 |     593 |
| robinfr02 |     586 |
| mcgwima01 |     583 |
| killeha01 |     573 |
| palmera01 |     569 |
+-----------+---------+
10 rows in set (0.49 sec)

There you have it. Another post in the database. Zing!

Next time, I will be covering joins.

*Actually, if you want to get technical, one row in the Batting table represents a player-stint. A player can have more than one stint per year if he is traded mid-season.

It’s a Big Country

As most of you probably don’t know, I’m writing this post via the free wireless internet provided at my Motel 6 in Mitchell, South Dakota. That’s right – I’m in South Dakota! Just over 24 hours ago, I was in my home town of Northern Virginia.

The Trip
You might be wondering what I’m doing in South Dakota and how I came to be here. Well, I’m on a road trip. I worked a bunch of overtime and used all of my annual leave to take 6 days off from work to have 10 days free to drive from Virginia to Idaho and back. I’ve never been to this part of the country before, and I am very interested in possibly living out west some day, so when my friend Sean suggested we go out to Idaho, I said “sure, let’s do it!”

The trip started Friday, and after an early morning trip to Hertz to pick up the rental car, we spent several hours outfitting the car with all the mobile electronics supporting this expedition, we hit the road. Well, here it is over 1,400 miles and just over a day later, and we’re in Mitchell, South Dakota. We drove straight through the night, only stopping for a total of about 2 hours – once for dinner and once for a nap.

The Nerdery

My friend Sean and are both huge nerds. We’re not too proud to admit it. Therefore, this trip is “supported” by far too much technology. Currently installed in our rental car, we have 3 GPS recievers, a laptop acting as a GPS server (allows the GPS connected to it to be shared out over TCP/IP to pseudo-serial ports on client machines), a webcam mounted on the dash taking a time-lapse video of the entire trip, a APRS (Automatic Position Reporting System) beacon that transmits our position via ham radio every 60 seconds. If the beacon’s signal is recieved by another ham’s station, the information is transfered to the Internet so our friends can see our location in “real time.” We’ve got a police scanner, radar detector, and VHF ham radio to keep tabs on the law and other local events. We’ve got a tablet running navigation software interfaced to the GPS server to give us turn-by-turn directions. And on top of it all, we’ve got a wireless access point which ties all of the equipment together and allows us to use our personal laptops on the “in-car” network seamlessly.
While all of this gear may seem pretty cool, it is really a pain in the ass to deal with during a 5,300 mile road trip – just in case you were wondering.

So Far

The trip has been awesome — I’m tired as hell, but who cares. I’m currently writing this post while sitting in a camp chair in front of my Motel 6 room and drinking a beer several beers. The weather is prefect, the air is fresh and clean, the town is small, the people are friendly, there’s a lot more freedom here, and I’m loving every second of it.

The west is really the best. The worst part so far was driving through Ohio, Indiana, and Illinios. Iowa and Minnesota were not as bad, and offered a lot better scenery. It doesn’t really start getting good until South Dakota, though. If you haven’t driven from the east coast out west, you really can’t appreciate how big this country really is — and I’ve only driven 1,400 miles so far!

I’ll be posting more as the trip progresses. The best is yet to come — Idaho and Wyoming.
Wall to wall and treetop tall, we’ll see ya on the flip side good buddy.

Degree of Separation: Wikipedia Edition- THE GAME

So I’ve seen several variation on this game, but here’s the general idea:

You pick a Wikipedia page, something fairly obvious, like a popular person or place.

You then choose the “Random Article” option on Wikipedia’s homepage. This will redirect you to a completely random article.

The goal then is to navigate to the original page using only the links contained within the articles, using as few pages as possible.

For example: today at work, we chose George Patton.

My first page was some Welsh actress. This is how I did it.

Wales-> England -> History of England -> Winston Churchill-> World War II -> Allied Leaders -> George Patton.

7 pages.

Hours of fun.

And knowledge is power!

Also, don’t try googling anything about Wikipedia. Because it will just suggest a page on Wikipedia about whatever else you googled.

Also, I’m three degree from Kevin Bacon. So anyone that has met me is now at most four degrees from Kevin Bacon.

zpizza

So approximately half of our reader base (Lenore) has requested that we make non-technical entries. While personally I don’t see the appeal in this, I will give it a shot anyway.

So there are about five pizza shops within a mile of my current domicile, all independent and marginally shady. If we expand that circle to two miles, we get a Pizza Hut, Papa Johns, Dominos, and a delightful little place called “zPizza.” Joe and I have decided to try one of these per week. So we went with zPizza.

I have limited experience with reviewing food, so I’ll keep this short. The pizza itself was generically good pizza. It was not mind-blowing in any regards. And it was $20.99 for a non-fancy large. Considering you can get two large’s from Sam’s for $14.99 total, I’m not impressed with zPizza. And it gives off a very trendy Web 2.0 green liberal vibe.

Pros: Clean restaurants, good pizza

Cons: Too trendy and expensive, limited menu.

C+

And now for something completely unnecessary: An intro to SQL

As a kind of, sort of “junior DBA,” I have learned several things about databases. I know Charlie’s looking to learn about SQL, so I’ll post a series about some of the basic stuff about the language that I picked up.

SQL (some people pronounce it “sequel”) is a fairly simple language, with a pseudo natural language flow. In this post, I’ll start with select statements, and in later posts I will cover insert, update, and delete statements. These four statements are the core of the language. They are practically standardized across all database systems. I’ll use MySQL in my examples, but it shouldn’t matter what system you’re using.

Installing MySQL

I won’t go into how to install MySQL. See the reference manual for that. Definitely give yourself a good hour to install it and set it up.

Setting up the database

Throughout my examples, I will use the freely available Baseball Databank. (This is the point in this blog where I unleash my baseball nerdiness.) Just get the zipped database in MySQL form. After you’ve downloaded it, run the following commands (assuming you have a Unix-like system*):

$ mysql -p -u root
mysql> GRANT ALL ON bbdatabank.* TO 'username'@'localhost' IDENTIFIED BY 'password';
mysql> CREATE DATABASE bbdatabank;
mysql> quit
$ mysql -u username -p -s bbdatabank < BDB-sql-2008-03-28.sql

Then, start the MySQL client, just type:

$ mysql bbdatabank -u username -p

If you have your own database and don’t want to use this one, just modify my examples to fit yours. The important thing is, you need a database, otherwise you will not get far.

select * from table

The basic form of a select statement is

select columns from table;

The “select *” variation is the most general form. With it, you are saying “give me all the columns in the table.”  An example of this query wouldn’t fit on the screen, but you can give it a try. Just run the following command at the MySQL prompt:

mysql> select * from Batting;

Be sure when you try this and anything else on the MySQL prompt, you include the semi-colon at the end. If you forget, just type a semi-colon on the next line and hit enter.

Selecting particular columns

Most of the time, you don’t want all the columns in the table. Instead, you will want to select certain columns to find the information you’re looking for. Here is an example:

mysql> select playerID,yearID,HR from Batting;

This script will pull all of the single season home run totals for every player-year in the database. Again, I won’t put the output here because it will be thousands of rows, but you can try it out.

The where clause

Usually, we don’t want all the rows in the table, only a subset. To limit the rows that we get, we can use the where clause. For example, I might want to look at all the single season home run totals put up by Babe Ruth:

mysql> select playerID,yearID,HR from Batting where playerID='ruthba01';
+----------+--------+----+
| playerID | yearID | HR |
+----------+--------+----+
...
| ruthba01 |   1926 | 47 |
| ruthba01 |   1927 | 60 |
| ruthba01 |   1928 | 54 |
| ruthba01 |   1929 | 46 |
| ruthba01 |   1930 | 49 |
| ruthba01 |   1931 | 46 |
| ruthba01 |   1932 | 41 |
...
+----------+--------+----+
22 rows in set (0.01 sec)

In this example (shortened for length reasons), I used Babe Ruth’s playerID. If you want to try a different player, you will have to find his playerID in the Master table. I will leave that up to you as an exercise. You can find out what columns make up the Master table by executing the describe command:

mysql> describe Master;

or

mysql> desc Master;

Aliases

Sometimes, column names can be funky or cryptic. Other times, we want to combine information from two or more columns and display it as one column in our result set. We can do this with aliases. In this next example, I’ll find the on base percentage (OBP) of Barry Bonds for each of his seasons. OBP is derived using a formula that would take up a lot of space in a column header. Instead we can use OBP as an alias. Notice the as keyword in this example:

mysql> select playerID,yearID as Year,(H+BB+HBP)/(AB+BB+HBP+SF) as OBP from Batting where playerID='bondsba01';
+-----------+------+--------+
| playerID  | Year | OBP    |
+-----------+------+--------+
...
| bondsba01 | 2000 | 0.4399 |
| bondsba01 | 2001 | 0.5151 |
| bondsba01 | 2002 | 0.5817 |
| bondsba01 | 2003 | 0.5291 |
| bondsba01 | 2004 | 0.6094 |
| bondsba01 | 2005 | 0.4038 |
| bondsba01 | 2006 | 0.4544 |
| bondsba01 | 2007 | 0.4801 |
+-----------+------+--------+
22 rows in set (0.02 sec)

select count(*)

Before I wrap up this intro to SQL, I’ll leave you with one more type of query. It’s one that’s quite simple, yet very useful. You can use it to tell the database “give me the number of rows in this table.” In this example, I’ll select the number of rows in the Batting table:

mysql> select count(*) from Batting;
+----------+
| count(*) |
+----------+
|    89945 |
+----------+
1 row in set (0.00 sec)

You’re a DBA now!

Not. But you’ve taken your first step. I encourage you to play around with the your queries and try to get different results. And if you think this intro was crap, well you can just go find another one. A good one is w3schools.com. Another good place is the reference manual for your database software. I hope you got something out of this though, because I’ll be back next time with more topics: the sum function and the group by clause.

*You only have a Windows system? Why are you reading this blog?