Kyle Boddy Entrepreneur, Hacker, Biomechanics Researcher, Baseball Lover.

14Feb/110

Scaffolding in CodeIgniter: Controller Code

Now that scaffolding has finally been removed from CodeIgniter, they've removed all references to it. However, I still use this function for clients, and as a result, stick with the 1.7.3 branch for now. If you're in the same situation and need the simple controller code, here it is:


<?php
class edit extends Controller {

     function edit()
     {
          parent::Controller();
          $this->load->scaffolding('tableName');
     }
}

Be sure to properly set your database configuration connections (database.php) and scaffolding trigger (routes.php) to make this work.

8Feb/110

Why Do You Care?

"I can't imagine not caring."

My friend and colleague Zac told me of this exchange that came from one of his short stories. Zac and I were discussing our busy schedules over beers at the local karaoke dive bar. For comparison's sake, Zac is a full-time game designer and could also be described by all of the following titles: Professional book editor, short story writer, screenplay writer, social networking site designer, published poet, political scientist, and literary critic. I'm sure I've left some titles out, but I think you get the point.

We have almost no directly overlapping interests - I'm a full-time programmer/developer and also could be described as an amateur biomechanics analyst and researcher, baseball coach, exercise scientist, game theorist, kinesiologist, physics student, pharmacology researcher, and economist. Worth noting, of course, is that I have very little formal education in most of those fields, and that I don't describe myself as a professional in any of them.

Yet we share the most important thing that makes us such great friends - the passion for knowledge and deep research. We both intensely study fields that nearly everyone thinks are esoteric at best and a waste of time at worst. For Zac, this might be poetry, and for me, this is applied biomechanics as it relates to throwing a baseball (and nothing else). We both spend our "down time" watching world-class lectures on various subjects at Academic Earth (I'm currently watching Walter Lewin's Physics I: Classical Mechanics series to better understand 3-D Kinematics and Vector decomposition; these are key factors when using Direct Linear Translation in biomechanical analysis) or idly thinking about new entrepreneurial ideas.

Example: I just spent my lunch today listening to Jason Fried's TED Talk about Why Work Doesn't Happen At Work while picking at some chicken fingers from Whole Foods.

In response to my announcement of the Elo Cube project, someone on my Facebook wall asked me how I "find time" for all of these activities. I glibly responded that "I hustle every day" and "work at least 60 hours per week." Today, I thought about it more at length and wanted to figure out how many hours per week I spend on activities that most people would consider either "working" or "learning."

In a typical week, I will spend:

  • 40 hours at my full-time job working as a developer, programmer, and business analyst
  • 10 hours training athletes at my facility
  • 5 hours researching general biomechanics/applied anatomy/kinesiology/exercise science
  • 5 hours watching lectures on Academic Earth or other open-courseware sites
  • 6 hours either writing code or thinking about code for my various projects (Elo Cube, Open Elo System, Biomechanics Database, Kindred Network Algorithm)

That adds up to about 66 hours of work in an average week, which is a bit lower than I suspected. Subtract 56 hours per week for sleeping and sleeping-related activities, 7.5 hours for commuting to/from my full-time job, and that leaves an average of 5.5 hours per day of "free" time. In those 5.5 hours, I personally train myself (though some of this overlaps with training my athletes), spend time with my wife Astrid, play some games (League of Legends, Magic: The Gathering) and try to do all the other errands that I'm supposed to do (which I invariably fail at doing). As summer approaches, I will be playing baseball upwards of 12 hours per week, though I probably will cut back on that this year since I'm having a kid in mid-July!

This is turning into a rather large digression, but it's my blog, so whatever. Approximately ten years ago, my friend Liz asked me a seemingly innocent question: "Kyle - are you good at everything you do?" I proudly answered: "Yes!" It was a badge of honor to select things that I'm good at and pursue them vigorously.

Years went by and I forgot all about this exchange until it dawned on me about five years ago that this is not a good trait to have! Sure, I was above-average in everything I took interest in, but I took interest in a very few things and this stupid limitation that I imposed on myself by refusing to do things that I wasn't good at was limiting my already eroding creativity and intelligence. While I wasn't the smartest guy on the planet and couldn't get inspired by fields I truly didn't understand - typically liberal arts related fields like literature, language, and sociology/psychology - I knew that I had some predisposition for understanding the scientific method. So it would be science that I would turn to in an attempt to be bad at some things while still maintaining interest.

Since then, I've applied my admittedly limited intelligence towards science-related fields. I'm researching topics that I have no shot of being the best (or probably even above-average) at understanding: Classical Mechanics, Kinematics, Kinetics, Machine Learning, Computer Science, Kinesiology, Biomechanics, Exercise Science, and so forth. And let me tell you, when you have a stubborn ego and disposition like I do, there's a never-ending sea of knowledge to wade through on topics like "Instantaneous Acceleration and it's Effect on UCL Rupture" or "Time-Measured Changes in Shoulder Flexibility and Pitching Kinematics in Youth Baseball Athletes," much less "Jacques Distler's Critique of Garret's Lisi's Exceptionally Simple Theory of Everything" which describes Lie algebra E8.

