Skip to content

warp.byu.edu

Conan Albrecht's Musings

For years now, Utah fishing license sales have been declining (hunting has too).  I’ve read a multitude of articles explaining why the number of fishermen are declining and arguing how to increase the numbers.  I’ve hunted and fished all my life, and the reasons for the decline are quite clear to me: hunting and fishing in the State of Utah is simply not much fun anymore.  Herd populations are mismanaged, licenses are mismanaged, and the number of rules has exploded.

Last week, three of my brothers and their families went fishing on the Boulder Mountain in Southern Utah.  They prepared food and supplies, spent hundreds of dollars in gas money, loaded up the 4-wheelers, and drove into a small lake in the mountains.  After 3 hours of fishing, one of the State’s fish cops came over and gave them tickets costing a minimum of $100 each (the actual amount will be decided by a judge).  He readily admitted to spying on them for three full hours with binoculars. I’ll explain just one of the bogus tickets to one of my brothers.

What was the offense of my brother?  He was “party fishing”, which means a group of people were sharing their fishing poles and fish.  My brother was there with his wife and two kids: ages 2 and 4.  He had three fishing poles: one for him, one for his wife, and a small “Barbie” pole for his kids.  Like any good father, he was baiting their hooks, casting their lines, and even hooking the fish for his kids to reel in.  His wife fished too, but she mostly was letting my brother do the work while she focused more on the littles.

Apparently in the great State of Utah, family fishing equals party fishing, which is somehow against the law.  What used to be a family activity is now a “state nannied” activity governed by a multitude of laws that differ from lake to lake.  In the past, the rules were simple for almost every lake in the state: the limit was 8 fish for adults and 4 fish for children.  Today, we have to look up the river or lake we are going to for the specific rules on fish species, minimum and maximum lengths, bait types, off-road vehicle use, road closures, etc.

We used to use fishing as a means to raise our kids.  We used to look forward each year to the hunt where our families came together and enjoyed the outdoors.  Now we get tickets for breaking ridiculous laws.

The State of Utah needs to realize that fishing and hunting are meant to be fun and family-oriented.  It isn’t a business for the State to make money on.  Fish cops don’t exist to just give tickets and bother everyone.  Fishermen are the last group that would want the rivers or lakes depleted of fish.  They have inherent interest in making sure the wilderness is there for tomorrow’s catch.  A select few will certainly take advantage of the system, but most will respect nature and fish wisely.

Microsoft is missing the point with its XPS format.  XPS is a MS’s answer to the ubiquitous PDF format.  I’m fine with MS wanting to provide an alternative to PDF; certainly, the benefit of standards is there are always so many of them!

What I’m not fine with is the lack of a free reader for every operating system.  If XPS is supposed to be a “printed” format, why can’t I read them on Mac or Linux?  Don’t tell me that Microsoft thinks XPS is important enough to make me switch to Windows just so I can read the documents.  I didn’t choose my operating system lightly, and if MS wants me to use XPS, it needs to provide a reader for the primary 3 operating systems.  Even if I did use Windows and could read XPS myself, I wouldn’t use it because many who I sent it to wouldn’t be able to read it.

The point of a printed document format is ubiquity.  Perhaps MS has a different goal in mind, but if the goal is to compete with PDF, MS needs to rethink this one.

BTW, I know many of you are saying, “but there are options for Mac like OpenOffice or NiXPS or PageMark”.  First, I’m not installing a whole office suite to read a single file.  Second, I’m not paying for PageMark just to read files in a format that is supposed to be “common”.  Third, I want something from Microsoft; it is their format, and they should provide the software rather than making me dig around.

/rant.  I guess I’ll send an attachment to my Gmail account so I can “preview” the document.

I’ve had a quote labeled “The Human Experience” on my blog for several years.  Let me try to explain my reasons for placing this quote on my home page.  The quote is a modification of Heinlein’s famous quote.

Specialization has brought amazing advances; indeed, it enables the modern world.  When each family had to provide for its own basics (food, water, security, etc.), people had little time to explore the music, science, technology, and other learning.  I fully realize that specialization enables cars, planes, bicycles, grocery stores, space shuttles, movies, books, shipping containers, electricity, and so many other fantastic things.  We live better than the kings and queens of the past (indoor toilets and nearly unlimited hot showers alone prove this one!).

