Navigation and Navigation bar

Why Website Navigation?
  • Websites are rarely single pages
  • Need to provide visitors an intuitive means of getting around your website
  • Several commonly used navigation patterns used on websites
Information Architecture
  • Structure of a system with respect to the way the information is:
    • Organized
    • Labeled
    • Navigation methods provided to access the information
  • Need to consider when designing websites
  • Dictates the provisioning of navigation on websites
Website hierarchy


Navigation bars
  • Users often expect it at the top of the website
  • Contains links to various pages within your website
  • Dos and Don'ts
    • Dos  : Use simple, user-friendly terms
    • Dos  : Standardize navigation
    • Dos  : Provide indication of the location within the navigation hierarchy
    • Dos  : Use standard web conventions:
      • Clicking on a logo takes you back to homepage
    • Don'ts : Have too many items
    • Don'ts : Use generic labels
Breadcrumbs


  • Secondary navigation
    • Usually placed below the primary navigation and above the content
  • Indicator of the current page's location within a navigational hierarchy
    • Path based: set of steps
    • Location based: hierarchy
    • Attribute based: set of choices
Other Navigation Aids
  • Tab
  • Pills
  • Pagination
  • Dropdowns
  • Accordion
  • Tags/Tag clouds
  • Scrollspy
  • Affix

Bootstrap Grid System

Viewport

<meta name="viewport" content="width=device=width,initial-scale=1">
The viewport meta tag : 

  • Ensures that the screen width is set to the device width and the content is rendered with this width in mind
  • Designing the websites to be responsive to the size of the viewport
    • Bootstrap grid system
Bootstrap grid

Designed to be:
  • Responsive
  • Mobile first
  • Fluid


- Bootstrap makes available four classes

  • xs for extra small
  • sm for small
  • md for medium
  • lg for large screen sizes
- Each row in Bootstrap grid system is divided into 12 columns
- Use the classes .col-xs-*, .col-sm-*, .col-md-*, .col-lg-* for defining the layouts for the - various screen sizes
- Specify how many columns each piece of content will occupy within a row, all adding up to 12 or multiple thereof.

Bootstrap grid detail


Using column classes



Using column push and pull


Column offsets


Nesting columns



Responsive Design

Why Responsive Design?
  • Users increasingly accessing websites from a variety of devices of different screen sizes
  • One size fits all no longer a possibility!
  • Adapt to the user's "viewport"
    • Build it into the core of the site
Another term you will often hear people talking about in the context of responsive design is Mobile First. What exactly is Mobile First design? Traditionally, when people were designing their websites for both larger screen windowed devices like laptops and desktops and smaller screens, they would often do the layout for the larger screens first, and then try to adapt their content to be appropriately displayed on the smaller screen. So in this diagram here that you see the traditional approach would have been first to design for a laptop and then adapt .


Increasingly, people are adopting the mobile first approach. What this means is that you first design your website with the mobile screen size in mind. First, do all your layout for the mobile screen size, and then start adapting your website design for larger screen sizes. So as your screen size expands the content will automatically flow and then adjust itself to occupy the larger width of the screen that becomes available on larger screen devices.

In order to achieve mobile first design, there are three things that need to come together:
  • First, your front end UI framework should be able to support a grid based system. This has been increasingly been opted by most front end UI frameworks. So look at anyone of the front end frameworks that is in use, and you will see that they will have some kind of support for a grid-based system.
  • The second aspect is to have fluid images, or what we call responsive images, so you can make your website images automatically adapt to the size of the screen. So this again has to be built-in. Bootstrap has good support for fluid images or responsive images already available within the Bootstrap CSS classes.
  • The third kind of support that is required is what we call media queries.
    • CSS technology to apply some styles based on the size of the viewport
      • e.g.,
        @media screen and(min-width: 600px){
              /* CSS styles customized for desktop */
        }



Getting Started with Bootstrap (Part 2)


Bootstrap Container class
<div class="container">... </div>
  • Container for all the content of the site
  • Fixed width (width depends on screen size)
  • Use as the outermost div to wrap all the site content for the grid to work correctly
  • .container-fluid class allows full width container
Bootstrap Rows
<div class="row"> ... </div>
  • Divide the page into multiple rows
  • Rows act as horizontal grouping for columns
  • Rows must be inside containers
Jumbotron
<div class="jumbotron">...</div>
  • Lightweight, flexible component for showcasing key content, e.g., company name, logo and key information.
  • Can be used outside a container to span the entire screen width
    • Use a container inside if you wish to contain the content within a fixed width

