Gifted Slacker

Found in the Darnedest Places

Posted in Software by Grant on June 30th, 2008

Nice concise definitions of closures, map, fold, unfold and filter sneaked their way into the middle of a Dr. Dobbs article (via Raganwald):

Closures, are anonymous functions created at run-time which can refer to variables that are visible where the function is declared.

Closures are especially useful when performing operations over elements in a collection. The most common collection operations (aggregate operations) in functional programming are map, filterfold, and unfold operations.

A map operation transforms a list into a new same-sized list by applying a transformation function (such as a closure) to each element in the original list. A common example of a map operation is when performing a vector scaling operation.

A filter operation creates a list from another list using only those items for which a predicate function returns true.

The fold operation combines values in a list using a binary function and an initial value. A summation function is a simple example of a fold operation.

The unfold operation creates a list from an initial value and by successively applying a generator function, until a terimination predicate returns true.

These are usually defined in much more obfuscated terms. It’s good to see them so clearly defined.

Anticipation

Posted in Life by Grant on June 25th, 2008

In a geeky programmer post Jeff Atwood made, he included this gem:

His [Daniel Gilbert's] research found that people are bad at predicting their own future happiness. They tend to radically overestimate the positive or negative impact of large events in their lives — losing your job, getting rich, getting divorced, having children. That’s generally good; it means we have defense mechanisms in place to adapt and survive in our changing circumstances as human beings.

What’s the lesson? Don’t avoid doing things because you fear the impact they might have on your life. Don’t do things that you’re only interested in the impact they’ll have on your life. Don’t suffer a meaningless toil, no matter how great the potential reward.

Live so that you can enjoy as many things as possible each day. That doesn’t mean banishing all of life’s annoyances. Perhaps some small joy can be found in them. Appreciate the rusty hinge or fix it; don’t let it bug you.

Enjoy the journey, choose the paths you pursue with that in mind, and don’t overlook the little things.

Geektacular

Posted in Filler by Grant on June 24th, 2008

If only I were this geeky.

Pain

Posted in Health, Life by Grant on June 23rd, 2008

I am in serious pain today.

I went to the gym this morning, as always. I was just about done with my workout when, feeling a bit of tightness in my lowerback, I began to bend over to stretch. That’s when I hurt myself. I got about 5-10º from vertical, at which point I was hit by a bolt of pain in my lower back, starting just above my tail and extending to about 1/3 of the way up my spine.

The pain nearly knocked me down. Fortunately, gyms are filled with heavy things to lean on.

Eventually, I made my way to the stairs and out of the building without attracting too much attention. It took me about half an hour to get back to Leazes Terrace. During my old-man slow walk home three people stopped me, asking if I was okay. I found it quite comforting that so many strangers showed concern about some random guy stumbling through the park. This also made me wonder just how badly I was moving.

It’s been a few hours since I hurt myself, and there’s been a bit of minor improvement but I still can’t sit, stand, walk or lie down comfortably.

Several times in my life I’ve gone through periods of intense pain, and this ranks with the worst I’ve experienced. Whenever I’m dealing with pain I’m thankful my dad is who he is.

My dad has dealt with, sometimes debilitating, chronic pain for as long as I can remember. Growing up I’ve picked up a lot of pain management techniques from him. The two most important ones for me at the moment are:

  1. Take care but don’t stop moving.
  2. The pain could always be worse.

It’s also a great help to know that I’ve got an amazing girlfriend that I can count on.

Today is all about popping ibuprofen and trying to get some work done.

Delphic Oracle

Posted in Filler, World by Grant on June 22nd, 2008

This is fascinating. It provides a sort of C.V. for the Oracle at Delphi.

What I’m Going to Eat Tomorrow

Posted in Filler, Life by Grant on June 18th, 2008

(Not that anyone cares.)

7:00 - Cereal mixed with yogurt.

12:00 - Schwan frozen pizza.

5:30 - Tuna melt.

Note 1: Buy a new can opener.

Note 2: All times are approximate.

Retirement School

Posted in Filler, World by Grant on June 17th, 2008

The best sentence I’ve read today:

[...] many jobs that require a college education today will require little in the way of education tomorrow. Many people may then defer college until retirement, in order to increase the returns to leisure by widening their cultural horizons.

Prediction

Posted in Filler by Grant on June 16th, 2008

OS X is serving as a gentle introduction to *nix for previously *nix-fearing developers. In these users’ next few upgrade cycles they will start moving to operating systems like Linux, OpenSolaris, or the *BSDs.

Last Day of the Month

Posted in Internet/Web, Software by Grant on June 15th, 2008

When a blog has never been visited my dissertation software retrieves any posts from the past 24 hours. This isn’t hard:

from datetime import datetime
lastvisit = datetime.utcnow().replace(day=(datetime.utcnow().day-1))

But when this happens and it’s the first day of the month you get:
ValueError: day is out of range for month
Since my project is only going to run for this summer, I did changed it so that it will work this year but not next year (sorry, WordPress strips out all of the tabs…):
from datetime import datetime

n = datetime.utcnow()
if n.day != 1:
    lastvisit = datetime.utcnow().replace(day=(datetime.utcnow().day-1))
elif n.month - 1 in (1, 3, 5, 7, 8, 10, 12):
    lastvisit = datetime.utcnow().replace(month=(n.month-1), day=31)
elif n.month - 1 in (4, 6, 9, 11):
    lastvisit = datetime.utcnow().replace(month=(n.month-1), day=30)
elif n.month - 1 == 2:
    try:
        lastvisit = datetime.utcnow().replace(month=(n.month-1), day=29)
    except ValueError:
        lastvisit = datetime.utcnow().replace(month=(n.month-1), day=2 8)


Today I ran across this article on ASPN. And now here’s what I would write (omitting some of the boilerplate from above):

if n.day == 1:
    days_in_month = [calendar.monthrange(year,month)[1] for year in [n.year] for month in range(1,13)]
    datetime.utcnow().replace(day=days_in_month[n.month-2], month=n.month-1)
elif:
    datetime.utcnow().replace(day=n.day-1)


If I would have spent 5 minutes looking for The Right WayTM to do this, I would have saved a little time and had cleaner code. Now I don’t want to change what I’ve got working well enough.

Dear Lazyweb: How do I post pretty code snippets?

Random Data

Posted in Filler, Internet/Web, Software by Grant on June 15th, 2008

In the last 3 and a bit days my software has gathered over 125,288 posts from 96,000 blogs. 37,594 blogs have at least one post from that period.

Below’s a crappy table ripped right from the mysql console. The first column is the total number of posts and the second column is the number of sites that have the corresponding number of posts.

+—————–+—————–+
| number of posts | number of sites |
+—————–+—————–+
|             100 |               1 |
|              89 |               1 |
|              87 |               1 |
|              83 |               1 |
|              79 |               2 |
|              75 |              12 |
|              74 |               1 |
|              72 |               1 |
|              70 |               1 |
|              69 |               1 |
|              68 |               3 |
|              66 |               1 |
|              65 |               3 |
|              63 |               3 |
|              62 |               2 |
|              61 |               1 |
|              60 |               3 |
|              59 |               2 |
|              58 |               4 |
|              57 |               1 |
|              56 |               2 |
|              55 |               2 |
|              54 |               2 |
|              53 |               4 |
|              52 |               8 |
|              51 |               2 |
|              50 |               2 |
|              49 |               3 |
|              48 |               6 |
|              47 |               4 |
|              46 |               2 |
|              45 |               3 |
|              44 |               4 |
|              43 |               8 |
|              42 |               9 |
|              41 |               8 |
|              40 |              10 |
|              39 |               5 |
|              38 |               7 |
|              37 |              10 |
|              36 |              10 |
|              35 |              12 |
|              34 |               7 |
|              33 |               7 |
|              32 |              12 |
|              31 |               9 |
|              30 |              16 |
|              29 |              19 |
|              28 |              16 |
|              27 |              32 |
|              26 |              27 |
|              25 |              43 |
|              24 |              28 |
|              23 |              45 |
|              22 |              45 |
|              21 |              49 |
|              20 |              66 |
|              19 |              69 |
|              18 |              78 |
|              17 |              71 |
|              16 |             116 |
|              15 |             106 |
|              14 |             140 |
|              13 |             166 |
|              12 |             184 |
|              11 |             259 |
|              10 |             312 |
|               9 |             410 |
|               8 |             548 |
|               7 |             791 |
|               6 |            1093 |
|               5 |            1699 |
|               4 |            2959 |
|               3 |            5139 |
|               2 |            8170 |
|               1 |           14695 |
+—————–+—————–+