Wednesday, December 31, 2014

Takeaways: Tuesdays with Morrie

I recently read Tuesdays with Morrie by Mitch Albom. Apparently, it's a bit of a staple in the American education system, but I hadn't read it until now. My initial thoughts are thus: in one sense it was a bit of a rehash - most of the ideas Albom brought up are already familiar. However, he brought them up in a stunningly, emotionally moving way that was an incredible reminder of these ideas.

One of my coworkers described Tuesdays with Morrie as bringing up interesting ideas, but not really describing what to do with them. I disagree - the book might not explicitly describe what should be done with its ideas, but it does show you. It shows you via Morrie's thoughts, speech and his relationships.

Here's a quote from the book that describes the purpose it serves:

"We don’t get into the habit of standing back and looking at our lives and saying, Is this all? Is this all I want? Is something missing?" He paused. "You need someone to probe you in that direction. It won’t just happen automatically."
Tuesdays with Morrie attempts to probe us in this direction. It is the final thoughts of an old Professor who's dying a slow death of ALS (of ice bucket challenge fame), as written by one of his former students (Albom) who visits him once a week in the days leading to Morrie's death.  Morrie's visible and repugnant decay is well-captured by the book, and it also captures his cheery and positive attitude through this dreadful disease along with the final thoughts of a dying man, rendered with the clarity that only death can bring.

One of the most important questions Tuesdays with Morrie wrestles with is the meaning of life.

The Meaning of Life

Here's what Morrie says on the subject:
"So many people walk around with a meaningless life. They seem half-asleep, even when they’re busy doing things they think are important. This is because they’re chasing the wrong things. The way you get meaning into your life is to devote yourself to loving others, devote yourself to your community around you, and devote yourself to creating something that gives you purpose and meaning."

So what is important? Morrie describes three things:
  1. Loving relationships
  2. Good community
  3. Meaningful work 

"Devote yourself to loving others, devote yourself to your community around you, and devote yourself to creating something that gives you purpose and meaning. “You notice,” he added, grinning, “there’s nothing in there about a salary.”"

Most psychology research guides us towards these same three things. Things like money are important, but only as far as they take you above the poverty line. Once you have a roof over your head and food on your table, the correlation between money and happiness stops. Focus on these three things. Let's talk about them:

Loving relationships

The most important of these is your relationship with family. Blood flows thicker than water, and your family will be there for you when no one else will. Here is a key quote from Tuesdays with Morrie that stood out to me:

"The fact is, there is no foundation, no secure ground, upon which people may stand today if it isn’t the family."
Oftentimes, we tend to replace family with a fascination with career, or we work on increasing our wealth. Wealth and a meaningful career are good in their own right, but there is something that only your family can provide. Even friends are a poor substitute for family.

"It’s what I missed so much when my mother died—what I call your ‘spiritual security’—knowing that your family will be there watching out for you. Nothing else will give you that. Not money. Not fame."
Morrie was dying of ALS - a slow, dreadful decay - and Albom, looking at him, wonders this:

"Yet when I looked at Morrie, I wondered if I were in his shoes, about to die, and I had no family, no children, would the emptiness be unbearable?"
Do you want to die surrounded by friends and family? Or do you want to die alone?

Death is always around the corner, and you never know when it might trip you up. I have a close great aunt who's very old, and she had an unmarried daughter who until recently, lived with her and took care of her. My great aunt slowly transferred all her assets to her daughter's name, expecting to pass on soon. This past summer, we learned that her daughter had breast cancer. It was a particularly vicious strain of the cancer that tore through her body, and three weeks after the diagnosis, her daughter had passed away.

If you've been putting off getting in touch with your family, stop. Get in touch with them now. Pick up the phone. Send them a text, put in a call, write them a letter or an email, whatever you're comfortable with. "Don’t assume that it’s too late to get involved," says Morrie, and he's right.

It might be awkward if you haven't talked to them for a while, or if you got estranged for the wrong reasons, but you've likely done more awkward things for less important reasons. Don't let this slip. If you think they've wronged you, or that you have a right to keep distant, consider this:

“Mitch,” he said, returning to the subject of forgiveness. “There is no point in keeping vengeance or stubbornness. These things”—he sighed—“these things I so regret in my life. Pride. Vanity. Why do we do the things we do?”
There is wisdom in a dying man's words. Why do we do the things we do?

One of the most important relationships you can have is that with your spouse. It can be the most powerful and fulfilling relationship you'll ever experience, and it can also be the most devastating.

