Pages1

ReST- Representational State Transfer

What is REST?
REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used.
REST is an architecture style for designing networked applications. The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.
In many ways, the World Wide Web itself, based on HTTP, can be viewed as a REST-based architecture. RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.
REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP, WSDL, et al.). Later, we will see how much more simple REST is.
Despite being simple, REST is fully-featured; there's basically nothing you can do in Web Services that can't be done with a RESTful architecture. REST is not a "standard". There will never be a W3C recommendataion for REST, for example. And while there are REST programming frameworks, working with REST is so simple that you can often "roll your own" with standard library features in languages like Perl, Java, or C#.

With thanks:
http://stackoverflow.com/questions/671118/what-exactly-is-restful-programming




The answer is very simple, there is a dissertation written by Roy Fielding.]1 In that dissertation he defines the REST principles. If an application fulfills all of those principles, then that is a REST application.
The term RESTful was created because ppl exhausted the word REST by calling their non-REST application as REST. After that the term RESTful was exhausted as well. Nowadays we are talking about Web APIs and Hypermedia APIs, because the most of the so called REST applications did not fulfill the HATEOAS part of the uniform interface constraint.
The REST constraints are the following:
  1. client-server architecture
    So it does not work with for example PUB/SUB sockets, it is based on REQ/REP.
  2. stateless communication
    So the server does not maintain the states of the clients. This means that you cannot use server a side session storage and you have to authenticate every request. Your clients possibly send basic auth headers through an encrypted connection. (By large applications it is hard to maintain many sessions.)
  3. usage of cache if you can
    So you don't have to serve the same requests again and again.
  4. uniform interface as common contract between client and server
    The contract between the client and the server is not maintained by the server. In other words the client must be decoupled from the implementation of the service. You can reach this state by using standard solutions, like the IRI (URI) standard to identify resources, the HTTP standard to exchange messages, standard MIME types to describe the body serialization format, metadata (possibly RDF vocabs, microformats, etc.) to describe the semantics of different parts of the message body. To decouple the IRI structure from the client, you have to send hyperlinks to the clients in hypermedia formats like (HTML, JSON-LD, HAL, etc.). So a client can use the metadata (possibly link relations, RDF vocabs) assigned to the hyperlinks to navigate the state machine of the application through the proper state transitions in order to achieve its current goal.
    For example when a client wants to send an order to a webshop, then it have to check the hyperlinks in the responses sent by the webshop. By checking the links it founds one described with the http://schema.org/OrderAction. The client know the schema.org vocab, so it understands that by activating this hyperlink it will send the order. So it activates the hyperlink and sends a POST https://example.com/api/v1/order message with the proper body. After that the service processes the message and responds with the result having the proper HTTP status header, for example 201 - created by success. To annotate messages with detailed metadata the standard solution to use an RDF format, for example JSON-LD with a REST vocab, for example Hydra and domain specific vocabs like schema.org or any other linked data vocab and maybe a custom application specific vocab if needed. Now this is not easy, that's why most ppl use HAL and other simple formats which usually provide only a REST vocab, but no linked data support.
  5. build a layered system to increase scalability
    The REST system is composed of hierarchical layers. Each layer contains components which use the services of components which are in the next layer below. So you can add new layers and components effortless.
    For example there is a client layer which contains the clients and below that there is a service layer which contains a single service. Now you can add a client side cache between them. After that you can add another service instance and a load balancer, and so on... The client code and the service code won't change.
  6. code on demand to extend client functionality
    This constraint is optional. For example you can send a parser for a specific media type to the client, and so on... In order to do this you might need a standard plugin loader system in the client, or your client will be coupled to the plugin loader solution.
REST constraints result a highly scalable system in where the clients are decoupled from the implementations of the services. So the clients can be reusable, general just like the browsers on the web. The clients and the services share the same standards and vocabs, so they can understand each other despite the fact that the client does not know the implementation details of the service. This makes possible to create automated clients which can find and utilize REST services to achieve their goals. In long term these clients can communicate to each other and trust each other with tasks, just like humans do. If we add learning patterns to such clients, then the result will be one or more AI using the web of machines instead of a single server park. So at the end the dream of Berners Lee: the semantic web and the artificial intelligence will be reality. So in 2030 we end up terminated by the Skynet. Until then ... ;-)