Yet with all of these advancements made possible by specialization, we have lost something.  We have lost our ability to meet our own needs.  In many ways, we are disconnected from reality.  Think of all the ways in which we no longer actively participate in basic life necessities.  I’ll have to generalize to the majority of the population with these examples:

  • We no longer make our own food, from hunting to gardening.  For many children, hamburger meat “grows” at the supermarket — the thought of killing an animal to get that meat is unthinkable, even though it happens every time.  As a hunter, I can tell you that there is something of a connection to the land and earth that occurs when hunting, cleaning an animal, bringing it home, cutting the meat, and placing in freezer bags.  For one moment each year, I and my family see the process start to finish.  Something similar occurs when we as humans dig our hands into freshly-tilled soil as we plant our gardens, watch the plants grow, prune and weed, and ultimately harvest the food.  There’s a whole set of knowledge about growing fruits and vegetables that is being lost in the majority of the population.
  • For many, we no longer care for our properties, cars, and other possessions.  A large part of the population lives in apartments where the grounds are manicured by hired help.  For many, sinks and toilets and electrical switches are fixed with a call to the maintenance man.  Garage-based amateurs used to work on their cars; modern cars don’t allow this, and some even fix flat tires by waiting for the government-based roadside helpers that drive the freeways.  In today’s world, it’s often easier and net-cash-positive to hire maintenance work and spend the time making money at our specialties.
  • We expect a pill to solve any health problem, including many things that would be better solved by exercising more and eating more healthy food.  I’m particularly bad at this one, and how absolutely wonderful modern medicine is.  But as with most things, we sometimes push it too far.
  • Even in our modern warfare, we press a button hundreds or thousands of miles from our enemies.  A missile or other implement races across those miles, and we watch our attack on a video monitor.  In the past, we had to physically fight with gory swords and clubs.  We immediately saw the effect of our actions.  With modern rifles, missiles, and now even autonomous planes, we are far removed from our actions.
  • Our kids would much rather build a virtual world on their iPads rather than a sand castle with their hands in the backyard.  They would rather shoot virtual pixels in the shape of monsters than watch watermelons explode when hit by a real .223 bullet at the shooting range.  They would rather text or post on a virtual wall than speak or see each other face to face.  In fact, I watch many experience real apprehension when they have to make a real phone call.

I could continue this list, but I trust these are enough to make the point.  None of the above are inherently bad — I fully participate in the modern medical system, including pills.  As a programmer, I spend much of my day in the virtual world.  I don’t fix my own cars.  My family visits the supermarket regularly.  I contracted out almost all the work on the house we just built (including the general contracting).  As a faculty member that primarily works with words, code, and equations, I fully realize that it takes a real specialist to correctly build a modern house.

But I look for opportunities to be a generalist — to help my family learn and grow in the basic life skills.   Here’s a few examples: I’ve spent many evening hours this week digging a trampoline pit.  I had a neighbor with a tractor help do the major part of the pit, but I’m finishing the work with a pick axe and shovel.  I’ll lay the cinder block walls myself.  This trampoline pit is a great way for me to connect and learn general skills because it doesn’t have to be done perfectly (and we all know I won’t do it even close to perfect!).  My wife started the seeds for our garden last night.  We’ll grow the plants initially in our basement, then transplant them outside when it is warm enough.  We planted over 100 trees around our yard last Saturday.  We have chickens in the backyard that we have to take care of each day.

As we continue our amazing, specialist-based society, we need to ensure that each rising generation understands the basics.  We need to ensure that we don’t lose the very skills we may someday need.  We don’t need to swear off modern society, go off the grid, and live in the desert somewhere.  We just need to look for opportunities.  By keeping a small garden, hunting a little bit from field to the dinner table, learning new cooking recipes, learning to drive a stick shift car, learning to swim, learning to solve algebraic equations and proofs, practicing our writing, reading good books, refreshing our first aid knowledge, learning a musical instrument, fixing our own computers and homes and machines, interacting with dogs and cats and animals, investing with play money or a small amount of real money, reading history, and actively participating in so many other opportunities, we build our generalist knowledge.

In my humble opinion, this is a goal that should be part of every year of our lives.  By keeping general, basic life skills alive, we maintain our independence and freedom while still enjoying the benefits of specialization.

I recently purchased a commuter car for my drive to work each day. Being the typical geek I claim to be, I researched a lot of new and used cars, and I prepared several spreadsheets. One thing that surprised me is that hybrids really don’t make sense financially.  You might save in gas, but the up-front and maintenance costs seriously outweigh any gains.  Most of the 2012 compact cars (Ford Focus, Honda Civic, Chevy Cruze, Hyundai Elantra, and several others) get upwards of 40mpg, which is pretty close to the Prius without all the complicated hardware.