The most important thing to do when getting married is to choose right. You and your spouse need to share similar values. You don't need to be the same person - it's okay if one of you loves Chinese food and the other hates it - but you need to have the same attitudes towards important things in life - like, honesty in the relationship, how much you'll emotionally depend on each other, the values (or faith) with which you'll raise your kids, attitudes towards each other's family. These things don't usually change with time.

This is the great filter through which you must evaluate potential spouses, but once you're done, the work isn't over, it's only just begun. You'll never have to work harder to keep a relationship than that with your spouse. Luckily (or hopefully) you should both be equally invested in the relationship, and willing to put in the legwork.

Morrie gives us three things to watch out for:

"If you don’t respect the other person, you’re gonna have a lot of trouble. If you don’t know how to compromise, you’re gonna have a lot of trouble. If you can’t talk openly about what goes on between you, you’re gonna have a lot of trouble. And if you don’t have a common set of values in life, you’re gonna have a lot of trouble."
The values we've already talked about, and those are the most important because they are difficult to change. The rest of those can be learned. Watch out for these caveats, and try and build openness and respect. Relationships are about give and take so learn to compromise - for example, if you insist on going to a Chinese place once in a while, it's okay, but try and choose a place where there's something on the menu your spouse will be willing to eat.

Good Community

There's a strong positive correlation between more religious/spiritual people and life expectancy, but any Psych 101 textbook will tell you, this is more because of the communities these people are part of on account of their faith, rather than because of the faith itself. We need to find such communities to be part of. The best way to become part of a community is to give to them. Morrie says:

"Giving to other people is what makes me feel alive. Not my car or my house. Not what I look like in the mirror."
Relationships in which you give are important to you because they make you feel needed. Remember that this is an even exchange - you might be giving your time, or a friendly ear, or even money, but you get in return a valuable sense of fulfillment. A conversation between Morrie and Blom goes as follows:

“The truth is, you don’t get satisfaction from those things. You know what really gives you satisfaction?”
What?
“Offering others what you have to give.”
You sound like a Boy Scout.
“I don’t mean money, Mitch. I mean your time. Your concern. Your storytelling.”

Sometimes all other people want is to be noticed. Morrie tells a story from his early adulthood when we was researching a mental hospital. A patient there would everyday just go to a hallway and lie on the floor, unmoving. The staff eventually learned to ignore her and would step around or even over her as they went about their business. The young Morrie was moved, and he went up to her and started talking to her. Eventually, he convinced her to get off the floor - it turned out that the only reason she was doing it was so that she was noticed. In the end, that's the driving force for most of us - we just want to be noticed.

Go out of your way to notice people. There's an art to this, encapsulated perhaps in this sentence: 

"When Morrie was with you, he was really with you. He looked you straight in the eye, and he listened as if you were the only person in the world."

Meaningful Work

Work is good because it gives us a sense of purpose. That sense of purpose helps us be fulfilled. However, in order for this to be true, that work has to be meaningful. Whether you're a software engineer who has moved up to management and hates it there, or an insurance agent who rips people off and hates themselves for it, or a corporate drone who is tired of playing office politics, if you don't have meaning in your work, you won't be happy.

Our culture drives us to go up the corporate ladder, but Morrie says: 

"Forget what the culture says. I have ignored the culture much of my life. I am not going to be ashamed. What’s the big deal?"
Find work that makes you happy, and do it. We already established that money is only good for taking you above the poverty line. Once you're above it, money has no effect (perceived or otherwise) on happiness, so as long as the bills are getting paid, what does it matter what you do? Don't let inertia cramp you for the rest of your life.

"And you have to be strong enough to say if the culture doesn’t work, don’t buy it."

Final thoughts

I want to close out with the following statement from Morrie that really stood out to me:

"Do what the Buddhists do. Every day, have a little bird on your shoulder that asks, ‘Is today the day? Am I ready? Am I doing all I need to do? Am I being the person I want to be?’"
Have you done what you need to do? This doesn't just mean backpacking across Europe, it also means having a plan in place to take care of your spouse and kids or any other dependants (including your parents) if something happens to you. Do you have life insurance? Any other documents your survivors might need to know about? Did you write a will, so that your estate isn't locked up in court if something happens to you? Protect your loved ones by thinking beyond yourself. Your death might not be slow and decaying like Morrie's - you could die in a car accident tomorrow.

Don't shy away from the thought of your own transience. If you embrace it, it might just make life more beautiful:

