Eric Guo's blog.cloud-mes.com

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Reinstall Macbook 2016 With MacOS 10.14.4

• Permalink

Two years after running MacOS 10.12.6, I decide to switch to a new job so have to re-install my MBP to 10.14.4 to make sure nothing left in my old computer.

Here is the list of application/software/tools currently heavy use:

MacStore apps:

MacStore apps:
Evernote
Xcode
QQ
Wechat
Aware
Pages
Numbers
Keynote
iMovie
Elmedia Video Player
Pixelmator
PDF Export
Squash
Affinity Designer
Youku
Drop - Color Picker
Polarr Photo Editor Pro
Mate
腾讯视频
Telegram Desktop
Tweetbot 2
AdGuard for Safari

Install tools via brew

Install tools via brew
brew install ansible
brew install bash
brew install elasticsearch
brew install eslint
brew install go
brew install hub
brew install jenv
brew install jq
brew install memcached
brew install mtr
brew install node
brew install overmind
brew install p7zip
brew install pandoc
brew install percona-server
brew install postgresql
brew install prettier
brew install proxychains-ng
brew install puma-dev
brew install redis
brew install ruby
brew install sqlite
brew install sshuttle
brew install unrar
brew install vim
brew install yamllint
brew install yarn

Install tools via brew cask

Install tools via brew cask
brew cask install adoptopenjdk8
brew cask install airserver
brew cask install anaconda
brew cask install chromedriver
brew cask install data-integration
brew cask install firefox
brew cask install google-chrome
brew cask install googleappengine
brew cask install java
brew cask install paw
brew cask install rubymine
brew cask install sourcetree
brew cask install sublime-text-dev
brew cask install surge
brew cask install typora
brew cask install viscosity
brew cask install zoomus

Install from web / download:

Install from web / download:
Excel
PowerPoint
Word
Remote Desktop Connection
SQLPro Studio
微信开发者工具
百度网盘

Append below lines to .bash_profile to activate conda.

Initialize Conda in .bash_profile
source /usr/local/anaconda3/etc/profile.d/conda.sh
conda activate

New brew relay on CommandLineTools, acturally there is no need and node need xcode existing, so run below to fix.

Reinstall Macbook 2016 with MacOS 10.14.4
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/

Some gem need special handle

Install gems that need special build options
gem install libxml-ruby -v '3.1.0' -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2
gem install nokogiri -v '1.10.2' -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

Deploy Another Rails App in the Same CentOS Server

• Permalink

Assure the first Rails app is running as user deployer and second as user scschub.

Setup second user account

Setup second user account
adduser scschub
gpasswd -a scschub wheel
visudo # add scschub ALL=(ALL) NOPASSWD: ALL at end
sudo su - scschub
mkdir .ssh
chmod 700 .ssh

Install rbenv and ruby-build

Install rbenv and ruby-build
cd # as a deployer
git clone https://github.com/rbenv/rbenv .rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~/.rbenv/bin/rbenv init
# As an rbenv plugin
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
git clone https://github.com/andorchen/rbenv-china-mirror.git "$(rbenv root)"/plugins/rbenv-china-mirror

Install Ruby 2.7.1

Install Ruby 2.7.1
rbenv install -l
rbenv install 2.7.1
rbenv global 2.7.1
rbenv shell 2.7.1
eval "$(rbenv init -)" >> ~/.bash_profile
echo "gem: --no-document" > ~/.gemrc
gem install bundler --default -v "1.17.3"
gem install bundler

Fix permission for CentOS

Fix permission for CentOS
sudo mkdir /var/www
cd /var/www
sudo mkdir scschub
sudo chown scschub:scschub scschub/

Copy puma config.rb and other shared link files

Copy puma config.rb and other shared link files
cap production puma:config

Create mysql DB

Create mysql DB
CREATE USER 'cybros_staging'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE cybros_staging character set UTF8mb4 collate utf8mb4_bin;
GRANT ALL PRIVILEGES ON cybros_staging.* to 'cybros_staging'@'localhost';
FLUSH PRIVILEGES;

Create postgresql role

Create postgresql role
sudo su - postgres
createuser scschub --pwprompt
psql
ALTER ROLE scschub LOGIN
CREATE ROLE sccsa_users;
GRANT sccsa_users TO deployer;
GRANT sccsa_users TO scschub;
ALTER ROLE deployer INHERIT;
ALTER ROLE scschub INHERIT;

Allow both user can access the same data.

