Categories
Other Other Programming PHP Programming

SVN Merge Example (Trunk to Branch)

I’m often in the situation where I need to merge changes from the trunk development into a branch.  I can never, EVER, remember the command, so I’m putting in here in hopes that I can reference it again and that other people might find it useful.

svn merge -r x:y svn://repositoryURL/repo/trunk/ .

So, how does it work? X is the revision that you branched at. This can also be the revision that you last merged changes from. Y is the version that you want to merge up to.  In most instances, HEAD is probably what you’re looking for.

Note:  Using –dry-run if you want to see the changes that will be made before actually doing it.  It takes some of the “this is scary” out of merging.

Categories
Other PHP Programming

Creating a Flexible Caching Module

I work for a great company, I really do.  Sure we have our problems (like just coming out of the developer stone age), but overall I work with smart, friendly people who are passionate about what they do.  One of the things that always bugged me though was the lack of any sort of caching in our CMS.  Most times it’s not needed, but when an operation takes about 100 queries or so to finish, then it’s time to start caching.

Since I’m a bit of an efficiency freak, I thought I would take a crack at writing a flexible caching module that is easy for our developers to use.  So what do “easy” and “flexible” mean?  To be “easy”, the caching module must be usable by even a novice developer and have a limited number of options.  For instance, I ended up deciding that we really only need two public methods, and one public property.

  • $cache->exists – If “$cache” is a cache object, calling exists checks to see if the cached object already exists in the database.  It also checks to see if it’s expired or not.  If it’s expired or non-existent, it returns false.   It returns true if the cached object exists and is up to date.
  • $cache->put($val) – This is how you store something in cache.  It can be any type of serializable PHP object.  So basically, resource types are off limits but objects, arrays, variables, entire web pages, etc. can be used.
  • $cache->get() – This fetches the object stored  in the cache.  It handles the re-serialization of it as well, so it really makes things pretty idiot proof.

What about flexible?  Well, by that I mean we need to be able to transparently implement several different types of caching.  Since we’re just crawling out of the dark ages, I opted to implement a fallback caching mechanism.  Here’s how it works.

  • The programmer defines a variable in our settings area to be which caching option he/she wants to use.  Options are memcached, file, mysql.
  • If the setting isn’t defined, we try memcached by default.  This is by far the best caching system to use, so it makes sense to try it first.
  • If memcached fails, we go to a database caching schema.  While not nearly as good as using memcached, it’s possible it could save you tons of queries on your database.
  • If the user chooses file caching, we do that.  It’s a pretty bad idea to use in most cases, but may still have it’s uses.

So why did it come this?  It’s not that we host terribly high-volume sites, but that our CMS is super slow.  A full-on page will take about 4 seconds to load to your screen completely, and that’s running local on the network.  One of the main problems is that we use output bufferring extensively.  The ENTIRE FRIGGIN PAGE is buffered.  This has 3 side effects:

  1. Slight performance loss due to bufferring.
  2. Apparent page load time sucks because the browser has to wait for the entire page to be generated before getting output.
  3. Development is super easy because you don’t ever have to worry about output being sent before doing a call like “header()”.

We can’t remove output buffering unfortunately.  It’s at the very core of our CMS and development practices, so it just won’t work.  To get the load time to generate the page as low as possible, I decided that caching was needed.

So what sort of problems do we run in to with this caching module?  Glad you asked!  Many of the problems aren’t specific to this caching module, but to caching in general.  The quick list:

  • If the original query wasn’t complicated, it’s not worth storing the results.  The number of queries the caching module does in MySQL mode is 3.  If your initial query was less than that, or not a super-complex-mega-join, it’s not worth using.  This caveat goes away in memcached mode.
  • Smart naming and design.  You have to be very careful out what you cache, and when.  Remember, page content and queries probably change when a user is logged in or on a different device.  Just things to keep in mind.
  • Getting developers to use it.  Not everyone likes to learn, let alone change their habits.  The biggest barrier to this is getting people to use it.  Some people don’t care about efficiency either (sad, I know), but at least our system administrator thanks me.

The caching module seems to work pretty well too.  On one particularly SQL heavy page, I reduced page load time from 14 seconds (ridiculous) to just under 6 seconds (still bad, but getting better).

That’s it for now.  Any questions or comments are welcome.

Categories
Other

Are we really worth 3.5 million?

A news (I use this term loosely) article recently came across TechCrunch about a Google engineer being offered $3.5 million in restricted stock to not leave for Facebook.  Now, I was alway taught to not undervalue myself, and I completely agree with that line of thought.  However, 3.5 million is ridiculous.  How many startups could you fund with that kind of money?  How many lives could be saved through research, aid, or vaccines?   How much good could be done with $3.5 million?

I understand that this may just be a rumor (it is TechCrunch after all), but it brings up a good point.  As programmers we’ve been taught that our skills are irreplaceable, but I don’t believe that.  Yes we have a hard job, and being good at what we do is even harder, but we’re not worth $3.5 million.  $100,000 for a good programmer, sure.  $500,000 for a “rock star”, maybe. But never $3.5 million.

Google is afraid of losing talent, but this seems like a knee-jerk reaction.  There will always be brilliant engineers who want to work for Google, so I say let him/her go.  Put that $3.5 million to use somewhere it can make a difference, not in the pocket of someone who likely already has a ton of cash.  Besides, if this person is leaving for Facebook, they are probably burnt out or looking for a new challenge anyways.  It happens, and no amount of money will change the fact that they are probably going to leave after their contract is up anyways.