"You see that? You can go out there, outside, anytime. You can run up and down the block and go crazy. I can’t do that. I can’t go out. I can’t run. I can’t be out there without fear of getting sick. But you know what? I appreciate that window more than you do."
Live life. Don't be afraid. Learn to love and be loved back. Life is defined by the people around you and the relationships you develop - not by money and cars and big houses. You can't take money and cars and big houses with you to grave with you, but when you die, "Death ends a life, not a relationship." You might be gone, but your relationships will survive you.

If you haven't read this book already, I highly recommend it: Tuesdays with Morrie: An Old Man, a Young Man, and Life's Greatest Lesson. If you're more into Audiobooks, here is a link to the Tuesdays with Morrie Audiobook.

And here's a non-affiliate link.


Wednesday, December 17, 2014

Takeaways: The Healthy Programmer

I recently picked up The Healthy Programmer by Joe Kutner. The 8+ hours of programming are beginning to take their toll on my health with various headaches/eyeaches, so I wanted to see if Joe had any insights into what I can do to stay healthy. Here are my key take-aways from Joe's book:

Walk Walk and Walk Some More

One of the big points that Joe stresses is the importance of walking. He tears through the current "standing desk" fad sweeping through the nation. Numerous studies can be cited which state that standing for 8 hours a day can be as bad for you as sitting 8 hours a day, albeit in different ways. The best thing we can do for our bodies is to take frequent breaks in which we walk. Walking gets the heart pumping, which is the source of the health benefits associated with walking. 

Walking is also associated with better cognitive function. We learn and remember things better while walking, which is extremely important for programmers. 

There are three areas of improvement I drew from the Healthy Programmer:
  1. If you get stuck on a difficult problem, take a walk. Walking will jog the brain and help it get out of its current rut of thinking.
  2. Take a walk either before or after learning something new. This will help you remember it better.
  3. Take a quick walk every 25 minutes. 
For that last bullet point, take advantage of the Pomodoro Technique. There is a Pomodoro Timer is available for Mac and Windows. I installed it on my work computer, and it looks like this:

You can set that little popup to always hover on your screen, and it alerts you when time runs out. When you get the alert, simply get up, walk around for a few minutes, look outside the window (to rest your eyes), and then reset the timer and get back to work. Using this technique will have remarkable effects on your health, and it will significantly lower your mental fatigue and increase your productivity.

Take care of your eyes

Imagine not having your eyes. It's a terrifying thought. Taking care of your eyes is important, and as programmers, we're already at a disadvantage because we stare at screens for 8+ hours a day. 

The Pomodoro Technique described above is a good way of giving your eyes the rest they need. Everyone knows they're supposed to rest their eyes and look in the distance every 15 or so minutes, but when you're in the middle of tracking down that obscure bug, an hour or several hours can go by before you remember to look up. The Pomodoro Timer is a good way of forcing yourself to look up and away more often. 

If you think there's a productivity cost, think about how productive you would be if you lost your eyesight. Your body is important. Take care of it. 

In addition to the technique above, I've also put a post-it note on my monitor with the message: "BLINK!" People tend to blink less while staring at a computer screen, so every time I see this note, I stop what I'm doing and blink several times for a few seconds. 

I've also lowered the contrast and brightness of my monitor so that it matches the brightness of my office. I've also put the display settings to "warm" - per Joe, red hues are better for the eyes than blues. 

Visualize breaking bad habits

Imagine yourself breaking through your bad habits. For example, if you know you go to the vending machine for chocolate at noon everyday, and you've decided you're going to stop doing that, then visualize several times over the course of the morning how you're going to not go to the vending machine at noon. If it helps, visualize yourself doing something else at noon - maybe going to the water cooler, or going to a coworker's cubicle, and then do that other thing. Once you've done it a few times, your chocolate urge will be significantly lower come 12PM.

Life should be a series of small improvements

I loved this point. "Set a new personal record everyday," says Joe. In many many small incremental improvements, we can make dramatic improvements in our lifestyles over the course of weeks, months, and years. Think about your daily routine. Is there something small you could do that would improve it? Seize that thing and fix it. Spend a few days making sure it's stamped out. Then pick on the next thing you want to improve and repeat.


I do recommend picking up the book I got these tips from - The Healthy Programmer (disclaimer: affiliate URL). It's not the best book in the world (it doesn't claim to be), but it does have some valuable nuggets of information that make it worth the time and energy spent reading it.

Friday, December 5, 2014

A Story about YAGNI - You-Aren't-Going-To-Need-It

Recently I was working for a project on a client where they wanted the project to be Live for a certain portion of time during the day - so for example between 9AM and 2PM, or 12PM and 3PM, or so on and so forth.