Getting Started with Bootstrap (Part 1)

Getting Bootstrap

Compiled Bootstrap source
  • Bootstrap files
  • Minified files available
  • Need to include these files
    within your project













Using bootstrap
Include these lines in the <head> of your html code 
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
Include the CSS files in the <head>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
Include the Javascript files at the bottom of the <body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
Using Bootstrap CDN
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"><script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"><script>

Introduction to Bootstrap

Bootstrap overview



Bootstrap is the most popular HTML, CSS and JS framework for developing responsive, mobile first projects on the web.
  • Front-end framework for faster and easier web development
  • Includes HTML and CSS based design templates for typography, forms, buttons, tables, navigation, modals, image carousels and many other, as well as optional JavaScript plugins
  • Easily create responsive designs with mobile first approach

Bootstrap history
  • First released in 2011
    • Mark Otto and Jacob Thornton
  • Currently in Version 3.3.5
    • 4.0 soon to be out
  • The first comprehensive framework
    • Gained popularity very quickly

Convert Decimal Number To Roman Number With Javascript

The roman symbol
Romans Numerals are based on the following symbols:




Basic combination :










Really big number:




How to convert from decimal to roman (less than 10000) :
function convertToRoman(num) {
 var arrRoman = [ 'I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD','D', 'CM', 'M' ];
 var arrDec = [ 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 ];
 var romanNum = "";
 while (num > 0) {
  for (var i = 0; i < arrDec.length; i++) {
   if (num >= arrDec[arrDec.length - 1]) {
    romanNum += arrRoman[arrDec.length - 1];
    num = num - arrDec[arrDec.length - 1];
   } else {
    if (num >= arrDec[i] && num < arrDec[i + 1]) {
     romanNum += arrRoman[i];
     num = num - arrDec[i];
    }
   }
  }
 }
 return romanNum;
}

What is Full Stack Web Development

What is Full Stack Web Development? Let me start by clarifying a few terms, so that we start with a common understanding about this area. First, we hear people talking about Front end and Back end, or sometimes the Client-side and the Server-side. Now when we talk about Front end we are primarily talking about presenting the data to the users. So this is where the users access the web through the browser. And so we would be using technologies like HTML, CSS and JavaScript to target the end users.

The Back end is more concerned with the business logic and the data aspect of our web application, so this might be implemented in one of several languages.

We often hear people talking about the Three Tier Architecture for web development and implementation. 

















Now in this approach, which is a common client-server software architecture pattern, the entire development is divided into three layers. 
  • The Presentation layer, which is concerned with the UI related issues and how to present the data to the end-user. 
  • Then we have the Business Logic layer, which is more concerned with data validation and processing the data in order to generate information for the users. 
  • And then we have the Data Access layer, which deals with data persistence and storage of data behind the scenes, for example, in a database. 

Exploring this further, let's look at what is implemented in each of these three layers in more detail. Now, the Business Logic layer is typically implemented, traditionally, in a server, where we use languages like Ruby, Python, C++, Java, on ASP.net, to implement a server. This server in turn, is talking to a Back end database management system to exchange data and in turn, will be generating the Front end display of data to the user by Server-side rendering of the HTML, CSS and JavaScript. This has been the traditional approach that that has been used successfully in the development. Now in this approach, we need specialists in each of these three layers. So, you have a Front end specialist who would be well versed in HTML, CSS, and JavaScript. And then you have the Back end specialists, one who would be well-versed in Server-side implementations, say, for example, one of the languages used for Server-side implementation. And then you would have a data specialist who would be mostly concerned with the databases and data persistence aspect of our web development.


There is an increasing trend towards Full Stack Web Development where a single language is used for implementation over the entire stack. So you could be having the front implemented as a single page application, using one of the JavaScript frameworks like AngularJS. Then the Server-side could be implemented using technologies like NodeJS and NodeJS modules, which again, depends on JavaScript. And then, the Data Access or data storage part implemented using Technologies like MongoDB, which works based on storing JSON data, and serving up information in the form of JSON data. Now, JSON has become the standard format for data interchange among the three layers. Server side increasingly is delivering a REST API, so that you can target multiple platforms through the REST API. So, essentially, the server is serving up data in the form of JSON, which can then be rendered either on a standard web browser, or on a mobile device using one of the multiplied form, hybrid mobile application development environments. 