Categories
Other

It’s Not Enough

I’m 24 (almost 25, but lets not go there). In my life I’ve accomplished many things, but with the exception of one, they aren’t very important. I’ve graduated high school, graduated college, got accepted to grad school, got married (the important thing), and created a start-up that failed. I have a good paying job (for the region), doing something I love (web development), at an amazing company with smart co-workers. But I still feel unfulfilled. It just isn’t enough.

Don’t take this the wrong way. I’ve done a lot of stuff. It’s not easy to graduate college. Getting accepted to grad school is hard too. But the thing is, none of these things stand out. Everyone graduates from college these days, and dropping out of grad school isn’t exactly a stand out thing either. I half-assed a start-up that was doomed to failure too. Out of all these things, I learned the most from that failure. I learned that without the right motivation and passion I will not make a good product. I also learned the most import lesson of all: It’s ok to fail.

So here I am now, happily married and decidedly middle class. The American dream right? Not for me. It’s not enough. I want to be passionate about the things I do again. Aside from my wife, nobody in my family seems to understand this. Maybe it’s because I come from a poor family. They feel that because I have a good paying job I should be happy. But the thing is, I’m not. Money just isn’t enough for me to be happy. I need to be intellectually challenged, passionate about what I’m working on, and excited. Now that I’m at this point in my life, I’ve realized that the ceiling is much higher than I ever thought possible.

Where does this lead me? For me, it means starting something that I can be passionate about. Be it a blessing or a curse, the Hacker News community has put the entreupanurial spirit in me, so I’m going to do another start-up (“Do or Do Not. There is no try.”). This time with a long time friend and an idea that seems extremely viable. But why should it be different this time? Maybe it won’t be, but it feels different this time. It’s like when you go for a run, and within the first 10 steps you can tell if it’s going to be a struggle every step of the way or smooth sailing. This feels like smooth sailing, so I’m hopeful. Most importantly though, I’m excited.

I wonder if this new start-up will be enough to satiate my thirst for knowledge, adventure, and success. I hope it is, but I feel that nothing will ever be enough. I’ll always aspire towards the next level. I’ll always work late into the night until my wife comes in and tells me to go to bed. I’ll never be fully satisfied, but maybe some day I’ll be just just satisfied enough to be happy.

Categories
Other

Exorithm – An Online PHP Playground

As I was cruising about the web this morning I stumbled upon Exorithm, an online PHP execution environment (or playground as I like to call it).  Actually, it’s a lot more than that.  It’s a hub for people to learn, create, and share.  Exorithm allows PHP developers to create functions that other people might find useful and share them.  For instance, just this morning there were algorithms on the site for reversing strings, drawing shapes, and sorting data.

It’s worth checking out.  I spent a good half hour just trying to break their evaluation environment (no luck!) and then another few minutes cruising the algorithms section.  Their web site is http://www.eXorithm.com.

Exorithm

Categories
Other

Traffic Analysis (Hacker News & Reddit Focus)

Over the past month I’ve started pulling in some modest traffic to this blog.  Now that I’ve gotten a few thousand visitors over that past few weeks, I thought it might be time to do a quick analysis of my traffic.

Overview

As you can see, my traffic goes in spikes.  Each of those spikes corresponds to when a new article is published.  Without the outliers, there is still a steady increase in traffic.  I’ve also noticed that over the past several weeks my average time on site has increased to over 1 minute ( it was somewhere near 45 seconds before I started posting articles frequently).  The best stat on here for me is that I actually have returning visitors.  Granted, they only make up ~16% of the traffic, but it’s still good to see.

Reddit -vs- Hacker News


As you can see, I clearly have Reddit and Hacker News to thank for my traffic numbers.  Without you guys (and girls), it wouldn’t be nearly as fun to write.  However, there is some interesting info tucked away in that table.  The most important piece is “Avg. Time On Site”.  Reddit’s average time is only 27 seconds, as opposed to Hacker News which is nearly 2 minutes.  This tells me that the typical Reddit user probably has no attention span (likely) and I should probably add a TLDR block at the beginning of each article (I won’t, don’t worry).   On the other hand, this might just mean that Hacker News users open up a ton of tabs and it takes 90 seconds on average to get to mine.  I tend to think it’s just lower brow traffic from Reddit, but I’ll give them the benefit of the doubt.

The bounce rate from Hacker News is also slightly better, but still nowhere near as good as traffice from PHPDeveloper.org or StumbleUpon.

OS & Browsers


There aren’t any surprises here.  Windows + Firefox is leading the pack, with Windows + Chrome closing in right behind them.  Mac users are also making a strong showing.  As this is a technical blog, this doesn’t surprise me at all.

Categories
Other

Google Keyword Tool

It’s not easy knowing what to write about.  When you run a niche site like this, it’s even harder.  One of the tools I rely heavily on to tell whether I should invest the time writing a post or not is the Google Keyword Tool.  The Google Keyword Tool allows you enter key words, and then it tells you the monthly search volume on those words, the competition, and even monthly local searches.  But it doesn’t stop there, it gives you other keywords that may be relevant to you and displays statistics on those as well.   By far though, the most important feature is the competition rating.  It lets you see if you should even bother trying to go after that niche or not.

Google Keyword Tool

Categories
Other

The New Digg Error Page

I was recently checking out the new version of Digg, when I hit their error page.

Digg Oregon Train Error Page (click to enlarge)

Nice job leveraging Oregon Trail guys.