While implementing this feature, a thought struck me - what if the client wanted to have a period that ran past midnight - so for example between 11PM and 2AM? At this point, the intelligent thing to do would have been to pick up the phone and call the client to ask. Instead, I thought to myself - well, even if they haven't asked for it now, they might need it later. Besides, I could build a decent set of unit tests and use them to catch all the edge cases, right?

Wrong.

What ended up happening was that I spent many hours writing the unit tests to capture the many edge cases that came with crossing the midnight deadline during a time period. I spent even more time writing the code to deal with them. The project went over-budget thanks to that extra time I spent, and the client never ended up using the added feature. After a few months in production, the client scrapped the project (albeit for unrelated reasons). 

Lessons learned: unless you're very strongly confident that you need to build something for the future, don't do it. Don't fall prey to what-if's. Remember: YAGNI - you aren't going to need it. And if you do need it, you can build it later, when it's accounted for in the budget. Finally, don't be afraid to pick up the phone and ask a question. It makes everyone's life easier.

Monday, November 17, 2014

Postback not happening on ASP:LinkButton with Adblock Plus

I recently had a problem while working on an ASP.NET website where I had a page doing a postback on an ASP LinkButton, except in FireFox with AdBlock enabled, the postback just wasn't happening. Clicking on the button resulted in nothing. When I examined the markup on the page it looked like this:

<a id="ctl00_ctl00_MainContent_Content_btnReserveTickets" class="btn" href="javascript:__doPostBack('/* postback param*/','')">Buy</a>

It looked like the Javascript initiating the postback should have been firing. I put a breakpoint i that __doPostBack function, but it didn't get hit. There were no console errors either. I racked my mind and googled around with no luck. The only potential solution I could find - to add a CausesValidation="false" attribute to the LinkButton - didn't work.

Finally I posed my question on StackOverflow and walther over there gave me a hint that led to the solution. He suggested that I look for AdBlock's blacklisted keywords that may have been attached to the name or attribute or something of the LinkButton, such as "ad" or "facebook" or so on and so forth.

In the end, I discovered that there was a function adding a click handler to the LinkButton that was sending a Google Analytics event, as follows:

$(anchorEl).click(function () { 
                        ga('send', 'event', 'outbound', 'click', anchorEl.href, {
                            'hitCallback':
                              function () {
                                  document.location = anchorEl.href;
                              }
                        });
                        return false;
                    }); 

It turns out that once this click event gets attached, and because it's Google Analytics, all javascript on the LinkButton gets stripped off!

In the end this blogpost guided me to a solution: I wrapped the click event binding above in the following if statement:

if (ga.hasOwnProperty('loaded') && ga.loaded === true) {
    // bind event
}
This means that if AdBlock is ever blocking Google Analytics from loading, the anchorEl's click event is never bound to that Google Analytics event (binding it successfully would be useless anyway, since Google Analytics isn't loaded), and AdBlock doesn't strip the Javascript from my LinkButton.

Sunday, November 16, 2014

Learning Angular | Using a factory to make an API call

I was recently building an Angular app in which I had a search page and a search results page. Obviously, the API call would be made after a user hit the search button on the search page, but the question was whether I should make the call from the search page or the search results page.

Search page on the left, search results on the right
My initial solution was extremely complex - I tried recording the selected parameters, and then I created a super-complicated route that allowed me to pass them into the the search results page. However, that was way too complicated, and I quickly realized that there had to be a better way.

After asking around a bit on some Angular help channels, I figured out that Angular services and factories are singletons! This means that I can make the call in the search controller, store the results in my API factory, and then bootstrap my search results controller user the cached results. This ended up being a much faster, simpler, neater implementation!

Here's how my final implementation worked:

Search function - searchController.js

$scope.search = function() {
        var searchParameters = {
            // create search object
        }
        
        API.search(searchParameters).success(function (data, status, headers, config) {
            $location.url('/results');
        });
    };


Controller - searchResultsController.js

// gets the cached results from the API
var data = API.getSearchResults();

    

API factory - API.js

angular.module("donorsApp").factory("API", ["$http", function ($http) {
    
    var constructSearchUrl = function (searchParameters) {
        //returns URL;
    }
    
    // cached results
    var results = null;
    
    return {

        // gets called from the searchController             
        search : function (searchParameters) {
            var request = $http.jsonp(constructSearchUrl(searchParameters));
            
            request.success(function (data, status, headers, config) {
                // caches the returned results
                results = data;
            });
            
            return request;
        },
        
        // gets called from the searchResultsController
        getSearchResults: function() {
            return results;
        }
        
    }
    

}]);

Lesson learned: don't make API calls from the controller, make them from a factory or a service, and then cache the results as needed. 