Let me say up front that if you want a hybrid because you 1) just like them, or 2) want to save the planet, this post isn’t for you.  I’m arguing strictly from a financial standpoint.  I was driving a full-size truck–which I absolutely loved driving–but the 15mpg over an 40 minute commute (each way) several times a week was doing serious damage to my bank account.  My new Civic EX has lessened the strain, but I still haven’t found a way to get it over the rocks to my favorite fishing holes…

I did several spreadsheets, but the simple math is quite sufficient to illustrate the costs of a hybrid over modern compact cars.  For the sake of this discussion, I’ll compare the best mpg hybrid, the Toyota Prius with 50 mpg average, with my 2012 Civic at 37.5 mpg.  Note that I just returned from a 3 hour trip over fairly level ground going 70-80 mph on the freeway, and my Civic achieved 43.4 mpg (on the cheapest, 85 octane gas, as measured by refilling the tank and doing the math by hand), so I’m being quite conservative in the Civic’s mpg abilities.  In reality, I’ve seen better than this.  In combined city/highway, I typically see 38-40 mpg with A/C, radio, and navigation on; I don’t see below 38 mpg unless I’m gunning it.  Note that my experience is better mileage than the government’s 32 mpg estimate for my version of the 2012 Civic, but I’ve been driving a bit like an old grandma–which you have to do with either the Civic or Prius to get the great mpg numbers.  In pure city, stop-and-go driving (again with slow acceleration), I get 35-37 mpg, again quite a bit higher than the government’s 28 mpg rating.  And I mean no offense to any old grandmas reading this. :)

To keep things round in the math below, I’ll conservatively assume my Civic gets an average of 37.5 mpg.  I’ll further assume that I’ll drive 15,000 miles per year.  Many people don’t drive this many miles, and the less miles a person drives in a year, the better the Civic looks financially.  More miles in a year will increase the benefit of the Prius’s 50mpg.   Finally, I’ll assume $4.00 gas, which is higher than today’s $3.50.  But I assume gas will go higher rather than lower, so I’ll assume $4 per gallon.

Here’s the simple math:

  • Prius at 50mpg over 15,000 miles = 300 gallons of gas per year.  At $4/gallon, this equals $1,200 per year.
  • Civic at 37.5mpg over 15,000 miles = 400 gallons of gas per year.  At $4/gallon, this equals $1,600 per year.

In other words, the Prius would save me about $400 per year in gas compared to a Civic.  With this $400 number in mind, consider the extra expenses of the Prius:

  • In my shopping, the Prius was usually $4,000 more than a comparable Civic (same status (new/used), same year, same miles, same trim).  This held fairly true in both the used market (2006+) and in new 2012 models.  On this point alone, it would take 10 years of driving the Prius to make it worth my initial investment– and this fully ignores the time value of money.
  • The Prius’s batteries won’t last forever.  Most web sites I’ve read say that the batteries will need replacing after about 6-8 years.  From my reading, this runs around $3,000.  From a non-financial sense, I’m not even convinced that hybrids are all that “green” with the number of batteries they will send to the landfill in the coming years.

Holding all else equal, the $7,000 costs above swayed me away from the hybrids.  It would take 17.5 years to pay back the difference (this counts only one battery change).  From a purely financial perspective, the two cars aren’t even in the same ballpark.

Even if a person drove 30,000 miles per year, the difference would only be $800/year.  It would take almost 9 years to gain the $7,000 back (again ignoring the time value of money).  I feel like I’m being overly fair to the Prius — my Civic gets better mpg than I’m giving it.

Adding to the financial expenses, hybrids drive different than regular cars.  They use variable gear ratio engines that shift funny, and the constant on and off of the engine is, at the very least, different.  Some may enjoy this new tech, but after driving the Civics (hybrid and regular) back to back at the dealer, I definitely liked the drive and pep of the traditional Civic over the hybrid version.

The Civic (and its many very nice competitors) has a traditional engine, a traditional drive, a much simpler overall system, and a cheaper purchase price.  Yet I see a lot of Prius and other hybrids on the road–are people just trying to be green, is the Prius really that nice to drive, or are they missing the financial point?

I recently purchased a Honda Civic to commute to work with, and it has a very cool Bluetooth interface for my phone — both for phone calls and for music/podcasting.  The phone connects amazingly well each time I get in the car.

However, when I first paired the car with my Galaxy S2, it disconnected/reconnected every 60 seconds, making calls or music playback impossible.  A quick web search showed that the phone has problems with many different cars.

The issue is with the transfer of phonebook information from the phone to the car.  This is done by the /system/app/BluetoothPbap.apk application.  Simply disabling this application from running fixes the problem.  Once fixed, the phone stays connected perfectly.

