2015年1月23日 星期五

Dual/Multiple OS Installation

We often need to install multiple OS in one system, for example
  1. Windows 8 & Ubuntu 12
  2. Ubuntu 12 & Ubuntu 14
  3. Windows 8 & Ubuntu 12 & Ubuntu 14...
We often follow the below instructions to achieve (assuming you have ONE Windows pre-installed and ONE Ubuntu pre-installed and you want to install the third OS, also Ubuntu)

  1. Navigate to the BIOS, set the USB Ubuntu stick as the booting machine
  2. Turn off the security boot to prevent the laptop not loading the USB (subjected to change on different BIOS)
  3. Turn off the EUFI boot specifically for Windows 8 to avoid always booting to Windows instead of Ubuntu
  4. Boot overriding the USB drive (subjected to change on different BIOS), if no boot overriding exists, just follow the old school boot priority function
  5. Make a new partition for your Ubuntu, remember if you lack disk space, you will need to do partition resizing and  be-careful not to override the Windows partition or you may not be able to boot into Windows again!! Before installing the new OS, make sure you which partition which OS refers to.
  6. After adding/resizing the partition, format it with ext4
  7. You will need to provide the mounting point (I usually pick "/") and create a very small bootloader partition called "Reserved BIOS Boot Area" for GRUB's code, this is VERY IMPORTANT, grub provides a boot menu for you to navigate to different OS, we need to provide it with some space (normally as small as 1MB), after creating both partitions, you are okay to proceed to the installation processes.
  8. Follow the Ubuntu install guide to finish the installation. 
  9. In the final step, Ubuntu will ask you to restart the machine, just do so.
  10. Luckily you will find a Linux boot menu listing all the partitions included (e.g. /dev/sda1,sda2.... etc.) but we will miss our newly installed OS partition, we need to update the grub file to reflect the changes (OS addition)
  11. Boot into the pre-installed Ubuntu (the one before our third OS installation), navigate to /etc/default/grub and use text editior to edit it.
  12. We only interest in GRUB_DEFAULT, this controls which OS the default OS should boot in, choose the one you want and save the setting
  13. Remember after updating the file, you will need to UPDATE by sudo update-grub , if not the newly installed OS will not appear in the grub menu
  14. Reboot the machine and you will see the newly installed OS appeared.
Reference:
  1. http://askubuntu.com/questions/16042/how-to-get-to-the-grub-menu-at-boot-time
  2. http://askubuntu.com/questions/343268/how-to-use-manual-partitioning-during-installation 
 

2015年1月16日 星期五

[requireJS] define VS require

Difference between define and require

We often see define and require in requireJS, but what's their difference? I try to elaborate as below.

require
  1. When you want to load some stuff, you need to use require, like jquery, bootstrap etc.
  2. It has NO return statement
e.g.:
require(["jquery", "bootstrap", "bootstrap_select"], function() {
 //requirejs sugar function
 var angular = require('angular');
});


define
  1. As the name implies, it helps you define module that will be depend by other modules or applications
  2. It has return statement for inclusion by other modules
e.g.:
define(["angular", "angular-route", "angular-animate"],function(angular){
 var insiderApp = angular.module("insiderApp",["ngRoute", "ngAnimate"]);
 //routing
 insiderApp.config(['$routeProvider','$locationProvider',function($scope,$routeProvider,$locationProvider){
  
 }]);
 
 return insiderApp;
});

This is official explanation
 /**
     * The function that handles definitions of modules. Differs from
     * require() in that a string for the module should be the first argument,
     * and the function to execute after dependencies are loaded should
     * return a value to define the module corresponding to the first argument's
     * name.
     */

2015年1月15日 星期四

[requireJS] Case Study: Working With AngularJS

Struggling for 2 days, I finally make myself clear with the combination of angularJS and requireJS. I will note down with examples.


Target
  • To load controllers, directives of AngularJS through requireJS.

  • Enjoy the benefits of requireJS on AngularJS

Files Included
  • main.js
    • Centralize all the js loading by one single main js file.

    • Specifying the dependencies of each module when loaded. E.g.: Bootstrap depends on jQuery

  • insiderApp.js
    • To define the Angular main insiderApp module

  • controller.js
    • To define the Angular controller module

  • step0.html
    • The Angular view

Coding