Monday, October 6, 2014

Be Careful What You Think

In Western culture, it's commonly considered a sign of intellectual freedom and ability to think about and consider several points of view before advocating a certain one. In our world, it makes sense to debate the pros and cons of various opinions - the good and the bad - before coming to a conclusion.

But consider this - the way the human brain works, in order to evaluate whether something is true or not, you have to, for a moment, believe that is true. This is because our minds contain a model of how the world works. When considering a statement, we evaluate it by adding it to our model and then checking whether the model still seems valid or not. If it seems valid, we accept the statement as true. If it doesn't, we reject it as false.

This means that for an instant, in your worldview, that statement - however ridiculous - is true. And this affects us. The first time you think that thought, it affects you a little. The more you dwell on it, the more it affects you. The better the thought originally fit in your mental model, the stronger its effect on you.

For example - if you keep thinking of how much better your coworker Joe is than you at your job, then even if you don't actively obstruct Joe's work, there will likely come a day when you have the opportunity to hinder him without anyone finding out, and you will take it. Once you take it, hindering Joe in the future will become okay. What was once an immoral thing - something you might never have considered - becomes a real possibility. Additionally, if you are naturally a jealous person, or are in an environment where jealousy is the norm, your mental model will be more accepting of such thoughts, and your progress down this path will be faster.

Therefore, don't just be a vacuum cleaner, absorbing every piece of information that comes your way. Carefully evaluate what pieces of information will guide you towards being the person you want to be. Be a person who thinks good thoughts. Don't expose yourself to wicked ideas unless you have a good, solid framework that will help you discern the right from the wrong. The human brain is like a sponge - wipe it in muck and it becomes dirty. Dip it in clean water and it absorbs the water and even cleans itself. Be careful what you choose to put your brain in - be careful what you think.

Wednesday, October 1, 2014

Creating simple logging "apps" with Google Forms


If you want to improve something, you've got to measure it first. Putting numbers on things helps us tame the wild waters of instinct and gut feeling. It helps us break things down and make them easy to understand. Numbers help us improve.

I've often felt the urge to create a means of recording something or the other in my life, and when I've had this urge, I've often fantasized about whipping out my Eclipse instance and putting together wonderful Android app that lets me record that thing and has a few dozen bells and whistles to boot. Of course, this never gets done, since I've never needed to record anything badly enough to create a dedicated app for it.

Recently though, I discovered a lovely shortcut to doing this, using Google Forms. I'm going to describe how to do that in this blog post. I mentioned in another article several ideas to help productivity. One of these was a recording what you eat and correlating productivity with it, so I chose that as my initial logging "app"/webpage.

Here's what the final result looks like:






This allows me to enter what I ate for dinner, breakfast, and lunch, and then in a 1-5 scale, rate how productive I felt at work and at home. The real trick was to keep the form simple. Once I conceived the idea of making this form, I wanted to add all sorts of bells and whistles - for example, if I wanted to track productivity, shouldn't I look at other major indicators? Maybe I should have a field for sleep, and another for any snacks that I ate. What if there were extenuating circumstances, like a friend visiting from out of state?

In the end I decided to include a catch-all "notes" field at the end of the form (not shown in the screenshot). I knew that if I made it too complicated, it would just be an excuse for me to procrastinate from filling it out at the end of the day when I'm tired anyway.

How to create the form

Step 1: Go to Google Forms and create a forms with the fields you want. In my example, I used type "text" for the breakfast/lunch/dinner fields, type "scale" for the rating fields, and type "paragraph text" for the notes field. This is what my "dinner" field looks like: 


Step 2: Make sure multiple responses per person are allowed in the form settings on the top of the page. 


Step 3: Go to File > Send Form. This will allow you to get the link to the form.

 

How to add the form to your phone

Step 4:  Copy the link and send it to your phone. You could just email it to yourself if you don't have a better way of doing it. 

Step 5: Open the link on your phone. On my Android phone, Chrome has the option to "Add to Homescreen":


If you tap that option, the OS will add an icon representing this form to your home screen. You can tap the icon, and it will open up your browser of choice with the form loaded! 

So there you have it - using this technique, you can make what is essentially a quick "App" to record any data you might want to on a daily or weekly basis in a convenient way using Google Forms. Whenever you want to check out your responses, and data logged so far, just log into your Google Drive, open up the form, and hit the View Responses button:

 

It might not be as neatly executed as a real app, but it will get the job done, and you can do it in five minutes, instead of spending hours coding an app!

Drop me a comment, letting me know what you use this technique for. :)