Bringing it back full circle...

"Why do you care?"

As stated above, I can't imagine not caring about these topics. And I understand what it's like to not care about them, because just six years ago I was a troubled young adult who thought he was relatively intelligent but had nowhere to apply it to. This type of thinking is infectious and needs to be purged from the untold millions of 20-something year old graduates (or dropouts) out there. Everyone has a propensity to understand something in this world - be it science, literature, art, history, computers, or any other very broad field. By gradually getting into a field that you find interesting - perhaps you remember being intrigued by the Winged Victory of Samothrace? - and looking at unsolved problems or complex concepts in that field, you will suddenly find yourself immersed in it.

I personally can't understand how people can't watch ten minutes of Walter Lewin's physics lectures and not be instantly hooked! What got me was this simple line:

Any measurement that you make without knowledge of its uncertainty is completely meaningless.

Taken at face value, it's not that interesting. But think about the ramifications of that statement: It is perhaps an elegant and more detailed paraphrase of Richard Feynman's famous statement:

I know how hard it is to know something.

How interesting is it to think about calculating something like joint torque in biomechanics and understanding the crazy uncertainty around it! Acceleration is used to calculate joint torque, and acceleration is a second-order derivation of location. Think about all the potential for error in such a calculation, and realize that we're just talking about torque around a single joint in the body. Relate this to the rest of the world: How hard is it to truly know something infinitely more complex, like the effect of gravity between two objects or why inertia is the way it is? (These are perhaps two unfair topics considering no one knows the definitive answer to both questions!)

For me, the countless interactions in our world described by the most basic concepts of physics occupies my mind all the time. For you, it might be the indescribable nature of macro evolution or the creativity required to even conceive of the most beautiful songs we've heard.

There is no excuse for being intellectually bored or not caring about things in our world. We live in an age where information is plentiful and freely available from the most prestigious of sources on all sorts of topics. Think broadly and spend a single hour per week thinking about this kind of thing, and I bet it will spiral into something ever more interesting to you. Cast aside your prejudices about who is and who is not smart enough to study these subjects and just think.

The worst thing to happen to young people is the stigmatization of the question "Why?" Start asking yourself this question all the time. The speed at which you will realize you know nothing about the most basic interactions in our world is astounding, humbling, and altogether unbelievably amazing.

3Feb/111

Understand the Axis You Compete On

A corollary to "Focus on What Matters," understanding the axis you compete on is an important trait in any good entrepreneur. The inability to focus on the competitive edge that justifies your product or service's end cost has sunk many organizations in the critical stages of their development. I've seen this time and time again and have been guilty of it myself on more than one occasion!

We live in an increasingly more specialized society and economy - we no longer want a Virtual Private Server; we want an unmanaged VPS under $20/month running Fedora Core located in Dallas with 5 IP addresses and partial physical access through a ticketing system. We're not interested in hiring programmers/developers - we want a developer who specializes in MySQL design/administration, thorough understanding of Rails 3, and experience with Joomla, Drupal, and Magento.

The failure to compete on an axis with a low barrier to entry is what ruins most small business ideas. However, for those small businesses that get off the ground and start competing in their niche, they eventually start to think bigger - and why not? There's nothing wrong with future planning for an entrepreneur; it is the hallmark of a smart businessman. The smart entrepreneur has an exit strategy and a general - if not malleable - 3-year plan for his organization.

But don't confuse this future planning with the generalization of your niche; this is the death knell for most organizations that get too ambitious. Most small businesses dominate because they have low overhead, smart planning, patient executives, and most of all - completely rule their niche and everything that connects to it!

Example of the Failure to Understand the Relevant Axis of Competition

An organization I did some consulting for that fell for this trap: The small business was in the black year after year and experienced phenomenal growth because they were smart enough (and lucky enough) to pick an unexplored niche that would eventually blossom. Throughout the process, they accumulated a lot of technical debt even though the extent of the technology involved posting data from a web form to a database and manipulating that data on the back end for marketing/financial purposes. The response to the growing technical debt wasn't to simplify the process, but rather to expand and try and compete on the Axis of Technology.

But this was a huge mistake - the company competed on the Axis of Marketing and had a large economic First Mover advantage. Remember, the entire extent of the technical interactions of the company involved posting data from a web form, storing it into a database, and manipulating said data. Marketing specialists tracked SEO-related data and made projections from these posts and sales people used the data to show off the dominance of the company in this small industry. To make such a huge paradigm shift in an attempt to compete on the Axis of Technology made no sense - the company did not succeed because of its superior technology department, but rather because of the first mover advantage and a solid foundation of sales/marketing.

They ported their technology to a more complicated and expensive platform, changing the base language everything was programmed in, and completely overhauled the existing database, requiring a giant migration of the data to the new schema. They hired all new developers and executive staff to oversee the change, leaving the Sales and Marketing departments in the dust - making huge promises that could never be met due to the technical debt that had accumulated and the problems that would invariably crop up as a result of trying to migrate millions of rows of poorly laid-out data into a brand new invented schema.