IAR STM8 Linker file

/////////////////////////////////////////////////////////////////
//      Example ILINK command file for
//      STM8 IAR C/C++ Compiler and Assembler.
//
//      Copyright 2014 IAR Systems AB.
//
/////////////////////////////////////////////////////////////////

define memory with size = 16M;

define region TinyData = [from 0x00 to 0xFF];

define region NearData = [from 0x0000 to 0x03FF];

define region Eeprom = [from 0x4000 to 0x407F];

define region NearFuncCode = [from 0x8000 to 0x9FFF];

define region FarFuncCode = [from 0x8000 to 0x9FFF];

define region HugeFuncCode = [from 0x8000 to 0x9FFF];


/////////////////////////////////////////////////////////////////

define block CSTACK with size = _CSTACK_SIZE  {};

define block HEAP  with size = _HEAP_SIZE {};

define block INTVEC with size = 0x80 { ro section .intvec };

// Initialization
initialize by copy { rw section .far.bss,
                     rw section .far.data,
                     rw section .far_func.textrw,
                     rw section .huge.bss,
                     rw section .huge.data,
                     rw section .huge_func.textrw,
                     rw section .iar.dynexit,
                     rw section .near.bss,
                     rw section .near.data,
                     rw section .near_func.textrw,
                     rw section .tiny.bss,
                     rw section .tiny.data,
                     ro section .tiny.rodata };

initialize by copy with packing = none {section __DLIB_PERTHREAD };

do not initialize  { rw section .eeprom.noinit,
                     rw section .far.noinit,
                     rw section .huge.noinit,
                     rw section .near.noinit,
                     rw section .tiny.noinit,
                     rw section .vregs };

// Placement
place at start of TinyData      { rw section .vregs };
place in TinyData               { rw section .tiny.bss,
                                  rw section .tiny.data,
                                  rw section .tiny.noinit,
                                  rw section .tiny.rodata };

place at end of NearData        { block CSTACK };
place in NearData               { block HEAP,
                                  rw section __DLIB_PERTHREAD,
                                  rw section .far.bss,
                                  rw section .far.data,
                                  rw section .far.noinit,
                                  rw section .far_func.textrw,
                                  rw section .huge.bss,
                                  rw section .huge.data,
                                  rw section .huge.noinit,
                                  rw section .huge_func.textrw,
                                  rw section .iar.dynexit,
                                  rw section .near.bss,
                                  rw section .near.data,
                                  rw section .near.noinit,
                                  rw section .near_func.textrw };

place at start of NearFuncCode  { block INTVEC };
place in NearFuncCode           { ro section __DLIB_PERTHREAD_init,
                                  ro section .far.data_init,
                                  ro section .far_func.textrw_init,
                                  ro section .huge.data_init,
                                  ro section .huge_func.textrw_init,
                                  ro section .iar.init_table,
                          ro section .init_array,
                                  ro section .near.data_init,
                                  ro section .near.rodata,
                  ro section .near_func.text,
                  ro section .near_func.textrw_init,
                                  ro section .tiny.data_init,
                                  ro section .tiny.rodata_init };

place in FarFuncCode            { ro section .far.rodata,
                                  ro section .far_func.text };

place in HugeFuncCode           { ro section .huge.rodata,
                                  ro section .huge_func.text };

place in Eeprom                 {    section .eeprom.noinit };

place in Eeprom                 {    section .eeprom.data };

place in Eeprom                 {    section .eeprom.rodata };

/////////////////////////////////////////////////////////////////

Understanding Flash Memory and associated concept

Flash storage a definition:
Flash storage systems are composed of a memory unit and an access controller. The memory unit is used to store data.
The access controller manages and controls access to the storage space on the memory unit.