main.js
require.config({
 paths: {
  'jquery' : 'lib/jquery.min',
  'bootstrap' : 'lib/bootstrap.min',
  'bootstrap_select' : 'lib/bootstrap-select',
  'stepOne' : 'core/stepOne',
  'angular' : 'lib/angular',
  'angular-animate' : 'lib/angular-animate',
  'angular-route' : 'lib/angular-route',
  'controller' : 'controllers/controller'
 },
 
 //we do not add AMD-compliant script here!!
 shim: {
  "bootstrap" : { "deps" : ['jquery'] },
  'bootstrap_select' : { "deps" : ['jquery', 'bootstrap'] },
  'stepOne' :  { "deps" : ['jquery','bootstrap_select'] },
  'angular' : {
   exports : 'angular'
  },
  'angular-animate' : {
   "deps" : ['angular'],
   exports : 'angular-animate'
  },
  'angular-route' : { 
   "deps" : ['angular'],
   exports : 'angular-route'
  },
 },
 //for debug
 urlArgs: "bust=" + (new Date()).getTime() 
});


require(["jquery", "bootstrap", "bootstrap_select", "stepOne", "insiderApp", "angular", "controller"], function() {
 //requirejs sugar function >> Avoid putting all modules to the parameters
 var angular = require('angular')

 var csArr = ["/css/bootstrap-select.min.css", "/css/bootstrap.min.css", "/css/psliteM.css"];
 
 //manually start over insiderApp for angularJS, no need to put ng-app in html file
 angular.bootstrap(document,["insiderApp"]);
});
insiderApp.js
define(["angular", "angular-route", "angular-animate"],function(angular){
 var insiderApp = angular.module("insiderApp",["ngRoute", "ngAnimate"]);
 //routing
 insiderApp.config(['$routeProvider','$locationProvider',function($scope,$routeProvider,$locationProvider){
  
 }]);
 
 return insiderApp;
});

controller.js
//controller
define(['insiderApp'],function(insiderApp){
 insiderApp.controller('insiderControl', ['$scope', function($scope){
  //store all the required images path here
  $scope.menuImages = [
                     {
                      lm : './images/info.png',
                      width : '200px', 
                     },
                     {
                      mid : './images/setting.png',
                      width : '200px',
                     },
                     {
                      rm : './images/tv.png',
                      width : '200px',
                     },
                    ];
 }]);
});
step0.html







Smart Moment (Menu)


 
 
 