Transfer ownership of shared PostgreSQL tables
psql -d sccsa_production
ALTER TABLE wechat_sessions OWNER TO sccsa_users;
ALTER TABLE schema_migrations OWNER TO sccsa_users;
ALTER TABLE ar_internal_metadata OWNER TO sccsa_users;
ALTER TABLE active_storage_attachments OWNER TO sccsa_users;
ALTER TABLE active_storage_blobs OWNER TO sccsa_users;
ALTER TABLE active_storage_variant_records OWNER TO sccsa_users;
ALTER SEQUENCE wechat_sessions_id_seq OWNER TO sccsa_users;

SQL which may help to build above ALTER faster.

Generate PostgreSQL ALTER TABLE ownership statements
SELECT 'ALTER TABLE '||table_name||' OWNER TO sccsa_users;'
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;
SELECT 'ALTER SEQUENCE '||sequence_name||' OWNER TO sccsa_users;'
FROM information_schema."sequences"
WHERE sequence_schema = 'public';
ORDER BY sequence_name;

Further reference.

How to Resolve Safari Download Filename Not Support Chinese

• Permalink

Found from stackoverflow, which I think should including in send_data acturally....

Set a UTF-8 attachment filename for Safari downloads
def make_and_send_pdf(pdf_name, options = {})
options = { :disposition => 'attachment' }.merge(options)
file_name = "#{pdf_name}.pdf"
send_data(
make_pdf(options),
filename: ERB::Util.url_encode(file_name),
type: 'application/pdf',
disposition: "#{options[:disposition]}; filename*= UTF-8''#{ERB::Util.url_encode(file_name)}"
)
end

Rbenv and CentOS Ruby on Rails Production Environment Install Log

• Permalink

Original refer, install on a Aliyun server.

Install software in root account

Update system

Run as root:

Update system
yum update
yum install -y htop git git-lfs zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
reboot

Setup a user account

Setup a user account
adduser deployer
gpasswd -a deployer wheel
visudo # add deployer ALL=(ALL) NOPASSWD: ALL at end
sudo su - deployer
mkdir .ssh
chmod 700 .ssh

Also disable root login and password via PermitRootLogin in /etc/ssh/sshd_config

Before exis, make sure you can login via ssh deployer@ip_address, other wise, check file permission.

Install rbenv and ruby-build

Install rbenv and ruby-build
cd # as a deployer
git clone git://github.com/sstephenson/rbenv.git .rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~/.rbenv/bin/rbenv init
# As an rbenv plugin
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
git clone https://github.com/andorchen/rbenv-china-mirror.git "$(rbenv root)"/plugins/rbenv-china-mirror

Install Ruby 2.6.5

Install Ruby 2.6.5
rbenv install -l
rbenv install 2.6.5
rbenv global 2.6.5
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
echo "gem: --no-document" > ~/.gemrc
gem install bundler

Install Javascript Runtime

Run as root:

Install Javascript Runtime
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
sudo yum install nodejs
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install yarn

Install postgresql

Install and initialize PostgreSQL
sudo yum install postgresql-server postgresql-contrib postgresql-devel
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo chkconfig postgresql on
Create the PostgreSQL application role and database
sudo su - postgres
createuser deployer --pwprompt
psql
ALTER ROLE deployer LOGIN
CREATE DATABASE harman_vendor_production WITH ENCODING='UTF8' OWNER=deployer
/var/lib/pgsql/data/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all peer
Connect to the PostgreSQL application database
psql -d harman_vendor_production

Install nginx

Install nginx
sudo yum install epel-release
sudo yum install nginx

Fix permission for CentOS

Fix permission for CentOS
sudo mkdir /var/www
cd /var/www
sudo mkdir jbl_product
sudo chown deployer:deployer jbl_product/

or further read nginx permission denied

Deploy Simple Rails App to CentOS 7.4 on Aliyun in 2018

• Permalink

It's 2018, docker quite mature, but since we can buy a server less than 600 RMB in Aliyun including 40Gb storage, 1MB network, 1 core CPU and 2G memory, so I still want to install it in the triditional way.

Install software in root account

Update system

Update system
yum update
yum install htop
yum install git
reboot

Install RVM

Resolve can not import from hkp://keys.gnupg.net

In a server which can running below cmd:

Export the RVM signing keys from a reachable server
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg --export --armor D39DC0E3
gpg --export --armor 39499BDB

In Aliyun server:

Import the RVM signing keys on Aliyun
gpg --import -

and copy and paste the can run server public key content and press Ctrl+D

Install RVM

Install RVM
\curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
logout

Update RVM to master

Update RVM to master
rvm get master
rvm list known # should see ruby 2.5

Install Ruby 2.5

Install Ruby 2.5
rvm install ruby-2.5
echo "gem: --no-document" >> /etc/gemrc
echo "gem: --no-document" >> ~/.gemrc

Install node.js

Install node.js
yum install nodejs
node --version # v6.12.3

Install yarn

Install yarn
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install yarn

Install nginx

