Monday, August 18, 2014

What is sleep? How much sleep do i need?



Sleep is a state when our senses and motor activity are relatively suspended; there is total or partial unconsciousness, and all voluntary muscles are inactive. Sleep is more reversible than hibernation or coma, but responds less to stimuli than quiet wakefulness. Sleep is the body's rest cycle.

This Medical News Today article provides the essential details about sleep, including how much sleep we need, what a sleep debt is, sleep deprivation, and sleep disorders.

At the end of some sections we have included updates from MNT's news stories.

Sleep is a heightened anabolic state - a period when our bodies are producing new bone, muscular and nervous tissue; a period when growth and repairs occur.

Most animals sleep, including mammals (humans are mammals), birds, a significant number of reptiles, amphibians, and fish.

A complex group of hormones trigger sleep. These hormones respond to cues within our body, as well as in the environment. Approximately 80% of sleep time is without dreams, this period of mainly dreamless sleep is known as NREM (non-rapid eye movement). Dreams occur mainly during REM (rapid eye movement).

According to the National Institutes of Health1, a number of crucial tasks are carried out by the human body during sleep to help maintain good health so that we can function at our best. Not getting enough sleep can be dangerous for both our physical and mental health.

Many people find it hard to fall or stay asleep. The Sleep Disorders Center2 at the University of Maryland informs that approximately 9-12% of the U.S. population have chronic insomnia.

NREM (non-rapid eye movement) sleep - during this period our heart and breathing rates are slow, and blood pressure drops. The person does not move about much.

NREM sleep is divided into three or four stages:
Stage 1 sleep - the transition period between wakefulness and sleep. There is slow eye movement. Alpha waves make way for Theta waves. If someone in this stage is woken up, they think they have not been asleep. Hypnic jerks (involuntary twitches) commonly occur during this stage.

Stage 2 sleep - 50% of our sleeping time is in Level 2. The heart and breathing rates slow right down. The eyes do not move at all. People hardly ever dream during this stage. Even though the sleeper is quiet, they can be easily awakened.

Stages 3 & 4 sleep - used to be divided into 3 and 4, but is now more commonly grouped into just Stage 3. Stage 3 used to be the transition period between 2 and 4, when delta waves started to occur. Delta waves are associated with deep sleep, and dominate Stage 4 sleep. There is some dreaming in this stage, more than in stages 1 and 2, but much less than in REM sleep.

REM (rapid eye movement) sleep - a normal stage of sleep that makes up between 20% and 25% of total sleep time. There is rapid movement of the eyes and low muscle tone.

Babies spend much more of a night's sleep in REM than older people.

Humans generally experience four or five periods of REM sleep during a typical full sleeping session; the last one is longer than the first.

Some people may have a brief period of light sleep, during which they are easily awakened, shortly after an REM session.

Sleep experts say our brain neurons are about as active during REM as they are when we are awake. However, atonia paralyzes the body during REM. Atonia is an extremely relaxed state of skeletal muscles.

If we remember a dream, it would have occurred during REM.

How much sleep do I need?

Our sleep requirements vary according to our age, lifestyle, when sleep occurs, how fixed our routines are, our general state of health, and our individual circadian rhythms (body clock). The figures below are general approximations, depending on age:

Daily sleep requirement, according to age and condition:
Newborn baby - up to 18 hours
1 to 12 months of age - 14 to 18 hours
1 to 3 years of age - 12 to 15 hours. A study found that midday naps boost learning in preschoolers.
3 to 5 years of age - 11 to 13 hours
5 to 12 years of age - 9 to 11 hours
Teenagers - 9 to 10 hours
Adults - 7 to 8+ hours
Women during pregnancy - at least 8 hours

It is important to remember that sleep requirements vary between individuals of the same age, health and lifestyle - sleep needs are individual. The figures above should at best be seen as a rough guide. A 28 year-old man may function well with 7 hours sleep each day, while a work colleague of the same age, health, height, weight and lifestyle may need 8 hours.


Source : MNT

Saturday, June 21, 2014

Salesforce Integration - Notes