Points to Note
  • main.js
    • Some tutorials will use require.config and we may also have requirejs.config, they are basically the same

    • Requirejs object is used to setup 
      • Dependencies of different modules
        • Remember only non-AMD script is allowed to put in the deps parameters for dependency loading.

      • Module exports as global variables for use of other modules

      • Define the exact path of the js files

    • require(["jquery", "bootstrap", "bootstrap_select", "stepOne", "insiderApp", "angular", "controller"]....
      • jquery, bootstrap etc. is the self-defined name of js scripts to load, they are loaded in order

      • We must load the controller module for the AngularJS controller to work properly

    • Inside require function we have a second require function,which is called sugar function, it only loads the required modules for use inside the function, if you don't need it, you are NOT required to include in function parameters.

    • angular.bootstrap is to manually trigger the start of angularJS, which is highly recommended to use when cooperate with requireJS
      • When this was set, NO exists in the html view or AngularJS will throw errors

  • insiderApp.js
    • define(["angular", "angular-route", "angular-animate"],function(angular){
      • Normally, we will ignore the first parameter of the define function and let requireJS to use the file name as the module name (recommended)

      • Second array parameter tells requireJS that insiderApp module requires angular, angular-route and angular-animate to be loaded before executing the insiderApp module

      • function parameter "angular" is returned by the angular function, this object is for the implementation of insiderApp

      • Return the insiderApp variable or not depends on whether or not other modules need insiderApp, normally you need to return it.

      • var insiderApp = angular.module("insiderApp",["ngRoute", "ngAnimate"]);
        Just like usual, start the angular module, we can do any configuration of the angular object in this file.

  • controller.js
    • Just like usual, controller of the Angular object

    • define(['insiderApp'],function(insiderApp)...
      • Controller rely on insiderApp for adding controller to the Angular module, so we need to put insiderApp to the array and use it inside the function

    • insiderApp.controller('insiderControl', ['$scope', function($scope){...
      • Do all the work of Angular controller as usual

  • step0.html
    • Main view

    • NO here as we have already bootstrapped it manually in main.js

Others
  •   How to determine whether a module is AMD-compatibile module
    • Check the source code to see whether it has keyword like "define", "require"

References
  1. http://segmentfault.com/blog/moejser/1190000000492238 
  2. http://camnpr.com/archives/1563.html
  3. http://tech.pro/blog/1561/five-helpful-tips-when-using-requirejs
  4. http://stackoverflow.com/questions/17366073/requirejs-define-vs-require
  5. http://kielczewski.eu/2013/04/integrating-angularjs-with-requirejs/
  6. http://stackoverflow.com/questions/14619239/require-js-shim-not-working-for-this-code

2015年1月14日 星期三

[AngularJS] Basic Concepts

Here are the basic concepts of Angularjs, these concepts are barely well documented by the officials.

  1. angular.config only accepts providers
  2. Every service and factory are the instances of the providers

    e.g.
    angular.module('myApp')
      .service('FooService', function(){
        //...etc
      })
      .config(function(FooServiceProvider){
        //...etc
      });
    
    
    
    Reference: http://stackoverflow.com/questions/17485900/injecting-dependencies-in-config-modules-angularjs

2015年1月13日 星期二

[Openwrt] Secure Your uhttpd Server

Sometimes you will need some http authentication for the uhttpd server, if it is so, we can follow the below steps to achieve.

  1. Set up the uhttpd config file
     
    config uhttpd 'main'
            list listen_http '0.0.0.0:80' 
            list listen_http '[::]:80'
            list listen_https '0.0.0.0:443'
            list listen_https '[::]:443'
            list interpreter '.php=/usr/bin/php-cgi'
            /*Use php as interpreter, add it if you want to load php correctly*/
            option home '/www'
            /*Actual web file is placed in this folder*/
            option rfc1918_filter '1'
            option max_requests '3'
            option max_connections '100'
            option cert '/etc/uhttpd.crt'
            option key '/etc/uhttpd.key'
            option cgi_prefix '/cgi-bin'
            option script_timeout '60'
            option network_timeout '30'
            option http_keepalive '20'
            option tcp_keepalive '1'
            option ubus_prefix '/ubus'
            option listen_http '8080'
            /*listen to http 8080, you can make your own listening port*/
            option config '/etc/httpd.conf'
            /*Specify the config for username and password for http auth*/
    

  2. Make a file called "httpd.conf" under /etc directory

  3. Modify the file with the following, basically, the first parameter is the directory you want to protect
    /:username:password
Reference:http://wiki.openwrt.org/doc/uci/uhttpd#basic.authentication.httpd.conf

2015年1月12日 星期一

[jQuery] Datatable: Some Hints

Be careful when using datatables, the following should take into account

  1. If you try to do some column visible/invisible work, you need to clear cookies to take effect or you may not see any differences
     
    $('#example').dataTable( {
      "columnDefs": [
        { "visible": false, "targets": 0 }
      ]
    } );

    For the above, we specify the column 0 to be invisible, but when I refresh my page, I cannot see anything, we need to clear the cookies to achieve the changes, the only reason for this I guess would be the bState parameter which use the cookie to save the sorting history and other datatable profiles.

    ***And usually you may need to restart the chrome browser with the private mode to reflect the changes***

I will update this doc if any new hints of datatables found.

2015年1月7日 星期三

[Ubuntu] Installing Symantec Endpoint Protection for Linux (SEPFL)

Although there is only a very few chance for us to install SEP in Ubuntu, but I have chance to do this, so I share my experience here.

Steps
SEPFL does not support 32 bit Ubuntu, therefore you may need to recompile the auto protection module.
  • Decompress the source code from the following directory
    ./yourSEPFLFileDir/src/ap-kernelmodule.tar.bz2
  • Recompile the Symantec Endpoint to support 32 bit Ubuntu
    sudo ./build.sh --kernel-dir /lib/modules/$(uname -r)/build
  • Once success, the auto protection of SEPFL should work as follows
References

[Apache] Overriding .htacess Files in Server

Sometimes, we may want to control the download behavior  through http server, in this case, we often need to override the htaccess config file to achieve.


Scenario 1: No authentication is needed
1) Make .htacess file with the below content
  
   
     Allow from all
     Satisfy any
   

2) After that, put the file to the directory, the following is the result (hierarchy level)

downFolder
     yourFileName
    .htacess 

So everytime the user download the file, they will not be asked for password


Scenario 2: Authentication with Username and Password

1) Make .htacess file with the below content
  
    AuthType Basic
    AuthName "yourProtectedMsg"
    AuthUserFile pathOfYourHtapasswdFile
    Require user loginUsrName
  

2) After that, make a .htpasswd file from the following URL
http://www.htaccesstools.com/htpasswd-generator/

3) Put .htacess, .htpasswd file to the same directory as your file
downFolder
     yourFileName
    .htacess 
    .htpasswd

So everytime the user download the file, they will be asked for password

2015年1月6日 星期二

[CMD] List of Common Commands Used in APs

This post will mark down all the necessary or common commands which often use and always forget.

  1. wifi detect > wireless
    • Generate the default config

This post will keep up-to-date.

2015年1月5日 星期一

[Steam] Streaming Games in Windows using VPN

Steam contains a very good feature called "Steam In-Home Streaming" which allow streaming of PC games in LAN or even through the Internet using VPN, with this feature one can use the strong desktop power to stream to other machines with different platform like MAC and Ubuntu, with the help of Steam software.


Environment
  • Windows 7 64 bit Ultimate Edition / MAC OS/ Ubuntu
  • A strong processing power PC (Steam suggest Intel Core i3 or above for the host computer for better performances)
  • OpenVPN (ASUS routers internally includes openVPN servers), do not use PPTP server inside the router as this will not work (reason: PPTP has no UDP port forwarding)
  • OpenVPN client URL: http://openvpn.net/index.php/open-source/downloads.html
Steps
  1. Set up VPN server (in my case, I use openVPN server provided by merlin build), turn on it.


  2. Select advance settings, follow the below settings
    * Remember to select "TAP", for steam steaming to work, bridging is required.
    * Username auth and password should be enabled
    * Allow connections between clients

  3. Make a new open vpn account in the top page (not in the advance set up page!)

  4. Export the settings (.ovpn)


  5. Import the ovpn file to the client openVPN located in C:\Program Files\OpenVPN\config and do the connection.



  6. Back to application, both side should have Steam opened, and make sure they are at the same LAN, you should have an option to stream your game.

2015年1月4日 星期日

[Windows] Hide User Account from the Home Screen

Sometimes, we open a new account for special purposes but do not want to the account to be shown at home screen, if it is so, please follow the below steps to achieve.

Environment:
Windows 7 (64 bit) Ultimate Edition


1) Go to start

2) Type Regedit

