The Nemeth Law Firm

One of my best friends, Ms. Nicole Nemeth has struck out on her own, founding a law firm in the greater San Diego, CA area.

Checkout her firm’s website: http://www.thenemethlawfirm.com/

And if you’re in need of legal advice, especially with business and contract law, divorce, personal injury or even arbitration in the San Diego area, check her out. She’s one of the brightest people I know and will take great care of you.

Modulus Sorting – Alternative to ORDER BY RAND()

If you have been doing LAMP (or anything MySQL) related for a while, you already know that the simplest way of getting a random set of rows from a table by using ORDER BY RAND() is a really Bad IdeaTM. The guts of SQL require that this solution generate a random number for each of the posts in your result set and then sort by this. Random numbers are generally expensive, and this requires one be made for each row, which as your result set grows will become quite the bottleneck.

I have seen other alternatives to this:

I am testing out another approach that I’m calling “modulus” sorting. The ID approach is decent, but as tables get large, you end up doing a large data transfer to get all of those IDs. My solution may not be truly random, but it appears to be doing nicely so far.

First query:
$query = “SELECT COUNT(*) AS c FROM `table`”;

Second query:
$query = “SELECT * FROM `table` ORDER BY `id` % ” . mt_rand(0, $count / 2);

Essentially, we pull the number of records in the table and assume that the IDs are fairly evenly distributed and then sort them by the modulus of their ID and a random value. The modulus operator is quite a bit faster than RAND() and the results I have been getting so far are random enough for my purposes. I’ll drop in updates as we see how it goes!

Tie Guy, Reporting for Duty

“I’ve wanted to ask for a while… why do you wear a tie?”

Not an unusual question for me. My office dress code is perfectly fine with jeans and a T-Shirt; in fact, that’s the norm. Plaid flannel, beige shorts, “pumped up kicks”, all good. As far as I know, I’m the only one who shows up in a shirt and tie on a daily basis. Honestly, the fact that I can dress differently and not be an outsider is an ironic testament to the open-mindedness of the office culture.

But why do I do it?

The simple answer: I like it.

The longer answer… well that’s more complicated. Personally, the process of getting ready in the morning and “suiting up” (sans blazer during the warmer months) gets me in the mood for work every day. It is a ritual sacrifice to the gods of business in hopes they will bless me with fewer bug reports. But when I get those bug reports, you can bet I’m ready to take them on.

To me, the tie is a reminder that I am part of a larger whole. It is a reminder in looking professional that I should also act professional. When I’m having a bad day and drudging through complicated problems, it’s a reminder that whenever it sucks for me, it sucks for somebody else who is using my creations even worse. Every moment I haven’t fixed the problem, they are less productive. It’s a reminder that as much as it would be nice to pass the problem on to somebody and forget about it, it is my responsibility, as part of the bigger group, to make sure it gets solved and not endlessly passed around. The people who need it fixed are funding our paychecks and they can take their money elsewhere. It is a reminder that when I screw up and it could affect other members of the greater team, they have a right to know as soon as possible so they can have the best shot at solving whatever problems it may cause them.

If a problem becomes frustrating and I want to just throw up my hands, it is a reminder that getting angry doesn’t help the company. Holding grudges doesn’t solve the problems for the customer. It’s a reminder to stop taking it personally and just look for the path that leads to an answer, no matter how much patience or time that answer is going to take. As a professional, it is my responsibility to have answers, get answers or direct people to answers. We’re all in it together.

You don’t need a tie to be professional, and a lot of people are much more comfortable not wearing one. Mandatory dress codes enforcing ties or suits don’t lead to more professional employees.

I just like ties.

The tie is my talisman.

Flow Revisited

During a big buy-out announcement recently within my company, one of the speakers mentioned the book Drive: The Surprising Truth About What Motivates Us. Now that I spend a lot of time as an NYC straphanger, I get a lot reading in during my daily commute and decided that coming from influential and successful people, it was a safe bet that it was a good read.

Let me just say up front: wow. It is not a smooth read, and at times the writing style is a bit repetitive, but the content of the book is amazing, and the majority of it is references to psychological studies around the world. If you have any desire to understand what motivates you or how you as a manager could motivate your employees, this is a must read. I’ve discovered things about myself that I did not effectively realize before, and beyond that discovered that I am not alone in them.

The core concept of the book is that human beings are far more complicated than can be modeled with a simple reward-driven behavior (“carrot and stick“). We have an innate desire to solve problems as well. When it comes to salary, as long as we are receiving fair pay or are not having money problems, more money is a very poor motivator. In fact, if you dangle the carrot of a (especially monetary) reward as a reason to do something, you can severely damage long term motivation and the desire to excel on that project. Essentially you can turn a fun project into drudgery by associating money with it.

They actually brought up Open Source web development as an example of how great things can come out of volunteer work. I take a bit of issue with that since most successful open source projects have some of the core pieces in place and are only supported because big money-spending companies back them and pay people within their own companies to make contributions. However, the idea is still reasonably sound.

