Jan 29, 2011

Sleep Patterns as a Function of Age

Sleep is not the same over a human life time. The time to fall asleep, the efficiency of sleep, and the amount of sleep vary with age. I found a great article about age-related changes in sleep patterns and thought it is of general interest to show some of the graphs that show these changes. It also shows that there is a difference between depressed and normal people. Read on to see them.

I found this in an article called "Age-related changes in sleep in depressed and normal subjects" by Gillin and colleagues published in the journal Psychiatry Research (vol 4, nr. 1) in 1981. They did all-night electroencephalography during sleep of people diagnosed with depression (78 people in total) and controls (who were not diagnosed as depressed, 36 in total). Both groups of people were unmedicated.

They found that healthy (non-depressed) people sleep more than depressed people.
sleep duration over age in normal and depressed people

Interestingly the total sleep time of sleep decreases over age. This trend is very much pronounced in depressed people. Another chart shows that the REM latency (the time to reach REM sleep) decreases over time, so people over age, become better with age in reaching REM sleep.

They also found that depressed people took longer to fall asleep as evidenced in the graph below.
sleep latency over age in normal and depressed people

From looking at the other charts, the time to wake up seemed to be inversely correlated on the latency (time to fall asleep) and of sleep duration. Depressed people took much longer to wake up. Depressed people not only sleep less, but also they wake up more frequently during the night.

(Please note, that the colors are inverted for depressed and healthy people (between the two graphs.)

Enjoy. Please leave a comment below for questions and suggestions.

Jan 4, 2011

Dynamic Javascript Loading on Scroll

If you have a lot of widgets on your webpage page, you can try out many tools in order to speed up page loading, however there is a limit to optimization. It is often tried to put heavy javascripts at the end of page loading, putting them before <head> or using the window.onload function. In this post, I show an alternative that has the advantage of shorter initial page loading and a smoother user experience than these methods.

I had the idea when I was researching social toolbars. Often the social toolbar would appear only when the page was scrolled. Therefore page scrolling should be detected and if the page was scrolled down the toolbar would fade in.

I thought that the same code could be applied for dynamic javascript loading. Many libraries are not needed initially. Some widgets are only visible once the page is scrolled. I implemented some code myself for scroll event detection, however in the end, I use the ajax library for this purpose.

Here comes the general pattern:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js' type='text/javascript'/>
<script id='aptureScript' type='text/javascript'>
function jsload(src){
var a=document.createElement("script");
var dynloaded=false;
$(function() {
$(window).bind("scroll", function(event) {
if($(window).scrollTop() > 50){
// ...
// javascript loading here, ex. jsload('script.js')

The number, marked in red is the scrolled distance from the top of the page, at which the loading of additional javascript code will occur.

Please note that if you want to use this in your blogger template, make sure to escape html tags within the javascript code.

Enjoy. Please leave a comment below for questions and suggestions.