A Good Night’s Rest

I am not the only techie who struggles to get enough sleep. I’ve recently instituted a lifehack that is giving me some relief, and I want to share it. To my sleep-deprived sisters and brothers, this one’s for you.

Although I have no trouble falling asleep (quite the contrary), I am dogged by insomnia because I delay and delay going to bed. And—as you well know—that makes every other aspect of life more difficult.

So, c’mon, we owe this to ourselves. To fully be our true awesome selves, we need a full night of sleep.

Sleep hygiene

The key to transforming sleep from a battle to a balm is regular routine. Sleep hygiene, like dental hygiene, is a collection of healthy habits, a pattern that signals “sleepy time” to your brain. Same bed time, same nightly routine, a restful wind-down to the day.

“I stay up until I’m sleepy,” you protest. But here’s the thing: shining light into your eyes tells your suprachiasmatic nucleus, “It’s daytime! Stay awake. Stay awaaaaaake!” If you’re punting on the internet, you’re not going to get sleepy. Not at the right time, anyway.

I’ve read up a lot on good sleep habits and, previously, practiced them rigorously, to get debilitating daytime sleepiness under control. In college I underwent an all-night-and-all-day sleep study (ugh, it was awful); results were inconclusive but various pharmacological solutions were bandied about. And I thought: I don’t need to be medicated; I can beat this. For more than a decade, I have, but habits have been sloppy lately, with bedtime slipping later and later. Time to change that.

As important as flossing and folic acid, make sleep hygiene a habit. Close the laptop, perform your nightly ablutions, and get into bed.

Take willpower out of the equation

My sage friend Aneel gave me the most useful advice on sleep hygiene. Willpower, he says, is a resource you deplete. At the end of the day, you’re tapped out. Therefore, any decision that relies on willpower—the decision to go to bed, for example—is likely to be made… poorly.

The solution is to take the decision out of your hands. To wit, automate it. Schedule the computer to shut down.

Script those zees

(Outside the US, do people “catch some zeds”?) I need something taken care of without having to think about it? PowerShell!

I created a PowerShell script that warns me to wrap up my work, then sets the computer to sleep. I call that script from a Windows scheduled task.

$WarningDuration = 5
$MessagePlural = ""
if ($WarningDuration -gt 1) { $MessagePlural = "s" }

[System.Media.SystemSounds]::Asterisk.play()
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[windows.forms.messagebox]::show(("Save your work. Sleep in {0} minute{1}." -f $WarningDuration, $MessagePlural))
Start-Sleep -Second ($WarningDuration * 60)

[System.Media.SystemSounds]::Beep.play()
Start-Sleep -Second 2
[System.Windows.Forms.Application]::SetSuspendState("Suspend", $false, $true)

Caveat emptor. To write this script, I picked up pieces of PowerShell and stuck them together with mud and spit. Please make a better version, put it in a gist, and link to it in the comments. Sleepy nerds will thank you.

Start the Task Scheduler, select Create Task, create a daily trigger a little before bedtime, and set the action to run your PowerShell script.

Create Task in Windows Task Scheduler

Create new Action, set action type to Run a Program, enter PowerShell as the command

It’s currently set later than I’d ultimately like, but if I made too drastic a change all at once, I’d just flout myself and restart the computer. So this is a compromise, a deal I’m making with myself for now. Incremental improvements.

I won’t tell you what time it was when I wrote that script. Heh.

Related Articles:

About Sharon Cichelli

I am a Headspring Senior Consultant, developing custom enterprise software for our clients and leading training classes on the latest Microsoft technologies. I blog about .NET development, best practices in agile software development, and my nerdy hobbies.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Pingback: The Morning Brew - Chris Alcock » The Morning Brew #1242

  • Peter

    Great tip! I’ve set this up: no excuses now.

    • scichelli

      @Peter, right on. Report back, let us know if it’s helping. I feel like we (the dev community) can help each other on this. Good luck!

  • http://Typecastexception.com John Atten

    Yup. You precisely describe the problem I have. I am learning development on my own, after work and on weekend. I constantly feel like I am “catching up” and trying to squeeze a few more minutes learning in. Therefore, I get to bed far too late, and whiloe I fall asleep right away, I sleep poorly through the night, and wake too early trying to squeeze in an extra hour or two of dev time before my workday begins. 

    • scichelli

      @JohnAtten:disqus , oh, I hear ya. It’s tempting to resent the fact that we need sleep, “all those wasted hours!” But console yourself, the time is not wasted, because sleep is when learning happens. I recall this awesome Radiolab episode on sleep (http://www.radiolab.org/2007/may/24/), and I think that’s where I learned: Sleep kind of paints a patina over the things you did that day, muting everything a little bit. And the things you practice and repeat, they’re taller and more emphasized, so they’re still prominent after turning down the intensity. Meanwhile, the other clutter is muted and wiped away. Without sleep, you’d never sort any signal out of all the noise of the day.
      Speaking of learning programming, if you’re in Austin, you’re welcome to join our programming language study group, http://polyglotprogrammers.org/

      I’m self-taught, and I never feel “caught up.” Don’t forget to take stock from time to time of what you _do_ know and how much you’ve already achieved.

      • http://Typecastexception.com John Atten

        re: Learning continues during sleep – Yes, in fact I have heard the metaphor that dreaming is akin to a giant, non-indexed database forming reinforcing relations. Great post!

        • scichelli

          Ha! Nerd metaphor, that’s awesome! :D

  • http://twitter.com/liquid_electron Josh Elster

    Another important utility that I think not just devs but anyone who faces a monitor for long periods of time should use: f.lux.  (http://stereopsis.com/flux/). As Sharon mentioned, light entering the eye participates in regulating a person’s circadian rhythms – the physiological body clock. Cooler color temperatures (think blue-er) fool the body into releasing day-time neurochems, making it harder to get a good night’s sleep. Simply modifying a display’s color temperature from cool to warm (more orange-y) can mitigate that effect, which is exactly what f.lux does. It changes the color temperature of your screen based on the time of day. I’ve been using it for a few months now and I can say that it has helped, even if it is only to remind me that yes, it is getting late!

    • scichelli

      Alrighty, @twitter-227175547:disqus , I’m with ya. I just installed f.lux. I’ve been hearing about it for years; thanks for the nudge. :)

      • scichelli

        Woah… amber-y! This takes some getting used to.

        • Josh Elster

          Ha ha yeah when the transition happens it almost seems like there’s something wrong with your eyes or the display!

  • Pingback: Noticing the Signs – Friendship Status | A Friend to Yourself