January 25, 2007

Meditating Is Good Lately

Filed under: General — mmrobins @ 4:57 pm

I really do want to do this every day, and I’ve been doing a good job recently. I’ve been motivated by listening to The Science of Enlightenment by Shinzen Young. I got it off Audible and it’s pretty good. It has some nice guided meditations as well as quite a bit of explanation.

Anyway, I seem to be close to integrating this as a habit, but it’s not there yet.

January 23, 2007

Ruby sort_by for Enumerables

Filed under: Technology — mmrobins @ 10:28 pm

I have been trying to figure this one out forever. I have an array of objects, usually hashes, and want to sort them. Thing is I want to sort them by their values, not their keys. Regular old sort for arrays is powerless here since it doesn’t know how to compare complex objects, let alone reach down inside them and sort by that value. I found sort_by finally, but still couldn’t get it to do what I wanted often because sometimes the objects I was sorting could have a nil value, and the sort function doesn’t know how to sort nil. Here’s an example: I have an array of Employees, and each employee has an employee_number. Actually not every employee has a number, since some are temporary. So if I try to sort by employee_number bad things happen.

Here’s how I finally made it work.

array.sort_by { |employee| employee.number.nil? : 0 : employee.number }

It basically says if the employee number is nil or null or whatever you want to call it, pretend we’re sorting by the value 0, otherwise sort by the employee number. Hooray!

January 4, 2007

Downsizing

Filed under: General — mmrobins @ 11:52 pm

Moving is a real pain, but it has some good points. The best I can think of right now is that it forces me to get rid of lots of things that I don’t need. Pulling things out of storage closets that I haven’t used in years makes me realize that getting rid of them is a lot better than moving them. Thank goodness for craigslist. I don’t know how people got rid of things they didn’t need before without throwing them away. Now you can sell things you don’t need for money, and people will show up to take the stuff!

New Years And Everyone’s Engaged!

January 4th, 2007
This post will become visible after your registration is approved.