9/07/2019

How to install Node.js on Ubuntu

Installing the Distro-Stable Version for Ubuntu

  • sudo apt update
  • sudo apt install nodejs
  • sudo apt install npm
  • nodejs -v


How to Install Latest Node.js and NPM on Ubuntu with PPA
  • sudo apt-get install curl
  • curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
  • sudo apt-get install nodejs
  • node -v
  • npm -v

7/03/2019

How to install Node.js on CentOS 7

Solution : https://www.e2enetworks.com/help/knowledge-base/how-to-install-node-js-and-npm-on-centos/#

# yum install -y gcc-c++ make
# curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
 
# yum install nodejs 

# node -v 
 
# vim test_server.js 
 
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Welcome');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');
 
 
# node --debug test_server.js 
 
 
How to upgrade node.js
https://tecadmin.net/upgrade-nodejs-via-npm/ 
 
How to install npx
https://stackoverflow.com/questions/49894620/npx-command-not-working 
 

CentOS forgot root password

Solution: https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/

Steps:

1. Boot -> on boot selection screen enter "e" to enter editor
2. Find the line contains ro.
3. Change ro to rw init=/sysroot/bin/sh
4. press Ctrl-X, and wait for a while.  It will enter single user mode
5. chroot /sysroot
6. touch /.autorelabel
6. passwd root

6/23/2019

重拾 Android - 開始 - Hello World!

大約四五年前, 幫公司硬寫了個 Mobile App, 當時是強力拼湊出來的, 很多 Detail 也沒有仔細研究. 時隔多年, 最近又有 Project 需要 Mobile App. 正好重新開始, 這次打算把他研究徹底.

先到官網 https://developer.android.com/

下載必要的工具 Android Studio, https://developer.android.com/studio

安裝之後, 跟著網站的 Tutorial, https://developer.android.com/training/basics/firstapp/

即可成功的 Build 第一個 App 出來.

目前我的手機是 Google Pixel 2, 必須要設定 Connected devices > USB > Use USB for File Transfer.

這樣第一個 App 就可以在手機上 Run 了.

5/21/2019

Windows Server 2016 Dashboard cannot refresh to get status


Problem:Installed Windows 2016 Server, but on the management dashboard always refresh fail. It shows "Missing Performance Counters from Server Manager"
Solution:Fixing Missing Performance Counters from Server Manager

3/12/2019

Kendo UI Grid date display issue


Problem:If you have a Date field shown on the grid, the display time will be variant based on the client's browser.
Reference:Use UTC on Both Client and Server
Real Case:Our Web Server and DB server are in timezone GMT-8 when we save a Date/Time into a field, the date/time displayed on the client side in timezone GMT-8 has no problem.  But the user in timezone GMT-5, the time will be added 3 hours.
For example, we can see the data saved in the server is 12/11/2018 17:12, the display in LAX has no problem.  But the display in JFK, it will be 12/11/2018 20:12.
Solution:
<script type="text/javascript">
        var onRequestEnd = function(e) {
            if (e.response.Data && e.response.Data.length) {
                var data = e.response.Data;
                if (this.group().length && e.type == "read") {
                    handleGroups(data);
                } else {
                    loopRecords(data);
                }
            }
        }

        function handleGroups(groups) {
            for (var i = 0; i < groups.length; i++) {
                var gr = groups[i];
                offsetDateFields(gr); //handle the Key variable as well
                if (gr.HasSubgroups) {
                    handleGroups(gr.Items)
                } else {
                    loopRecords(gr.Items);
                }
            }
        }

        function loopRecords(persons) {
            for (var i = 0; i < persons.length; i++) {
                var person = persons[i];
                offsetDateFields(person);
            }
        }

        function UTCToLocal(utcDate) {
            var offset = new Date().getTimezoneOffset() / 60;
            var date = new Date(utcDate);
            var hours = date.getHours();
            date.setHours(hours - offset);
            return date;
        }

        function offsetDateFields(obj) {
            for (var name in obj) {
                var prop = obj[name];
                if (typeof (prop) === "string" && prop.indexOf("/Date(") == 0) {
                    obj[name] = prop.replace(/-?\d+/, function (n) {
                        var offsetMiliseconds = (new Date(parseInt(n)).getTimezoneOffset()-8*60) * 60000;
                        return parseInt(n) + offsetMiliseconds
                    });
                }
            }
        }
    </script>