Types of flash memory:
1.   NOR flash
-       This has every cell connected to ground and interns it resemble the way NOR gate behaves,
and due to same reason this can be programmed randomly. And it byte addressable  

2.   NAND flash
-       Nand flash connects several cell connected in series, interns resembles with the Nand gate.
Due to the reason it can be programmed, only in blocks/pages not bytewise( Randomly)

Note: Both the flash memories uses field effect MOSFET-Metal oxide filed effect transistor- FET is  voltage controlled device while BJT- Bi polar junction transistors is voltage controlled device.  

What causes flash to store data permanently ?
Flash is a transistor-based silicon memory technology that can store information permanently by trapping electrons into,
floating-gate transistors( Field effect MOSFET)

Flash memory advantage and limitations
NOR Flash:
 Pros
-          Offers random access and hence Byte can read and written like in RAM.
-          Board can be booted directly from this type of flash memory,  as it offers random access.
-          NOR offers faster read speed.
Cons:
-          However, with NOR technology, write and erase functions are slow compared to NAND
-          NOR also has a larger memory cell size than NAND, limiting scaling capabilities and therefore achievable bit density compared to NAND
Usage: PDA, mobile phone( usually internal memory)

NAND flash:
Pros:
-          Cost effective, cheaper than NOR,
-          Size is smaller than NOR
-          Erase is cycle is faster than that of NOR.
-          can be used where big memory size is needed ideally, uses NAND gate.  
Cons:
-          No random access
-          Board can never be directly booted from this  kind of flash.


Usage: Device in which larger permanent storage is required. I.e. Digital camera, SD cards

Most frequent interview Question: How "ping" Command work, Draw flow of ping command

Ping command (Program on the application layer) --->
Opens a 'raw' socket to IP Layer -->

IP layer (Layer 2 on OSI) packages ICMP(ICMP (Internet Control Message Protocol) packet and sends it
Since there is no TCP layer in between,the Ping (program) has to monitor all the incoming ICMP packets and filter only the one's from the destination.

Relation with ARP( Address Resolution Protocol)
You enter a command to ping a destination
- DNS is used to determine the IP address (if needed)
- The routing table is consulted to find the next hop towards that destination
- ARP is used to find the hardware address of the next hop
The IP packet is sent to the next hop, encapsulated in an Ethernet or WiFi frame

ARP protocol also used when a device boots up, it sends ARP packet through this an entry in routing table is made against device mac address. Final delivery of any packet  in a network is done via use of mac address. 

Linux- How to: Edit password, group

user vipw command for the purpose. man page listing is below. vipw is system command

VIPW(8)                                                  System Management Commands                                                  VIPW(8)

NAME
       vipw, vigr - edit the password, group, shadow-password or shadow-group file

SYNOPSIS
       vipw [options]

       vigr [options]

DESCRIPTION
       The vipw and vigr commands edits the files /etc/passwd and /etc/group, respectively. With the -s flag, they will edit the shadow
       versions of those files, /etc/shadow and /etc/gshadow, respectively. The programs will set the appropriate locks to prevent file
       corruption. When looking for an editor, the programs will first try the environment variable $VISUAL, then the environment variable
       $EDITOR, and finally the default editor, vi(1).

OPTIONS
       The options which apply to the vipw and vigr commands are:

       -g, --group
           Edit group database.

       -h, --help
           Display help message and exit.

       -p, --passwd
           Edit passwd database.

       -q, --quiet
           Quiet mode.

       -s, --shadow
           Edit shadow or gshadow database.

ENVIRONMENT
       VISUAL
           Editor to be used.

       EDITOR
           Editor to be used if VISUAL is not setENVIRONMENT
       VISUAL
           Editor to be used.

       EDITOR
           Editor to be used if VISUAL is not set.

FILES
       /etc/group
           Group account information.

       /etc/gshadow
           Secure group account information.

       /etc/passwd
           User account information.

       /etc/shadow
           Secure user account information.

SEE ALSO
       vi(1), group(5), gshadow(5) , passwd(5), , shadow(5).

LINUX How to: Add user in sudoer list

While working on UBUNTU  your may incur in a situation where you need to login as root to execute some task.  When you login as sudo you may get error like: "you are not sudoer list". This ideally due to reason  that when you are trying to log for first time, root as a user is not enabled. Do make root as user ans to enable logging as root.  One has to activate root account in new UBUNTU  machine it is not activated by default. 
Execute command to activate root and set password
sudo passwd root
How to add user in sudoer list, is common problem new linux user faces.
Here is answer of this question.
vikram@vikram-Satellite-C640:~$ sudo ls -l  /etc/sudoers
-r--r----- 1 root root 723 Jan 31  2012 /etc/sudoers
vikram@vikram-Satellite-C640:~$ sudo vi /etc/sudoers
 vikram@vikram-Satellite-C640:~$ sudo visudo 
  GNU nano 2.2.6                                 File: /etc/sudoers.tmp                                                                         

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d







                                                               [ Read 29 lines ]
^G Get Help             ^O WriteOut             ^R Read File            ^Y Prev Page            ^K Cut Text             ^C Cur Pos
^X Exit                 ^J Justify              ^W Where Is             ^V Next Page            ^U UnCut Text           ^T To Spell
 

vikram@vikram-Satellite-C640:~$ sudo visudo
and add below line press CTRL +X to and "Y" to save the file. Please check the file name prior to pressing "Y" file name should ideally be "/etc/sudoers"
If file successfully over written it means command your saved is fine. 

 user ALL=(ALL)ALL 
 visudo usually parse the command you are saving against any error otherwise it you will not be able to save.

Now adding a user is sudoer list is done :)