* API/ Webservice
- API - Collection of methods
Ex : Salesforce
Force.com API
- Webservice - Small service
* SOAP API
- Strict Grammer rules.
-  Number of parameter should match.
-  Datatype Should match
- WSDL - Webservice Description Language
- Generate WSDL File in salesforce.
- XSD - XML Schema Defination
* REST API
- Mostly used in mobile
* Call - In / Call - Out
- Access Salesforce from outside - Call In
- Access Outside service from Salesforce - Call Out
* Formats : XML/ JSON / Key - Value
* Authentication Mechanisems
* HTTP
Request header
Request Body
Response header
Response body
* XML Parsing
XMLStreamReader
* JSON Parsing
JSON Serialize/Deserialize
================================================================

Wednesday, March 12, 2014

Backbone.js For Salesforce1

Backbone js tutorial for beginners

http://youtu.be/HsEw2i4wQMM
http://www.youtube.com/watch?v=2BDGBJUtAmo
http://adrianmejia.com/blog/2012/09/11/backbone-dot-js-for-absolute-beginners-getting-started
http://backbonejs.org/
http://www.youtube.com/watch?v=_6pBvMK1Qgo

Backbone force

Backbone js Script URLS (Can downloaded from http://cdnjs.com/)
Underscore js : 
          http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js
Backbone js : 
          http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js

Jquery js:
         Normal all jquery plug ins

Libraries

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Hello World in Backbone.js</title>
</head>
<body> 
  <!-- Your HTML --> 
  <!-- Libraries -->  
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js" type="text/javascript"></script>
  <!-- Javascript code -->  
  <script type="text/javascript">
    // your JS code goes here
  </script>
  
</body>
</html>

Example code for Model
=================

<apex:page docType="html-5.0" standardStylesheets="false" showHeader="false" sidebar="false">
<head> 
  <link href="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/css/jquery.mobile-1.3.0.min.css')}" rel="stylesheet" />
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/jquery-2.0.0.min.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/underscore-1.4.4.min.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/backbone-1.0.0.min.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/forcetk.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/force.entity.js')}" type="text/javascript"></script>
  
  <script>      
      var book = Backbone.Model.extend({ 
          //x.get('Author') - if we trying to access the record, before creating the record, it gives the error. To avoid this situvation we can use the defaults function
          defaults: function(){
              return{
                  Author: 'Raja',
                  Book: 'BackBone'
              }
          },           
          // initialize method used to run the code in onload         
          initialize: function(){
              alert('called');
          }
      });
      
      //If we create the list of records, we need the initialize the variable for Backbone.Collection
      var bookListTemp = Backbone.Collection.extend({
          model:book
      });
      
      var bookLists = new bookListTemp();
      var x = new book({Author: $('author-name').val(), Book: $('book-name').val()}); 
      bookLists.add(x);    
      // toJSON() - used to dispaly the list of elemets
      // x.get('Author') - used to display the author of a single record 
      console.log(bookLists.toJSON());
  </script>  
  </head>
  <form>
      Author : <input type="text" name ="author" id="author-name"/>
      Book : <input type="text" name ="book" id="book-name"/>
   </form>
  
</apex:page>

HTML Example code for view
<html>
<body>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js" type="text/javascript"></script>
  <div id="div1">Loading...</div>
  <script>
    var viewVar = Backbone.View.extend({    
        el : '#div1',
        initialize: function(){      
       
          this.render();
        },
     
        render: function(){        
          this.$el.html('test');
        }
    });
    var ins = new viewVar();
  </script>
</body>
</html>

 Backbone’s Templates
_.js templates have the following syntax

_.template(templateString, [data], [settings])

where in the templateString you use the place holder <%= %> and <%- %> to dynamically insert data. The later allows for HTML escape while the first one doesn’t. Moreover, you can use <% %> to run any javascript code.

Example for Backbone view with template


    var AppView = Backbone.View.extend({
      el: $('#container'),
      // template which has the placeholder 'who' to be substitute later 
      template: _.template("<h3>Hello <%= who %><h3>"),
      initialize: function(){
        this.render();
      },
      render: function(){
        // render the function using substituting the varible 'who' for 'world!'. 
        this.$el.html(this.template({who: 'world!'}));
        //***Try putting your name instead of world.
      }
    });

    var appView = new AppView();

Backbone events

Events are written in the following format: {"<EVENT_TYPE> <ELEMENT_ID>": "<CALLBACK_FUNTION>"} E.g. events: {'keypress #new-todo': 'createTodoOnEnter'} in jQuery it would be something like: $('#new-todo').keypress(createTodoOnEnter);


Backbone js code for show the list of websites in button click
==============================================================
<apex:page > 
    <head>
        <link href="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/css/jquery.mobile-1.3.0.min.css')}" rel="stylesheet" />
        <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/jquery-2.0.0.min.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/underscore-1.4.4.min.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/backbone-1.0.0.min.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/forcetk.js')}" type="text/javascript"></script>
        <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/force.entity.js')}" type="text/javascript"></script>
    </head>
    <body>       
        <div id="container">
            <button> Load</button>
            <ul id="list">             
            </ul>
        </div>
        <div id="list-template">
            <li> <a href=""> </a> </li>
        </div>
        <script type="text/javascript">
            var model = new Backbone.Model({
                data:[
                    {text: 'Google', href: 'www.google.com'},
                    {text: 'Yahoo', href: 'www.yahoo.com'}
                ]
            }); 
            
            var viewVar = Backbone.View.extend({
                initialize: function(){
                    this.template = $('#list-template').children();    
                },
                
                el:'#container',
                
                events: {'click button': 'render'},
                
                render: function(){
                    var data = this.model.get('data'); 
                    var l = data.length;                    
                    for(var i= 0;  i < l; i++){
                    var li = this.template.clone().find('a').attr('href', data[i].href).text(data[i].text).end();
                        this.$el.find('ul').append(li);
                    }  
                }
                
            });  
            var view1 = new viewVar({model: model});                      
        </script>        
    </body>
</apex:page>

Call the controller method in backbone.js visualforce page

//Use VF Remoting to send values to be
//queried in the associated Apex Class


In the following example 

CallEditControllerMobileVersion -Apex Controller Name
updateApprovedCallsTest - Apex Controller method name
callId - Parameter for the method updateApprovedCallsTest (We can send more parameters with , separator)

Example:
------------
app.ContactView = Backbone.View.extend({
        events : {
            "click #approveButton" : "approveCalls"
        },
        approveCalls: function (event){  
            var callId = $(event.currentTarget).find('input[type=hidden]').val();  
            alert(callId);
            Visualforce.remoting.Manager.invokeAction(
                '{!$RemoteAction.CallEditControllerMobileVersion.updateApprovedCallsTest}',
                    callId,
                    function(result, x){
                        console.log(result);
                        
                        if (x.status) {
                            console.log(result);
                            
                        } else if (x.type ==='exception') {
                            console.log('exception');
                        } 
                        
                    },
                {escape: true}
            );
        },
        tagName: 'li',
        template: _.template($('#contact-template').html()),
        render: function(){
          this.$el.html(this.template(this.model.toJSON()));
          return this; // enable chained calls
        },
        initialize: function(){
        }
      });   


How to Built the redirect URL for one app
===============================
Example:
------------
* sforce.one - returns true if the page loaded from mobile, otherwise it returns false

var warehouseNavUrl;
try{
    if(sforce.one){
 
        warehouseNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + warehouse.Id + '\')';
    }
} catch(err) {
    console.log(err);
    warehouseNavUrl = '\\' + warehouse.Id;
}


Tuesday, February 25, 2014

Salesforce Videos

ANALYTICS FOLDER SHARING BUILDING MATRIX REPORTS
HOW TO USE CROSS FILTERS IN SALESFORCE REPORTS INTRODUCING JOINED REPORTS IN SALESFORCE
TIPS FOR SCHEDULING REPORTS MAKING YOUR REPORTS RUN FASTER
EMBEDDING CHARTS ANYWHERE GETTING STARTED WITH REPORT BUILDER
GETTING STARTED WITH BUCKETS DASHBOARD OVERVIEW
Source: Salesforce.com

Salesforce - Generate dynamic inner query to fetch parent and related child records

Use Case: In many scenarios, we need to clone the records with related child records. Issue / Limitation: We may simply use the "cl...