The organization was able to make these changes because they promised the moon to the business units - unification of tools, better access to data, and faster reports!

It didn't happen: The migration was an enormous failure, the implementation of a more complicated programming foundation flopped, the tools became worse, and sales have been steadily dropping while company morale plunged.

Due to the fractured database structure, the organization now maintains a legacy database and a post-migration database - both of which have differing schemas and do not blend whatsoever. Their products exist on two platforms and all new employees must learn two separate systems, both of which have rapid changes inflicted on them due to exponentially-increasing technical debt.

All of this happened because the organization failed to understand what axis it competed on, and tried to get too fancy. In this age of specialization, right-pricing, and cheap outsourced labor, you simply cannot afford to make these types of mistakes and hope to remain relevant - or even solvent - in today's economy.

17Jan/110

array_walk() in CodeIgniter

Recently I needed to call trim() for multiple variables in an array in my CodeIgniter application, but had issues with calling the custom function using array_walk() to do so. A bit of Googling and experimentation led me to this answer:

function stuff()
    {
	    // trim array data
	    array_walk($data, array($this, 'trim_value'));

	    $this->load->view('preview_view', $data);
	}

	function trim_value(&$value)
	{
	    $value = trim($value);
	}

You have to pass array_walk() or array_walk_recursive() an array with $this as a defined variable/pointer.

Try that piece of code if you're having an issue!

2Jan/110

Workout Programming: Smolov Jr.

A friend of mine asked me about trying to work the Smolov Jr. bench program (split into 3x/week over 4 weeks) into a regular training schedule. I put a fair amount of thought into it and figured that I'd share it. Here is the exchange:

Kyle,
If you don't mind, I'd like to ask you a few questions on Smolov - specifically how it impacted recovery for the squat/deadlift.
I've decided that enough is enough re: Show and Go. The program itself is fine, but I feel as if I've been stagnating big time on both lower body lifts. My bench has also stayed the same. Part of this is due to failing to eat enough to gain weight, and part has been some poor efforts in the gym, but in any event, a change probably needs to be made.
...
I'll be squatting 2x/week - likely one time for speed and once a week where I'll work up to a heavy single.
This seems like a good program to maintain squat strength at your bodyweight; that is pretty much my plan when it comes to in-season squat programming. Speed work / heavy triples. Is that your goal? You won't drive much upwards progress in the squat with this type of program due to lack of volume.
Tuesday
DE Squats, Smolov Workout #1, DB Incline, Chins, KB Swings, Abs
Wednesday
Smolov Bench #2, JM Press, Pushups, Row Variation (either chest supported or cable)
Friday
Deadlift, Squat, Chins, GHR, Abs
Saturday
Smolov Bench #3, Push Press, DB Row, BB Curls
Smolov Bench #3 just one day after ME DL/SQ workouts + chins/pull-ups is going to be very hard, especially if you are at your upper novice limit of bench progression (while I wasn't). I strongly prefer a Sunday/Tuesday/Thursday/Friday schedule where you have at least one day off between workouts; and scheduling your ME DL on Tuesday (surrounded by fresh days).
I think you would do well to maintain progress (or gain slight progress) on the SQ while you attempt to drive bench/DL progression. Squat strength is something to focus on as a primary target and costs a lot in terms of training economy and recovery; the main secondary benefit of that type of programming is that your pulling strength will go up without much DL work. IMO you either focus on improving squat strength or maintaining it, and if you maintain it, you can focus on one other type of training goal (endurance, bench strength, weight loss, etc). Recovery is not a pitcher of water you pour into various body parts, but you knew that already.
Hope that insight helps you some for what it's worth.
13Dec/100

The Universe Is…

Filed under: Humor No Comments
7Nov/100

Merging Two Arrays of Different Size (PHP)

This isn't pretty, but I needed to write code that would merge two arrays of differing sizes. One contained injury information for 1400 players with an overlapping field of elias_id with an array of 900 players of PITCHf/x data. Simply put, I needed to insert two values from the injury array to matching players in the PITCHf/x array.

Here's how I did it with array_search() and preg_replace() - the arrays were in the format of $pitcher['elias_idxxx'] where xxx was the numeric point at which the value was in (so elias_id0 through elias_id899 for the PITCHf/x array and elias_id0 through elias_id1399 for the injury array).

Whether or not the arrays are properly formatted and constructed is not the point of this blog post. (Though it is likely that it is better done through a second recursive array, we're not selling code here. We're selling functionality.)

$x = 0;
$y = 0;
$pattern = '/[^0-9]/';

if (!@$pitcher){
	// do nothing
}
else // parse the array
{
	foreach($pitcher as $blank)
	{
		$key = array_search($pitcher['elias_id' . $x], $injuries);
		if ($key)
			{
				$y = preg_replace($pattern, '', $key);
				$pitcher['timesinjured' . $x] = $injuries['timesinjured' . $y];
				$pitcher['daysmissed' . $x] = $injuries['daysmissed' . $y];
			}
		$x++;
		if (!@$pitcher['elias_id' . $x])
			break;
	}
}