So, in this particular specialization we are targeting the entire stack. We'll look at HTML, CSS, and JavaScript and then we will look at web UI development using Bootstrap. Then we'll look at Front end JavaScript frameworks like AngularJS. Then we'll look at NodeJS and NodeJS Modules, and also review Back end as a service, and also review data support through MongoDB on the Server side. 
Recommender system to find music

Recommender system to find music

Problem:

I need on building recommender systems to find music that interest users.

Solution:

I built  a personalized model, and showed the significant improvement provided by personalization. I’m going to explore the song data and the recommendations made by my model.

Download:

Start:

# Use Graphlab library
import graphlab
# Use Sframe of Graphlab to load data
song_data = graphlab.SFrame('song_data.gl/')
# Create Users to contain all users are unique
users = song_data['user_id'].unique()
# Create Train Data, Test Data
train_data,test_data = song_data.random_split(.8,seed=0)
# Use similarity recommender
personalized_model = graphlab.item_similarity_recommender.create(train_data,
                                                                 user_id='user_id',
                                                                 item_id='song')
# Use the persionalized model to find similar songs to any song in the dataset
personalized_model.get_similar_items(['With Or Without You - U2'])
Screen Shot 2016-01-25 at 5.39.14 PM
#the personalized model to make song recommendations
personalized_model.recommend(users=[users[0]])
Screen Shot 2016-01-25 at 5.41.02 PM

Finish

Basic Data Manipulation

Read an NIfTI files

This is example to read some NIfTI files and execute some basic data manipulation, by using this example code you must be install package oro.nifti,fslr,AnalyzeFMRI first.

Download a NIfTI file from Neurohacking_data repository

library(oro.nifti)

url <- "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001-01-MPRAGE.nii.gz"
destfile <- "SUBJ0001-01-MPRAGE.nii.gz"
fname <- file.path(getwd(), destfile)
download.file(url, destfile,mode="wb") # NIfTI is binaryfile format

maskurl <- "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001_mask.nii.gz"
maskdestfile <- "SUBJ0001_mask.nii.gz"
maskfname <- file.path(getwd(), maskdestfile)
download.file(maskurl, maskdestfile,mode="wb") # NIfTI is binaryfile format

T1 <- readNIfTI(fname,reorient=FALSE)

mask <- readNIfTI(maskfname, reorient=FALSE) 

Show meta data from MPRAGE file

print (T1)
## NIfTI-1 format
##   Type            : nifti
##   Data Type       : 16 (FLOAT32)
##   Bits per Pixel  : 32
##   Slice Code      : 0 (Unknown)
##   Intent Code     : 0 (None)
##   Qform Code      : 1 (Scanner_Anat)
##   Sform Code      : 0 (Unknown)
##   Dimension       : 170 x 256 x 256
##   Pixel Dimension : 1.2 x 1 x 1
##   Voxel Units     : mm
##   Time Units      : sec
As you see the Dimension is : 170 x 256 x 256

Show meta data from MPRAGE file

print (mask)
## NIfTI-1 format
##   Type            : nifti
##   Data Type       : 4 (INT16)
##   Bits per Pixel  : 16
##   Slice Code      : 0 (Unknown)
##   Intent Code     : 0 (None)
##   Qform Code      : 1 (Scanner_Anat)
##   Sform Code      : 1 (Scanner_Anat)
##   Dimension       : 170 x 256 x 256
##   Pixel Dimension : 1.2 x 1 x 1
##   Voxel Units     : mm
##   Time Units      : sec
As you see the of mask is same dimension (170 x 256 x 256).

Visualizing orthographic T1

orthographic(T1)


Visualizing orthographic mask

orthographic(mask)


Visualizing orthographic T1*mask

library(fslr) # you may need install fslr
masked.T1 <- niftiarr(T1, T1*mask)
orthographic(masked.T1)


Visualizing orthographic subtract

library(fslr) # you may need install fslr

followurl <- "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001-02-MPRAGE.nii.gz"
followdestfile <- "SUBJ0001-02-MPRAGE.nii.gz"
followfname <- file.path(getwd(), followdestfile)
download.file(followurl, followdestfile,mode="wb")

T1.follow <- readNIfTI(followfname, reorient=FALSE)

subtract.T1 <- niftiarr(T1, T1.follow - T1)
orthographic(subtract.T1)


Visualizing orthographic subtract

library(fslr) # you may need install fslr