To learn more about visudo you can open man page of visduo. Below is the man page listing
 VISUDO(8)                                                   MAINTENANCE COMMANDS                                                   VISUDO(8)

NAME
       visudo - edit the sudoers file

SYNOPSIS
       visudo [-chqsV] [-f sudoers]

DESCRIPTION
       visudo edits the sudoers file in a safe fashion, analogous to vipw(8).  visudo locks the sudoers file against multiple simultaneous
       edits, provides basic sanity checks, and checks for parse errors.  If the sudoers file is currently being edited you will receive a
       message to try again later.

       There is a hard-coded list of one or more editors that visudo will use set at compile-time that may be overridden via the editor
       sudoers Default variable.  This list defaults to "/usr/local/bin/vi".  Normally, visudo does not honor the VISUAL or EDITOR
       environment variables unless they contain an editor in the aforementioned editors list.  However, if visudo is configured with the
       --with-env-editor option or the env_editor Default variable is set in sudoers, visudo will use any the editor defines by VISUAL or
       EDITOR.  Note that this can be a security hole since it allows the user to execute any program they wish simply by setting VISUAL or
       EDITOR.

       visudo parses the sudoers file after the edit and will not save the changes if there is a syntax error.  Upon finding an error,
       visudo will print a message stating the line number(s) where the error occurred and the user will receive the "What now?" prompt.  At
       this point the user may enter "e" to re-edit the sudoers file, "x" to exit without saving the changes, or "Q" to quit and save
       changes.  The "Q" option should be used with extreme care because if visudo believes there to be a parse error, so will sudo and no
       one will be able to sudo again until the error is fixed.  If "e" is typed to edit the  sudoers file after a parse error has been
       detected, the cursor will be placed on the line where the error occurred (if the editor supports this feature).

OPTIONS
       visudo accepts the following command line options:

       -c          Enable check-only mode.  The existing sudoers file will be checked for syntax and a message will be printed to the
                   standard output detailing the status of sudoers.  If the syntax check completes successfully, visudo will exit with a
                   value of 0.  If a syntax error is encountered, visudo will exit with a value of 1.

       -f sudoers  Specify and alternate sudoers file location.  With this option visudo will edit (or check) the sudoers file of your
                   choice, instead of the default, /etc/sudoers.  The lock file used is the specified sudoers file with ".tmp" appended to
                   it.  In check-only mode only, the argument to -f may be "-", indicating that sudoers will be read from the standard
                   input.

       -h          The -h (help) option causes visudo to print a short help message to the standard output and exit.
       -q          Enable quiet mode.  In this mode details about syntax errors are not printed.  This option is only useful when combined
                   with the -c option.

       -s          Enable strict checking of the sudoers file.  If an alias is used before it is defined, visudo will consider this a parse
                   error.  Note that it is not possible to differentiate between an alias and a host name or user name that consists solely
                   of uppercase letters, digits, and the underscore ('_') character.

       -V          The -V (version) option causes visudo to print its version number and exit.

