Category Archives: Science

Science

Melatonin for Jet Lag: The short and simple answer.

I am going to be doing a few red-eye flights in the near future, to time zones far from my own. I decided to review the scientific recommendations around melatonin for jet lag. Unfortunately, most of the articles that have the needed information are behind paywalls, so I bit the bullet and bought a review article. Now I can share the important information with you, dear readers. Here it is:

  • Take 2-5 mg of fast-dissolving or liquid melatonin about 30 minutes before sleep.
  • Do this when you’re ready to sleep on the red-eye flight
  • Do this every day at your destination for the first 3-4 days
  • Maybe avoid caffeine and alcohol
  • Do NOT take melatonin earlier in the day, or at any other day or time beside what is listed above. This includes not taking any in the days before your flight.
  • Try to get dark when you should be sleeping and light when you should be awake (by the time zone you’re adjusting to).

That’s it. Lots of long-winded discussion exists on the internet. Many abstracts tease at this information but don’t give it. But now you have it. Happy travels.

Retiring Virtually Shocking

I started Virtually Shocking when I had dreams of becoming the web’s foremost cardiac electrophysiology blogger, especially as it relates to simulation. As it turns out, I didn’t really have the interest, drive, or time required to achieve such lofty status. I would much rather blog about whatever interests me. Some of that relates to cardiac simulation, some does not.

I’ve therefore moved the blog to http://blog.brocktice.com. I’ve set up redirects and all of that good stuff, so old links should all still work.

I’ve taken down my fancy Virtually Shocking theme and replaced it with an oldish-looking default wordpress theme. This blog is about content, not presentation. At some point I’ll spiff it up a little.

I’m sad to see Virtually Shocking go, but if I’d been honest with myself, this should have become blog.brocktice.com a long time ago. I may still post Cardiac Electrophysiology stuff over at http://cardiosolv.com/blog/.

Which Internet Weather Site is Most Accurate?

I have been a long-time user of the Weather Underground, while my wife uses some Weather Channel app or something on her phone. We frequently have disagreements about what the high temperature for the day is/was supposed to be because we use these different services.

I really like the Weather Underground, but I must confess her numbers/rain probabilities seemed to jive better with what was happening, so I did a search to see if someone had analyzed the various weather sites for consistency and accuracy. Someone did, and how.

I’ll be honest. I mostly just skimmed through the site, because I was just interested in the conclusions (at first). An important caveat is that the analysis was done for only one location, by one guy, but I have to admire the effort and the statistical analysis.

In conclusion: I’m going to see if I can find an IntelliCast app for my phone.

Extracting certain lines from a file using Perl

As often happens to me when processing data, I needed to extract a specific set of lines from many files. If the files are small or few, or the list of lines is short, this can be done manually. If the list of lines or number of files are large, well, that’s what computers are for.

As Google will reveal, there are a number of ways to hack this up with bash, grep, sed, and other command-line tools, but none (that I know of) are really designed for this.

Here’s my script. It’s designed around some heart model stuff, and we use base-0 (first line is line 0, second line is line 1, etc), while many other tasks require base-1 (first line is line 1, second line is line 2, etc), and I’m sure there are other numbering schemes out there. Therefore, I included an optional base parameter. Without that it assumes base 1.

Note: I have no idea if this works on non-UNIX-like systems (i.e. Windows).

Use it like:

extract_lines.pl <file with list of lines> <file from which to extract lines> [optional base number]

And now, the code:

#!/usr/bin/env perl

use strict;

unless(@ARGV == 2 || @ARGV == 3){
    die "Usage: extract_lines.pl <line number file> <source file> [base]\n";
}

open(NUMBERS, "<$ARGV[0]") || die "Failed to open line number file $ARGV[0] for read: $!\n";
chomp(my @numbers = <NUMBERS>);
close(NUMBERS);

open(SOURCE, "<$ARGV[1]") || die "Failed to open source file $ARGV[1] for read: $!\n";
chomp(my @source = <SOURCE>);
close(SOURCE);

my $base = 1;

if(@ARGV == 3){
    $base = $ARGV[2];
}

# sort inputs just in case
my @sorted = sort { $a <=> $b } @numbers;

# save mem
undef @numbers;

my $nextline;

$nextline = shift(@sorted);
my $currline = $base;

foreach my $line (@source){
    if($nextline == $currline){
        print $line . "\n";
        if(@sorted > 0){
            $nextline = shift(@sorted);
        }
    }
    $currline++;
}

Bug reports welcome, just leave a comment.