To disable the BluetoothPbap service, I visited the Galaxy S2 rooting page over at xda-developers.  In particular, I went to the specific Sprint Epic Touch 4G forum and downloaded the one-click root kit for my phone.  I used the “official” Samsung image for my phone, only with root privileges enabled.

Once I had rooted the phone, I renamed the /system/app/BluetoothPbap.apk file to /system/app/BluetoothPbap.apk.bak.  I restarted the phone, and the service never ran again.

Today I switched the BookEducator server from Apache/mod-wsgi to Nginx/uwsgi.  I needed the X-SendFile feature of Nginx, and while I could have added the X-SendFile module to Apache, the memory issues I’ve been having with Apache pushed me over to Nginx.  Here’s some initial thoughts on Nginx:

  • Nginx has a much smaller memory footprint than Apache.  Apache using too much memory was the reason for this switch.  Nginx is running on about a quarter of the memory.  This may change as the web server continues over the next few weeks, but my observations of less memory are in line with what I’ve heard about Nginx.
  • Nginx seems to be faster out of the box.  I had tweaked the settings on Apache to make it fast, but I think Nginx gets the speed without tweaks.  I didn’t collect any real statistics on this — just a feel after installing both.
  • Nginx’s documentation is as dismal as Apache’s.  I have never been very satisfied with Apache’s dictionary-like approach to documentation, and Nginx isn’t much better.
  • Nginx’s configuration files are much simpler/cleaner than Apache’s.  So while the documentation was difficult, I was able to get Nginx up pretty quickly because the configuration files were fairly obvious.  Nginx is just a lot nicer to work with.
  • Apache’s mod-wsgi (the Python web app connector) plugs directly into Apache, which I like.  Nginx requires a separate installation of a wsgi server like uwsgi, which runs on its own port/socket.  Nginx at least knows how to connect to the app server, but I now have two servers to keep running instead of one.

Nginx seems to be purring smoothly–and with less resources.  I’ll post again in a few weeks with further impressions.

There are times when I need to wait for an event to occur in Javascript.  For example, rich text editors like elRTE or CKEditor can take several seconds to load on some browsers.  While some of these editors provide a callback function that is called when they are ready, others do not.  The callback function approach is the right way to do this, but it isn’t always available.  Here’s a clever way to make it work without much code, global variables, or threading.

The idea is to check whether the condition is satisfied (in the editor case, whether the editor is setup and ready for use) every 1/10 of a second.  Once the condition is satisfied, we run the routine and stop checking.  A final addition to the process is to timeout after one minute or so if the condition never gets satisfied.  Suppose the editor never becomes “ready” (because of a bug in the code).  We don’t want our checking routine to keep running for the life of the page.  We want to stop checking after a timeout period.

Javascript, being the lame language it is IMO, doesn’t provide a “sleep” function.  The only way to sleep in Javascript is to call setTimeout after each check.  This sets a timer to run our code again after a given length of time.  (I should also say that the newest browsers support a new idea of Web Workers–real threads–but these only work on newer browsers and might be a bit heavy for our purposes here.)

I’ll first give the code, then I’ll explain the important parts of it:

<script>
  (function(start_time) {
    if (condition) {
      console.log('Component is ready, so running code!');
      // put your code here
    }else if (new Date().getTime() - start_time < 60000) {
      console.log('Condition not met yet...waiting 100 ms.');
      setTimeout(arguments.callee, 100, start_time);
    }//if
  })(new Date().getTime());
</script>

First, note that the function doesn’t have a name — it’s a single use, anonymous function.  This is important because it creates its own scope for variables.  Since we don’t define any global variables, we won’t mess with other scripts on the page.  Once the function is done running, it and everything that goes with it can be garbage collected.

To call the unnamed function, we define it and immediately call it with (function() { })(params).  A function like this can only be called one time from the main scope because it never gets a name.  It gets defined and then executed immediately.

Second, note the single parameter to the function: the start time in milliseconds.  This allows us to check whether the checking has been happening for too long.  If the current time minus the start time is greater than 60,000 milliseconds (one minute), we don’t set the timer again.  The process stops because we assume something went wrong and the condition will never be satisfied.