Install nginx
yum install nginx
sudo chkconfig nginx on

Normal user

Create new user - harman

Create new user - harman
adduser --home-dir /data/www/harman harman -g rvm

Copy authorized_keys

Copy authorized_keys
mkdir /data/www/harman/.ssh
sudo cp ~/.ssh/authorized_keys /data/www/harman/.ssh/
sudo chown harman:rvm /data/www/harman/.ssh/

Do capistrano deploy

Change nginx

Modify nginx

Add below to http section and comment out default server section.

Configure Nginx logging and the default server
http {
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time $pipe';
access_log /var/log/nginx/access.log timed_combined;
}

Create /etc/nginx/conf.d/harman.conf

Create the Nginx upstream and virtual host
upstream harman_web {
server unix:/data/www/harman/shared/tmp/unicorn.socket fail_timeout=0;
keepalive 3;
}
server {
listen 80 default_server;
# server_name harman.bayekeji.com;
location /nginx_status {
allow 127.0.0.1;
deny all;
stub_status on;
}
root /data/www/harman/current/public;
access_log /data/www/harman/shared/log/harman-access.log timed_combined buffer=1k;
error_log /data/www/harman/shared/log/harman-error.log;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
location ~ (/assets|/uploads|/system|/favicon.ico|/*.txt) {
access_log off;
expires 14d;
gzip_static on;
add_header Cache-Control public;
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://harman_web;
gzip on;
}
}

Chart Number and Calculation Logic Explanation for OpenApply

• Permalink

I plan to rewrite the OpenApply all the chart, so need list the calculation logic as below first.

Dashboard

The dashboard provides a quick overview of most common key number for the school.

Enquiries

Enquiries provide a month by month overview for inquiry and it's submitted applicant forms number.

Monthly inquiry students define as the new students created at that month.

Monthly conversion students define as the student who submits the application form that month.

So normally, such gap between inquiries and conversion should not very large, otherwise, it's indicate maybe your application form is too complex and many students don't finish it.

Applicants

Applicants will list the students' number per day, the students is the one who was being marked at the applied status in that day, the mark effective date can be different with actually the marking day.

Applicants date range always starts at Month Day 1.

The applicants number is based on student status history effective on date.

Enrolment

Enrolment chart will display the count number of enrolled student per that month. The enrolled day is students status histories enrolled record effective on date.

Re-Enrolment

Re-enrolment help you manage the re-enrolment student status. there is 3 status which will be recorded in student reenrolment status.

Pending means email already sent, but student no response. Confirmed means student confirm the re-enrolment for your select academic year. Declined means student read the email but decide not continue attending the school at the select academic year.

If the student is eligible to attend the select academic year, but no student reenrolment status record, it will belong to Not sent.

Analytics

Enquiry

Based on filter condition, to analyze the company, nationality by reference source or grade distribution.

The time range always the academic year.

Conversion Funnel

Conversion Funnel focus on the enroll perspective.

The left part is the drop down student status for the select academic year, the Pending number is 100% percent, then all other status is based on that percent.

In demo side, as the enrolled student in 25%, which means only 1/4 student can be enrolled amount all inquiry student.

Center part pie chat compare the declined and enrolled students for that year.

Right small pie chat display sub status for select status students, if the school does not configure their own sub-status, it will leave blank.

Enrolment

This part no chart, so intentionally leave blank.

Checklist

The checklist will give an overview of checklist status per academic year and per program.

Pending means those students not complete the checklist item. Partial means those students have already filled the forms, but not submit yet. Complete means those students finish such checklist item.

Click any part of rectangle box will display detail students in such status in the checklist item.

You can filter to analyze students as the checklist completion data source.

Geography

It will analyze the student country, if the student country is blank, will take parents country instead.

Nationality

It will analyze the student's nationality.

Languages

It will analyze the student's language.

Pow Used .dev Will Be Redirect to Https by Google Chrome

• Permalink

After Chrome 63 released, Google makes the decision to redirect .dev to https direct as they buy the domain TLD.

So if you using pow as well like me, you need to add below line to ~/.profile:

Set Pow domains to localhost
export POW_DOMAINS=localhost

And running below command and restart pow.

Restart Pow with the localhost resolver
cd /etc/resolver/
sudo mv dev localhost
launchctl unload -w ~/Library/LaunchAgents/cx.pow.powd.plist
sudo launchctl unload -w /Library/LaunchDaemons/cx.pow.firewall.plist
sudo pow --install-system
pow --install-local
sudo launchctl load -w /Library/LaunchDaemons/cx.pow.firewall.plist
launchctl load -w ~/Library/LaunchAgents/cx.pow.powd.plist

So you can continue using http://faria.oa.localhost/ to access your local rails projects.