ZeptoBlog

My tech playground

August 3rd, 2008

The 12th War

Overview

You will be given the name of someone in the war that you must eliminate by getting them wet. You may get him/her wet by any, non harmful, means you choose – squirt gun, water balloon, hose, cup of water, etc. Elimination means that you are out of the game. When you eliminate your target, he/she must give you the name of his/her target and that person becomes your next target. When you eliminate your target, you will get credit for all of that person’s eliminations. At the Ward Party on August 23rd, a prize will be given for the last player standing or the player with the most eliminations if not all players are eliminated. The game will start on August 4th at 12:00 AM and end August 23rd at 12:00 AM.

Rules of the game

1) You cannot eliminate your target on Sunday.

3) You cannot eliminate your target in any church building.

4) You cannot eliminate your target at any church sponsored activity nor on the way to or from the activity.

5) You cannot eliminate your target while the person is at work or at school. (Please don’t soak your target right before work or school.)

6) You cannot eliminate your target in his/her house or garage.

7) If there is a questionable elimination Russ J is the judge.

Please report eliminations to Russ J, russ@staceyshouse.com or 774-8271, within 24 hours of the deed.

If you would like to share a good story about eliminating someone, add a comment below.

January 29th, 2008

My PVC Carbide Cannon is a blast

What is a Carbide Cannon? As it turns out, if you take some Calcium Carbide and mix it with water, it produces lime (which settles in the water) and Acetylene gas. Acetylene gas is explosive. I’ll bet you are already thinking of how to make use of that information. Well, we gave our boys a book for Christmas called Backyard Ballistics. You are probably thinking that we are bad parents for teaching our 9 and 11 year old boys stuff like that. Your probably right. The book shows you how to make a cannon that will make a lot of noise as it generates and acetylene gas that you ignite. Here are some pictures of my cannon that I built.
carbide cannon

pvc carbide cannon

pvc carbide cannon

pvc carbide cannon

My first attempt did not fire. I think the ignition hole is too big and let the acetylene out too fast. I stuffed a little paper towel in the hole and it worked great.

This is my first successful firing of the carbide cannon: I leaned over it when it went off and nearly took out my eye. Not too smart.

So I did it a second time.

January 27th, 2008

New York Doll and Endless Summer 2

I saw a couple of documentaries this week, both of which I highly recommend.

New York Doll is about a guy who was in the band New York Dolls in the early 70s. The band fell apart before they made any real money but they inspired a number of famous artists that came later. Drugs and Alcohol played a big part in the fall. In the late 80s Arthur “Killer” Kane joined the LDS Church. Then in 2004 Arthur’s life-long dream came true as he was ask to do a show with the New York Dolls.

Endless Summer 2 is about a couple of surfers who want to relive what the makers of Endless Summer did 30 years earlier. They travel around the world and surf in a bunch of beautiful spots all over the globe. There is a couple of scenes on the beach in France where the women don’t have tops on, so beware. If you like great surfing and good commentary, you will enjoy this one.

December 5th, 2007

Why Isn’t There an Index

As you may or may not know, I am a big reader. I read many books each year mostly in the fantasy genre. I recently finished Book 11 of the Wheel of Time series by Robert Jordan. I think that each of the books in the series is between 700 and 900 pages. When you consider that there is a year or two between each book release, it can be quite a long time from the time that you start the series to the time you finish it. As I was reading book 11 Knife of Dreams a character became center stage that had been introduced a couple of books back. I can’t remember his name, but he is the Deathwatch Guard. The problem was that when I was reading I couldn’t remember anything about him until near the end of the book. It would have been a far more interesting read if I could have gone back and read the earlier sequences with him when he first popped up in the book.

This is where I come to the point of this post. There should be an index for this kind of thing. Why can’t I see a character and go look him up and get the page and book numbers where I can go back and read the previous interactions. Maybe it is up to people like me to get it started.

What do you think?

January 14th, 2007