Bringing this back to my previous post on the “good vs bad” sides of achieving “flow“, the book noted that it becomes much more difficult to reach flow when you are working on a project for a monetary reward. This helps to explain why when you are writing code for fun and solving problems on your own time, you can end up glancing bleary-eyed out of the window and realize it’s 5AM. If you are doing the same project for work because somebody is pushing a deadline on you, you can be checking the clock every five minutes until it’s 6PM and you can leave without feeling too guilty.

In independent analysis of the results of work in both situations, the people building for fun very consistently create higher quality code.

I say score ++ for flow.

Facebook Harassing Goo.gl Users?

So I work in social media for a large advertising-centric company, and one of the things that I do is test integration with Facebook Pages. I run a simple test Facebook Page to try out different things on, and I recently started having issues with including any goo.gl URL in a post to the page:

If I have a simple link to XKCD, shortened with Goo.GL: http://goo.gl/b4UzX and shortened with Bitly: http://bit.ly/1pB1Uk, I get the following results when I try to post them onto the wall of the page:

Original XKCD link: posts and embeds just fine
Bitly link: posts and embeds just fine
Goo.gl link: always asks to solve a CAPTCHA

I’ve tried it with a bunch of other sites and some other URL shorteners and have had no issues. Is anyone else having this problem? Any other Google-related services that are being tampered with? It’s not blocking it, it just feels like harassment!

Programmer “Flow”: Good or Bad?

If you’ve done any mind intensive task, even taking a very challenging but doable exam, you probably understand the concept of “flow”. Flow (aka getting “in the zone”) happens when you are hyper-focused on a particular problem or task, and you are able to provide contiguous output on the problem, pretty much non-stop.

Personally, coffee helps me get in the flow a lot. If I have some audio distractions around me, then Trance music can help too (preferably very repetitive and with no words). I know some people who compare the feeling of this “flow” to what happens when you’re on Adderall. The rest of the world and the seconds that it ticks with just disappear, and as a programmer, your fingers never stop typing.

It’s an amazing feeling, and I have within the past month read two different authoritative reviews on how it really affects your productivity. According to Robert C Martin in The Clean Coder, flow is patently bad. He compares it to being hypnotized (I’m not arguing there), but he says code produced in the flow is code that is unaware of the bigger picture, and not flexible. A lot of code produced in this way has to be revisited and re-architected at a later date because it will be single-minded and not jive with the rest of the program.

Just today, I read one of the old Joel on Software posts by Joel Spolsky entitled “Where do These People Get Their (Unoriginal) Ideas?”  where he says that achieving flow is one of the basic requirements of programming in general as focusing on the problem very closely helps you solve it quickly and more thoroughly.

What are your experiences with this?

Personally, I fall more on Joel’s side, but with some reservations. You need to make sure you have your environment set up correctly and you know proper programming standards. My most solid code has been written in the flow while following TDD. I was able to easily refactor it for later additions and it was solid, usable and well documented (I write all of my PHP code with PHPDoc / JavaDoc style comments). Putting all of these together and still focusing hard on the problem gives me excellent progress while still generating maintainable code.

Caribbean Cruise 2011

So for a few years now, my girlfriend and I have gone on a cruise in the Caribbean Sea in December. This year, we brought her parents along with and hit San Juan, St. Thomas, St. Lucia, St. Kitts and St. Martin. I just bought a new Sony Alpha A-500 and took 1,600 pictures throughout the cruise! I was brand new to the camera and just getting used to the lens and exposure options, but here are a few of my favorite pics!

Speaking to NY-PHP Bootup to Startup

I will be speaking to the Bootup to Startup with NY PHP group on Tuesday, February 28th at IBM. The topic for discussion is “Talk Virtualization” and this is the abstract:

Virtualization has changed the platform playing field for web development considerably. With the advent of platforms like Amazon’s EC2, not only can our PHP apps scale outward with a few clicks of the mouse, but our apps can also be platform-aware and provide all of the right metrics to know when is the right time to scale. This presentation is going to cover the core models and issues that you will encounter as a PHP programmer in a virtualized world. Focusing on EC2, but brushing on private virtual infrastructures with VMWare, Xen and KVM, we will talk about how the virtual environment affects your production code execution and your development environment as well as what new considerations you should be taking into account for every app you write. We will finish by going over future features you might want to consider that this infrastructure approach makes possible.

Material will be a combination of slide show and live demos with the technology.

Event information hasn’t been posted yet, but here’s a link to the Meetup Event: http://www.meetup.com/new-york-php/events/32189482/

About Justin

Justin grew up in the back woods of Maine at the end of a dirt road with no electricity. True story. His friend claims that when he finally moved into modern civilization at the age of 12, he decided he had to learn these computer things, and kind of over-compensated. Justin started programming at 13 and loved it so much he got a bachelors in it from University of Connecticut. Working on a lot of very small teams he also had to branch out into system administration land and has worked using VMWare ESXi, Xen, and Amazon EC2. He was a major contributor early on to the Zentific Xen management UI project and has run LAMP clusters along with NoSQL clusters on EC2 for a New York advertising agency, supporting hundreds of millions of ad impressions a day.