baseurl <- "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001-01-MPRAGE_N3.nii.gz"
basefile <- "SUBJ0001-01-MPRAGE_N3.nii.gz"
basefname <- file.path(getwd(), basefile)
download.file(baseurl, basefile,mode="wb")

followurl <- "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001-02-MPRAGE_N3_REG.nii.gz"
followfile <- "SUBJ0001-02-MPRAGE_N3_REG.nii.gz"
followfname <- file.path(getwd(), followfile)
download.file(followurl, followfile,mode="wb")

T1.base.process <- readNIfTI(basefname, reorient=FALSE)
T1.follow.process <- readNIfTI(followfname, reorient=FALSE)

subtract.T1.process <- niftiarr(T1, T1.follow.process - T1.base.process)
orthographic(subtract.T1.process)


Transformations and Smoothing

Read an NIfTI file

This is example to read a NIfTI file and apply TRANSFORMATIONS AND SMOOTHING , by using this example code you must be install package oro.nifti,AnalyzeFMRI: first.

Download a NIfTI file from Neurohacking_data repository

library(oro.nifti)


url <- "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001-01-MPRAGE.nii.gz"
destfile <- "Output_3D_File.nii.gz"
name <- file.path(getwd(), destfile)
download.file(url, destfile,mode="wb") # NIfTI is binaryfile format
T1 <- readNIfTI(destfile)
As you see this file contain 22 images 512 x 512 pixels, one pixel using 16 bits

Visial an Slice an NIfTI file

image(T1,z=11,plot.type="single") 

Visualizing Log-Scale Histogram

im_hist<-hist(T1,plot=FALSE)
par(mar = c(5, 4, 4, 4) + 0.3)
col1=rgb(0,0,1,1/2)
plot(im_hist$mids,im_hist
$count,log="y",type='h',lwd=10, lend=2,
col=col1,xlab="Intensity Values",ylab="Count
(Log Scale)" ) 

Log-Scale Histogram with Linear Transfer Function

im_hist<-hist(T1,plot=FALSE)
par(mar = c(5, 4, 4, 4) + 0.3)
col1=rgb(0,0,1,1/2)
plot(im_hist$mids,im_hist
$count,log="y",type='h',lwd=10, lend=2,
col=col1,xlab="Intensity Values",ylab="Count
(Log Scale)" ) 
par(new = TRUE)
curve(x*1, axes = FALSE,xlab = "",ylab= "",
col=2, lwd=3)
axis(side=4,at = pretty(range(im_hist$mids))/
max(T1), labels=pretty(range(im_hist$mids)))
mtext("Original Intensity", side=4, line=2) 



Plot the spline transfer function

#This defines a linear spline. Other definitions are possible
lin.sp<-function(x,knots,slope)
 {knots<-c(min(x),knots,max(x))
 slopeS<-slope[1]
 for(j in 2:length(slope)){slopeS<-c(slopeS,slope[j]-
sum(slopeS))}
 rvals<-numeric(length(x))
 for(i in 2:length(knots))
 {rvals<-ifelse(x>=knots[i-1], slopeS[i-1]*(x-knots[i-1])+rvals,
rvals)}
 return(rvals)}
#Define a spline with two knots and three slopes
knot.vals<-c(.3,.6)
slp.vals<-c(1,.5,.25) 

im_hist<-hist(T1,plot=FALSE)
par(mar = c(5, 4, 4, 4) + 0.3)
col1=rgb(0,0,1,1/2)
plot(im_hist$mids,im_hist
$count,log="y",type='h',lwd=10, lend=2,
col=col1,xlab="Intensity Values",ylab="Count
(Log Scale)" ) 
par(new = TRUE)
curve(lin.sp(x,knot.vals,slp.vals),axes=FALSE,xlab="",ylab="",col=2,lwd=3)
axis(side=4,at = pretty(range(im_hist$mids))/
max(T1),labels=pretty(range(im_hist$mids)))
mtext("Transformed Intensity", side=4, line=2) 

Apply spline transfer function

trans_T1<-lin.sp(T1, knot.vals*max(T1), slp.vals)
image(T1,z=11,plot.type='single', main="Original Image")
























image(trans_T1,z=11,plot.type='single',main="Transformed Image") 


Smoothing by GaussSmoothArray

library(AnalyzeFMRI)

smooth.T1 <- GaussSmoothArray(T1,voxdim=c(1,1,1),ksize=1,sigma=diag(3,3),mask=NULL,var.norm=FALSE)
orthographic(smooth.T1)