Writing a PHP Framework (Authentication and Authorization)

In my previous post about writing a PHP Framework I mentioned a script called Tower.php. By using Tower as the single point of entry I can handle authentication and authorization all in one place for any page rendered.

Authentication is deciding whether a user has access to the system. This is most often accomplished by requiring the user to enter a username and password. Tower.php checks the users credentials and sends them to the login page if they are not authenticated. This works whether the user is trying to go to a bookmarked page or if their session has timed out but they still have the application up in their browser.

Authorization, on the other hand, determines what parts of the system the user has access to - whether they have been authenticated or not. In my framework, I have chosen to implement authorization by require each page to defined the permission required to render the page. I then group the permissions into roles and assign a role to each user. If the page doesn’t require any permissions, then it is a public page and anyone can view it. This is, of course, the case with the login page.

December 17th, 2006

Performance tuning my MySQL database

I doubt that many of you have ever tried to write your own web tracking software. I mostly did it to see if I could and also to have complete control over my tracker. My wife says I’m a bit of a control freak. Anyway, I posted on it earlier this year. I have called it Silentracker.

I wrote it in PHP. Any good software architect out there is probably shaking their head and laughing at me right about now. I know because I’m a pretty good software architect and I still wonder about my decision. It comes down to the fact that I never expect to make any money from the project and I don’t feel like spending money to get a server with more capabilities. So my choices where Perl or PHP. I didn’t feel like learning Perl… so there you have it. I originally wrote it using flat files to store the data. I changed that to MySQL and there we are.

Everything was fine when I started and was only tracking my mom’s web site which gets a few hits a day. Now, my brother’s company has started using it also and it didn’t take very long before I had 25,000 row in the hit table of the database. It won’t be long before there are 100,000 or 1,000,000. You get the point. As often happens, this “prototype” was in full production and suffering from the lack of fine tuning that you would expect from a prototype.

This week I took some time to clean up the queries and see if I could speed things up a bit. There are a number of things that I have considered and some of them I have implemented. Things are moving along nicely now and I figured I would throw these out there for those who might be having similar problems (I am going to assume that you are administering your database using phpMyAdmin):

  • Take a look at the queries that you are running most often and the tables that they hit and see if you can add an index or two to help speed things up.
    If you are not familiar with indexes, you can create an index on any table and base it on one or more columns in that table. Then when a query is run against the table the database will use an index where available to speed up the query. This ads overhead to inserts, updates, and deletes on the table so don’t over do it.

  • Denormalize the data if necessary.
    I found that I was performing the same expensive operation in most of my queries. I was doing a complex text comparison between two columns. I was able to do that same comparison as part of the insert and store the result in a separate column as a boolean value and save time on every query. One problem with this is that it is denormalizing your data to a certain degree, but to me it was so worth it. Then I create an index on that new column to speed things up even more.

  • Use explain to analyze your queries.
    When you run any query in phpMyAdmin you can then click on the explain link. This will analyze the query and tell you how it executes. It tells you what kind of search it does on the table and which, if any, index is being used. You may need to go to the MySQL documentation to see exactly what the results mean, but this can be invaluable when you have nested queries and complex table with complex joins.

These optimizations were enough to get thing back up to a good speed for now on Silentracker. When the data gets larger I will probably start archiving old data from the table. I may move each site into it’s own table or even create multiple databases to limit the size of the data. I also may divide types of hits into separate tables. If necessary there are other denormalizations that I can do also. A little analysis can go a long way.

One word of caution. Avoid premature optimization. Optimizations can degrade the maintainability of your software. Only optimize when there is a problem to solve.

Performance tuning is not limited to the database. With a language like PHP, you sometimes have to get performance enhancements wherever you can. For instance, I have graphs that only need to be created once each day. Why not cache those on the disk and check the file modification time to decide when to recreate them. If there is information that is guaranteed to be constant for the length of the session, store it in the session. Feel free to add other performance tuning in the comments below.