3) Navigate to
HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\Winlogon

4) Right click "Winlogon" and make a new key (K)

5)  Name "SpecialAccounts" and press enter

6) Right click the newly created SpecialAccounts, make a new key again named "UserList"

7) On the RHS of the panel, add a DWORD (32bit) value, name the value with the account name you want to hide.

8) The value of the DWORD is evaluated as follows
0: Hide 
1: Show

9) You do not need to restart computer, this will be in effect instantly.


Finally result



Reference: https://social.technet.microsoft.com/Forums/windows/en-US/16378967-8a39-4aef-85e4-d859a71648d3/hide-user-accounts-on-windows-7-logon

2015年1月2日 星期五

[Windows] Setting Up Remote Login in Windows 7

The following is the some notes of setting up remote login for machines behind routers (NAT)

Environment:

  1. Windows 7 (64 bit) Ultimate Edition
  2. Asus N66U router
  • Setup port forwarding (default 3389 port)

  • Under Windows "Firewall > Advanced setup, choose inbound connection, open tcp port 3389 to allow remote login services


  • Finally, go to Advanced system settings > remote > allow all remote connections from different versions of Windows (default is closed for security, need to open manually)

2015年1月1日 星期四

[Windows] Solve Microsoft Visual C++ 2005 Redistribute 1935 Error

When installing Microsoft Visual C++ 2005 getting the 1935 error, follow the below instructions to solve the issue.

Error message
"Setup failed to install Microsoft Visual C++ 2005 Redistributable..."
To resolve the issue, you tried to install Microsoft Visual C++ 2005 Redistributable, but you get the following error message:
"Error 1935. An error occurred during the installation of assembly 'Microsoft.VC80.ATL..."M

Steps to solve
1) Start terminal with admin privelege

2) Run the following cmd'
fsutil resource setautoreset true C:\
3) Restart the machine


Reference: http://esupport.trendmicro.com/solution/en-US/1059423.aspx

Windows sucks,right?