Third, the condition in the first if statement checks whether the component is ready or not.  This is specific to whatever you are waiting for, of course, so I’ve just put the pseudocode “condition” word in there.  You obviously need to change this to a real true/false evaluator.  In my case with the rich text editor, I use JQuery to check whether the embedded <iframe> has been created: if ($(‘#my_textarea_id’).closest(‘form’).find(‘iframe’).length > 0) …

Fourth, assuming the condition is not met and we’re still within the first minute, we set a timer using setTimeout to run the function again after a brief waiting period.  In the case above, I’m waiting 100 milliseconds.  After that waiting period, the browser will call the function “arguments.callee” with the start_time as the single parameter.  The reserved object “arguments” is provided by the browser, and it contains information about the current function (such as the function itself, the parameters, etc.).  The sub-object “arguments.callee” is a reference to the current function.  So even though our function is nameless, we can use the self-referring arguments.callee to recall the function after the sleep period.

Self-calling, anonymous functions are an odd duck idea, but they can be useful at times.

The Hunger Games movie is on its way out, and it seems to be all the rage.  I, for one, won’t be going to see it.  After hearing how incredible the book was, I read it clear through.  I was interested the entire way.

And I was also disgusted. Am I the only one who realizes that it’s a book about kids killing kids? I will heartily agree that it is well written as a literary work.  I know the author expects me to be disgusted (and I’ll somehow learn from it).

I draw the line with this book.  Kids don’t need to read it.  Teens and adults don’t either.  The kids in the books are victims, and even the two who “triumph” at the end still kill plenty to get there.  The book is about what could happen to society in the face of severely limited resources.  I get it.  But with all the real hurt in many nations of the world, do I really want to read about how bad we can hypotheticaly become on a societal level?

If you want to read a real story about what happens with severely limited resources, read about the Willy and Martin Mormon handcart companies.  They spent weeks in absolute desolation with freezing winds, deep snow, and almost no food.  And unlike the Donner party who faced similar trials, these two pioneer companies showed the best of the human race.  They cared for one another.  They sang songs and did what they could to keep spirits up.  Down the trail, one of the largest rescue operations of the time was started to rescue them.  Fathers gave their allotted morsels of food to their wives and kids.  Many of these brave people died, but they died honorably.  Those who remained did their best to bury and respect their bodies, despite their starving condition..  Now that’s a story about scarcity worth reading.  It’s a story showing the best of humanity, and a true one at that.

I realize I’m in the minority with this post.  I know many of you love the Hunger Games and are impatiently waiting for the movie.  Let me end by asking where you’ll draw the line?  What topic is too much for you or your kids?  Where will the desensitization stop?

A well written book?  Absolutely.  Worth my time?  Nope.

There may be a lot of rich-text web components out there, but there’s only a few worth looking at. CKEditor seems to be one of the most popular, and I initially chose it because I knew it would be actively developed, relatively bug-free, and supported. On the whole, my expectations were met. However, I resumed my search when I hit a JQuery dialog + CKEditor bug that only occurred on WebKit browsers. I spent 3 full days on the bug, and I finally gave up and looked for another editor.

I found a relatively new editor called elRTE, and it works great.  Here’s the advantages of elRTE over CKEditor from my viewpoint:

  • elRTE loads much faster.  CKEditor has a bit of a lag when the page loads.  I’ll bet elRTE is as fast as it is because it uses JQuery extensively (and jQuery is pretty optimized these days).
  • elRTE is written with JQuery so it integrates nicely.  CKEditor has its own framework that I had to learn to deal with.
  • elRTE’s dialogs (for things like links, images, etc.) are much prettier than CKEditor’s because they are written with JQuery UI.  They were much easier to integrate into my site since I’m also using JQuery UI.
  • elRTE is truly open source.  CKEditor is open source, but it’s got a funny commercial+open license.

elRTE seems to have its own drawbacks as well:

  • elRTE is newer than CKEditor, and it shows its immaturity at times.  It has a few bugs here and there, although I found them relatively easy to work around.
  • elRTE has almost no documentation.  Be prepared to dive into the forums and even the Javascript code behind it.
  • elRTE probably doesn’t work on as many old browsers as CKEditor does.  This is a guess of mine after looking at the code rather than a result of my testing.

It is useful to freeze table headers or left-side columns when working with spreadsheets. This behavior doesn’t translate to the web: HTML tables simply don’t freeze table columns. This JQuery plugin, when applied to any HTML table, adds the spreadsheet-like behavior of freezing.

To use the plugin, simply create a table, then run the following:

          $('#mytable').freezeTableColumns({
            width:       900,   // required
            height:      500,   // required
            numFrozen:   4,     // optional
            frozenWidth: 200,   // optional
            clearWidths: true,  // optional
          });//freezeTableColumns

That’s it!  The algorithm behind the script splits your table into four tables (which I call regions).  These regions split your table as follows:

Region 1 (frozen) Region 2 (frozen)
Region 3 (frozen) Region 4 (main data section, with scroll bars

As you scroll the table in Region 4, the script matches Regions 2 and 3 to match.  It’s a big hack, but the user sees it as one big spreadsheet-style table.

You can download the script here.

or see a DEMO here!

Enjoy.