ENVIRONMENT
       The following environment variables may be consulted depending on the value of the editor and env_editor sudoers variables:

       VISUAL          Invoked by visudo as the editor to use

       EDITOR          Used by visudo if VISUAL is not set

FILES
       /etc/sudoers            List of who can run what

       /etc/sudoers.tmp        Lock file for visudo

DIAGNOSTICS
       sudoers file busy, try again later.
           Someone else is currently editing the sudoers file.

       /etc/sudoers.tmp: Permission denied
           You didn't run visudo as root.

       Can't find you in the passwd database
           Your userid does not appear in the system passwd file.

       Warning: {User,Runas,Host,Cmnd}_Alias referenced but not defined
           Either you are trying to use an undeclare {User,Runas,Host,Cmnd}_Alias or you have a user or host name listed that consists
           solely of uppercase letters, digits, and the underscore ('_') character.  In the latter case, you can ignore the warnings (sudo
           will not complain).  In -s (strict) mode these are errors, not warnings.

       Warning: unused {User,Runas,Host,Cmnd}_Alias
           The specified {User,Runas,Host,Cmnd}_Alias was defined but never used.  You may wish to comment out or remove the unused alias.
           In -s (strict) mode this is an error, not a warning.
       -q          Enable quiet mode.  In this mode details about syntax errors are not printed.  This option is only useful when combined
                   with the -c option.

       -s          Enable strict checking of the sudoers file.  If an alias is used before it is defined, visudo will consider this a parse
                   error.  Note that it is not possible to differentiate between an alias and a host name or user name that consists solely
                   of uppercase letters, digits, and the underscore ('_') character.

       -V          The -V (version) option causes visudo to print its version number and exit.

ENVIRONMENT
       The following environment variables may be consulted depending on the value of the editor and env_editor sudoers variables:

       VISUAL          Invoked by visudo as the editor to use

       EDITOR          Used by visudo if VISUAL is not set

FILES
       /etc/sudoers            List of who can run what

       /etc/sudoers.tmp        Lock file for visudo

DIAGNOSTICS
       sudoers file busy, try again later.
           Someone else is currently editing the sudoers file.

       /etc/sudoers.tmp: Permission denied
           You didn't run visudo as root.

       Can't find you in the passwd database
           Your userid does not appear in the system passwd file.

       Warning: {User,Runas,Host,Cmnd}_Alias referenced but not defined
           Either you are trying to use an undeclare {User,Runas,Host,Cmnd}_Alias or you have a user or host name listed that consists
           solely of uppercase letters, digits, and the underscore ('_') character.  In the latter case, you can ignore the warnings (sudo
           will not complain).  In -s (strict) mode these are errors, not warnings.

       Warning: unused {User,Runas,Host,Cmnd}_Alias
           The specified {User,Runas,Host,Cmnd}_Alias was defined but never used.  You may wish to comment out or remove the unused alias.
           In -s (strict) mode this is an error, not a warning.






Login as "Su" in new ubuntu machines: you are not in sudoer list

While working on UBUNTU  your may incur in a situation where you need to login as root to execute some task.  When you login as sudo you may get error like: "you are not sudoer list". This ideally due to reason  that when you are trying to log for first time, root as a user is not enabled. Do make root as user ans to enable logging as root.  One has to activate root account in new UBUNTU  machine it is not activated by default. 
Execute command to activate root and set password
sudo passwd root
Once password setting successful then one can go ahead to login a root by executing command below. 
su root