2015年8月3日 星期一

Raspberry pi NOOBS install on linux

Main -> http://qdosmsq.dunbar-it.co.uk/blog/2013/06/noobs-for-raspberry-pi/
https://github.com/raspberrypi/noobs/wiki/NOOBS-partitioning-explained
https://github.com/raspberrypi/noobs
http://blogger.gtwang.org/2014/12/raspberry-pi-b-plus-noobs-linux-installation.html

# unmount the sdcard
umount /media/3466-6661/

# check sd card
fdisk -l

# format sdcard
fdisk /dev/sdc
// detail
----------
# delete them using the ‘d’ command repeat until you have deleted them all.
Command (m for help): d
Selected partition 1

# Listing the existing partitions afterwards should show the following:
Command (m for help): p

# create a single new partition
Command (m for help): n
Select (default p): p
Partition number (1-4, default 1): 1
First sector (1-15523839, default 2048): 1
Last sector (1-15523839, default 2048): 15523839

# The partition type is FAT32
Command (m for help): t
Hex code (type L to list codes): b

# Print content
Command (m for help): p
Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1936    15550888+   b  W95 FAT32


# All that remains now is to write the new partition table to the SD card
Command (m for help): w
The partition table has been altered!

------

# finally format the particial
mkfs.vfat /dev/sdc1



# check noobs boot integraty
>sha1sum NOOBS_v1_4_1.zip
279cdeb50861d2ef2681b4d1f5e98c40581f48b1  NOOBS_v1_4_1.zip



# mount the sdcadrd
mount -t vfat  /dev/sdc1 /media/pi


# cp the boot file
cd /media/pi/
unzip /home/Andy/IBMS/Software/pi/NOOBS_v1_4_1.zip


# exit
cd ~
umount /media/pi

2015年8月2日 星期日

First For Backbone.js of simple hello world


Backbone.js provide the MVC pattern for web development

1. HTML code

  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>hello-backbonejs</title>
  </head>
  <body>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js"></script>
  <script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script>

  <script src="1.js"></script>


  </body>
  </html>


2. JS code
// This example illustrates the declaration and instantiation of a minimalist View.
 (function($){
          var ListView = Backbone.View.extend({
//                 el: $('body'), // attaches `this.el` to an existing element.
                 el: 'body', // attaches `this.el` to an existing element.

                initialize: function(){
                        _.bindAll(this, 'render'); // fixes loss of context for 'this' within methods
                       this.render(); // not all views are self-rendering. This one is.
                },
                render: function(){
                      $(this.el).append("<ul> <li> cool hello world</li> </ul>");
                }
          });
         var listView = new ListView();
})(jQuery);


Reference
1. hello-backbonejs_example
2. tutorials_eample
3. backbonejs_doc

2015年7月21日 星期二

Apache shiro ldap multiple OU

Problem:

Shiro provide the LDAP access, but the accessing links is only complete CN.
such as
ldapRealm.userDnTemplate = cn={0},ou=eee,dc=gp,dc=mycompany

If you want to access the different ou such as
ldapRealm.userDnTemplate = cn={0},ou=eee,dc=gp,dc=mycompany
ldapRealm.userDnTemplate = cn={0},ou=aaa,dc=gp,dc=mycompany

It will use the ou=aaa, how to I access the two ou in same ldap content ?


Solution:

I define the access multiple ou format in shiro and inheritance the JndiLdapRealm

a. Shiro format  in shiro.ini
  - Define handle class
     >  ldapRealm = package.LdapMultiOU
  - Using the piple as sepearte
     > ldapRealm.userDnTemplate = cn={0},[cn=aaa|ou=eee],dc=gp,dc=mycompany


b.  The code

public class LdapMultiOU extends JndiLdapRealm {

protected AuthenticationInfo queryForAuthenticationInfo(
AuthenticationToken token, LdapContextFactory ldapContextFactory)
throws NamingException {

Object principal = token.getPrincipal();
Object credentials = token.getCredentials();

// coding
AuthenticationInfo info = null;
NamingException e = null;

principal = getLdapPrincipal(token);
System.out.println("Before ldap cn was " + principal);
String[] CNs= principal.toString().split(",");
StringTokenizer OUs = new StringTokenizer(CNs[1].replaceAll("(\\[|\\])", ""), "|"); 
while (OUs.hasMoreTokens()) {
         principal = CNs[0] + "," + OUs.nextToken() + "," +  CNs[2] + "," + CNs[3];
System.out.println("After ldap cn was " + principal);
       LdapContext ctx = null;
    try {
ctx = ldapContextFactory.getLdapContext(principal, credentials);
// context was opened successfully, which means their credentials
// were valid. Return the AuthenticationInfo:
info = createAuthenticationInfo(token, principal, credentials, ctx);
} catch (NamingException eNam) {
e = eNam;
    } finally {
LdapUtils.closeContext(ctx);
}
    }

if (info != null)  return info;
else throw e;
}
}


Reference:
http://stackoverflow.com/questions/9273631/apache-shiro-ldap-multiple-ous
http://blog.stratio.com/supporting-service-based-multi-realm-authentication-and-authorization/

2015年7月19日 星期日

Javascript Regular Expression

Description

Javascript provides two  regular function.

exec():
- Goal: This method will testing the string and return the match pattern into array.
- Example:
var  tabName = /#(.*)/g.exec(window.location.href)[1];

test():
- Goal: only testing the string is having the pattern and return true or false




Reference:
Chinese introduction
More detail explanation





2015年7月8日 星期三

Jquery event handler

1. You can define your own event using trigger() method

 $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')



2. Then to receive the event by bind() or on() method

 $(document).bind('reveal.facebox', function() {

}

2015年5月18日 星期一

Multiple CSS and jquery

Problem Description

How does the meaning in class="errorMessage active"
HTML Code
<span class="errorMessage active">Invalid</span>


CSS Code and why the .active after the .errorMesage
.errorMessage{
display: none;
color: red;
margin-left: 10px;
}
.errorMessage.active {
display: inline-block;
border: 1px solid #e6e6e6;
padding: 0 5px;
background: #ffdae0;
border-radius: 3px;
}

Jquery code
$('.IncludeSnRNA').on('change', function(){
    if($(this).is(":checked")){
    $('.errorMessage').addClass("active");
    $('.IncludeSnRNA').val('t');
    }else {
    $('.errorMessage').removeClass("active");
    $('.IncludeSnRNA').val('f');
    }
    });



Solution

Target an element that has all of multiple classes
and means the active class of errorMessage class is use as constraint to that the subject is errorMessage

2015年5月4日 星期一

Jquery Deffer method

Introduction Basic content

Ajax: Asynchronous Java script and XML
JSON: Using string representation for an object 
jqXHR object:  is jquery XML HTTP object which represent as $.ajax
JSONP: Give a strategy to access cross domain data
 
                    Subject of Deffer function
Goal: 
It will let programmer make a asyn-like calling mechanism
and often use in nested ajax calling to avoid to nested content.

Event trigger:
In the process, declare the deffer start .deffer().
Then, you should write deffer.resolve() mean it success, or deffer.reject() mean fail in handle process.
Finally, you return it by .promise();

Event Handle:
Client code can handle it by .then(callback1, [callback2]) method after it use the Event trigger method,


Ref:
ajax-deferreds tutorial
jquery deferred-object function
jquery-deferred-object chinese