November 15th, 2006

Writing a PHP Framework

I’m not even sure where to start with this topic. I’m thinking that a good place to start is how the users get to the framework. .htaccess

htaccess is somewhat of a new thing to me. I have extensive experience in writing a Java Framework using Tomcat and JBoss. The way that I choose to write a framework is to have every page request filter through a single controlling entry point. This can really limit the chance of security holes. In Servlet containers this is done using servlet and servlet mapping definitions. You can easily send all requests through a single servlet that takes care of authentication and authorization before a page ever gets displayed. It turns out that the servlet mapping is just a watered down version of Apache’s mod_rewrite and, of course, .htaccess is processed by mod_rewrite. What I discovered is that you can achieve the same effect by using .htaccess and a well written php script.

This is what my .htaccess looks like:

RewriteEngine On

RewriteRule .*style/(.*) style/$1 [L]

RewriteRule .*images/(.*) images/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(framework/Tower.php)
RewriteRule . framework/Tower.php [L]

First of all, I used the .htacess that comes with Wordpress as a starting point - give credit where credit is due. I think there is only one line left from the borrowed file though. If this code looks totally foreign to you then do a Google Search for mod_rewrite. I looked at this Apache Doc and this nice reference sheet when getting familiar with mod_rewrite.

The gist of that code is this. Every request that come to my url will be redirected to a script called Tower.php - tower is meant to be like an airport tower that directs traffic - unless the request points to an actual file on the server. This caveat is there because I am building this framework in the middle of a working site and I don’t want to convert the entire site before using the new features. Also, I added the style/… and image/… so that my scripts don’t have to worry about how many ../../../ are needed to find the css and image files. Of course if your system is always running at the root - not in a subdirectory - you don’t need this little bit.

Now, I’m not saying that this is the best way to write a .htaccess file to do what I am doing, but it works. If you experts out there have suggestions, please let me know.

October 20th, 2006

Troubadork?

I have been a fan of the genious of Weird Al since the 80’s. Here is an exellent article on the subject
Troubadork

October 7th, 2006

Ajax with xajax

Early this year I was talking to a friend of mine and he told me that he was working on an open source project called xajax. At the time I hadn’t really started to play with Ajax yet but the project sounded interesting so I filed it away in the back of my mind for future retrieval. Then in May my company sent me to The Ajax Experience in San Fransisco. That got me all excited about what could be done with Ajax. It also scared me because of the dificulties that people experience when using Ajax. So now one of my projects has got me using xajax.

As far as tools go, xajax seems to be a good one so far. It has many of the things that I want (unabtrusive, lightweight, extensible) without being overbearing.

So far I have stuck to a basic - edit table rows in place - implementation and even that has given me headaches. What I find is that most of the headaches are related to the poor error logging in the browsers or the incompatibility of the browsers. I started by using a link to call the javascript function like this <a href=”javascript:xajax_myFunction()”>click here</a>. That worked fine in IE but was giving me problems in Firefox. I chose to use a button instead of tracking down the problem (this is only a prototype) and got that working in Firefox but could not get it to work in IE. It turns out that you can set innerHTML in a <tr> tag in Firefox, but not in IE. So I moved things around and started setting the innerHTML in the <td> tags instead and then it stopped working in Firefox but started working in IE. Eventually I found that I had to move my <button> outside of the form in order to get it to work in Firefox. This whole time I am working with a new tool - xajax - and wondering if it is the tool or the browser. Well, I decided it was the browser and the tool worked as advertized.

If you are thinking about using Ajax in one of your projects, remember that it takes a lot of patience. If your project is in PHP then take a look at xajax. It doesn’t do everything Ajax for you, but it give a nice abstraction layer for the usual stuff.

September 28th, 2006

Blogroll Z version .80 Released

Blogroll Z is a rss/atom feed aggregator. See documentation Getting Started, Configuration, and Add Blogroll Z to your page. Get downloads here. See implementations here and here.