2015年11月15日 星期日

Java 8 - centos 7

Switch Java version by default: alternatives --config java

Installation script:

2015年10月22日 星期四

Linux command tips

Logout all users: pkill -u username

SSH port forwards: ssh -L port:127.0.0.1:port -lAccount -N RemoteIP

add text at the end of each line in unix : awk '$0=$0" | --recursive"'

2015年10月4日 星期日

Mac command line


  • Check mac version: sw_vers -productVersion 
  • Change HostName: sudo scutil --set HostName nameyouwant
  • Change hostname: sudo hostname mbpr
  • To start an application from command line, TeamViewer for example:
       > open -g -a /Applications/TeamViewer.app
  • To gracefully quit instead of kill-ing:
      > osascript -e 'quit app "TeamViewer.app"'

  • Open multiple VLC
    /Applications/VLC.app/Contents/MacOS/VLC
  • Restart from terminal: 
    • sudo shutdown -r now 
    • sudo shutdown -h +5 

With details on hiding given by: https://support.apple.com/en-au/ht203998
pwpolicy can both disable and enable users, without losing their password
To disable the user
pwpolicy -u username disableuser
To enable the user
pwpolicy -u username enableuser
Use dscl to hide the user so they don't show on login:
sudo dscl . create /Users/username IsHidden 1 
To show a hidden user
sudo dscl . create /Users/username IsHidden 0 

2015年10月2日 星期五

Brew tip

Official site: http://brew.sh/

Brew Installation:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Java:
brew tap caskroom/cask
brew install brew-cask
brew cask install java

Install wget:
brew install wget

Install unrar:
brew install unrar

Install Ruby:

Install php mcrypt:
brew install homebrew/php/php56-mcrypt

Search php module:
brew search php | grep mcrypt

Install Pillow:
brew install libtiff libjpeg webp little-cms2

pip install Pillow


2015年9月16日 星期三

send email using gmail - python

Python example:
If got an SMTP Authentication Error. go to https://www.google.com/settings/security/lesssecureapps and enable the access for less secure apps.

If still got the error, check google account to see if that computer is been blocked by google. https://myaccount.google.com/security#activity


2015年9月12日 星期六

Git tips

Syncing a fork:
Sync a fork of a repository to keep it up-to-date with the upstream repository.
  1. git fetch upstream
  2. git checkout master
  3. git merge upstream/master
  4. git push origin master 
  5. git checkout home (home is a branch)
  6. git rebase master
  7. git push origin home
ref: https://help.github.com/articles/syncing-a-fork/


Sync branch:
git fetch --prune

Update a PR:
  1. git reset --hard  (optional)
    Did my changes in code I wanted to do
  2. git add
  3. git commit --amend
  4. git push -f origin 
Cache the password in Git:
git config --global credential.helper cache

ref: https://help.github.com/articles/caching-your-github-password-in-git/#platform-linux

Create a new branch:
git checkout -b office master

Count:
git rev-list --count HEAD --since="March 20 2020"              
git rev-list --count HEAD --since="February 20 2020" --before="March 20 2020"

Create alias:
git config --global alias.co checkout
git config --global alias.st status

Move file to untracked file:

git rm welcome.html --cached

Finish and delete branch:
  1. git branch -D fcrepo-xxxx
  2. git push origin :fcrepo-xxxx
Pull a PR:

  1. Get the PR changes into the test branch:> git fetch origin pull/1485/head:test
  2. Create a test branch to merge the PR into locally. Assuming you're on the master branch:
    > git checkout test
Change the URI (URL) for a remote Git repository

git remote set-url origin NEWURL

Show remote URI 

git config --get remote.origin.url

Delete all commit history
  1. Checkout
    git checkout --orphan latest_branch
  2. Add all the files
    git add -A
  3. Commit the changes
    git commit -am "commit message"
  4. Delete the branch
    git branch -D master
  5. Rename the current branch to master
    git branch -m master
  6. Finally, force update your repository
    git push -f origin master
Show watchers and stargazers URI 
  • https://github.com/[user]/[repo]/watchers
  • https://github.com/[user]/[repo]/stargazers
Search the latest commit
  • git log --graph --all --format=format:'%h - (%ai) %s — %cn %d' --abbrev-commit --date=relative -1

    Output: 6080b81 - (2017-11-14 21:41:39 +0000) run characterization on ingested file — Name  (branch name)
  • 6080b81 is the commit #
Find branch name by commit #
  • git branch --all --contains  6080b81
Sync a branch with master

  1. git checkout test
  2. git rebase master
  3. git push origin +test

Your branch is based on 'origin/master', but the upstream is gone.

  1. git remote add origin giturl
  2. git push -u origin master
.gitignore template: https://github.com/github/gitignore
Remove previous gitignore files:
git clean -fX

Delete a branch
git branch -D dev
git push origin :dev

Rename a branch
git branch -m old_branch new_branch         # Rename branch locally 
git push origin :old_branch                 # Delete the old branch 
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote

Squash commit:

$ git rebase -i HEAD~4
or
$ git rebase -i 97c9d7d
1 r 01cc5a08 Removes open div
2 s a2b6eecf Restores old fonts
3 s 603479ff Cleans left out div

$ git push origin branch-name --force

# Edit last commit message, before pushing, by using
$ git commit --amend

Cheatsheet: https://gist.github.com/davfre/8313299


Project management

MindTheProduct is a community blog that covers a lot of the processes that product managers use as part of their job.

Experimentation 101 http://www.mindtheproduct.com/2012/08/experiments-101/
Agile Roadmapping http://www.mindtheproduct.com/2012/08/agile-roadmapping/
Product Prioritisation http://www.mindtheproduct.com/2012/06/product-prioritisation-101/

2015年8月29日 星期六

Run Commands Remotely via SSH with No Password

1. Generate SSH key pair: ssh-keygen -t rsa
you will get a id_rsa.pub file in .ssh/


2. add content in id_rsa.pub to remote server .ssh/authorized_keys file

2015年8月25日 星期二

Docker tips

Installation:
  • Mac: https://docs.docker.com/installation/mac/
  • Ubuntu: curl -sSL https://get.docker.com/ubuntu/ | sudo sh 
  • Linux: wget -qO- https://get.docker.com/ | sudo sh
  • CentOS: 
    • sudo tee /etc/yum.repos.d/docker.repo <<- span="">'EOF' [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF
    • sudo yum install docker-engine
    • sudo service docker start
CA not find error:
> unset ${!DOCKER*}

Start/Stop docker service: service docker start/stop

Build image: docker build -t="test:latest" .
List images: docker images
Run a command in a new container:

  • docker run -it -p 8888:8080 -d test:latest
  • docker run -it --rm -p 8888:8080 test:latest
  • docker run -w /ICADL icadl:latest bash -c "python dockertest.py"

List containers: docker ps
Connect to running docker container: docker exec -i -t "IMAGE ID" /bin/bash
Stop containers: docker stop $(docker ps -a -q)

Remove image: docker rmi "IMAGE ID"
Remove containers: docker rm $(docker ps -a -q)
Removing all unused docker images: docker images -q |xargs docker rmi

Docker hub commands:
Push docker image:
  • docker tag 515ba39974ef test/icadl:version1
  • docker push test/icadl
Recreate default env
  • docker-machine rm default
  • docker-machine create default --driver virtualbox
  • eval $(docker-machine env default)
Show docker-machine ip
  • docker-machine ip
Docker-compose command

  • rebuild image: docker-compose build or docker-compose up --build
  • docker-compose up -d 
  • docker-compose stop 
  • docker-compose rm -f

2015年8月24日 星期一

grep commands

Search within a directory:
  • Show both file and matched string: 
    • grep -R text /home/users/workspace
    • grep -lir text /home/users/workspace 
  • Show only file: grep -Rl text /home/users/workspace
  • Grep and append string: more musiclist.txt | grep ecx | sed -e 's/^/wget /' 
  • Append a string on the every line from the grep result.
    • ls -a | grep "Vol_" | perl -ne 'print "zip $_"'
    • ls -a | grep "rar" | perl -ne 'print "unrar x $_"'
  • Grep than replace string: 
    • grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'
    • grep -rl 'windows' ./ | xargs sed -i 's/windows/linux/g'

2015年8月23日 星期日

Time machine commands

List paths to all of the computer's backups: sudo tmutil listbackups

Delete a backup: sudo tmutil delete "path to the backup file"


2015年8月22日 星期六

IBM Bluemix - Virtual Machines

1. Start virtual machines. Go to dashboard and click run virtual machines

2. Select VM size, create security key, select image, and create your VM group

3. You can see your VMs in the dashboard
4. Click the VM to see the detail of that VM

5. You can scale up and scale down the VM


2015年8月20日 星期四

TACC tips

TACC user guidehttps://portal.tacc.utexas.edu/user-guides

Stampede:
  • Environment:
    • $HOME: 
      • Use the environment variable $HOME to reference your home directory in scripts.
      • Use the "cdh" or "cd" commands to change to $HOME .
    • $WORK:
      • Use the environment variable $WORK to reference this directory in scripts.
      • Use "cdw" to change to $WORK.
    • $SCRATCH
      • Use $SCRATCH to reference this directory in scripts.
      • Use the "cds" command to change to $SCRATCH.
  • Python:
    • load module: module load python, module load hdf5, module load
      matplotlib
  • Submit job:
    • sbatch thescript
  • Check queue:
    • showq -u userid
    • squeue -u userid

2015年8月19日 星期三

Java installation

Java 8 installation:

Ubuntu:
> sudo add-apt-repository ppa:webupd8team/java
> sudo apt-get update
> sudo apt-get install oracle-java8-installer


2015年8月18日 星期二

Virtual Box Tips

CentOS7 installation:
  1. yum install qt
  2. yum install qt-x11.x86_64 
  3. rpm -Uvh VirtualBox-5.0-5.0.2_102096_el7-1.x86_64.rpm

Export VM into file: VBoxManage export win8 --output win8.ova
List VMs: VBoxManage list vms

Port forward:




2015年8月16日 星期日

Apple 常用設定與軟體

MacBook 快速鍵設定
Spaces setup: setup the mouse setting to mouse 4.
Dock setup: Add/Delete icons. Just drag in/out icons.
Dashboard setup: click little i in each widget.
Function key: press fn + F12 for example.
Mac 同程式內不同視窗切換:command-`(1左邊那個符號鍵)
Mac Page Up/Down/Home/End:fn + 上下左右
Safari 上下頁切換: Apple + [ 上一頁,Apple + ] 下一頁
Command+Alt+Esc:Windows Ctrl+Alt+Del
螢幕放大縮小:放大螢幕 Command+option+加號。縮小螢幕 Command+option+減號。

MacBook 好用的軟體:
Chmox: 看.chm檔案的軟體 http://chmox.sourceforge.net/
CoRD: 遠端連線Windows軟體 http://cord.sourceforge.net/
Cyberduck: SFTP http://cyberduck.ch/
DiskAid: 將檔案從電腦傳到 iPhone or Touch http://www.digidna.net/diskaid/
Dvd2onex2: DVD 燒入軟體 http://www.dvd2one.com/ note
HandBrake: 將影片轉成IPhone/Touch 可看的格式 http://handbrake.fr/
iWork: Replace existing com.apple.iWork09.Installer.plist file in Macintosh HD > Library > Preferences with the included plsit. (Or edit the existing com.apple.iWork09.Installer.plist and change InstallMode from "Trial" to "Retail"
Nally: BBS 連線軟體 http://yllan.org/app/Nally/
Paparazz!: 將網頁轉成圖檔 http://derailer.org/paparazzi/
Skitch: 抓圖軟體: https://skitch.com/
Tooble: 將youtube的影片儲存於iPhone & iTouch http://tooble.tv/
Unarchiver: 解壓縮軟體 http://wakaba.c3.cx/s/apps/unarchiver.html
Xee: 很好的看圖軟體http://wakaba.c3.cx/s/apps/xee.html
Fetchy: 下載YouTube影片 https://fetchy.io/

相關文章:
MacUknow:必備軟體 http://www.macuknow.com/essentialapps

MacBook 使用小技巧

1. 將選單列和Dock放在延伸螢幕上,打開"系統偏好設定"裡頭的"顯示器">"排列方式",然後將圖片中紅框所示的白色Bar拖拉過去你要的螢幕上,那麼選單列和Dock就會跑到那個螢幕上。

參考來源:MacUknow

2. 中文繁簡切換: http://www.macuknow.com/node/229 ps. 基本原則選擇 Services -> ChineseTextConverter -> 繁to簡 or 簡to繁

3. 快速建立捷徑:按住 Apple + Alt 然後拖住要建立捷徑的應用程式到你想要的地方。

Install xrdp in Ubuntu 14.04 and CentOS 7 for remote desktop

Ubuntu 14.04:
Prerequisites:
  • Update OS: sudo apt-get update & upgrade -y
  • Install gnome desktop : sudo apt-get install ubuntu-gnome-desktop -y
Install xrdp:

  1. sudo apt-get install xrdp
  2. sudo apt-get install xfce4 -y
  3. echo xfce4-session >~/.xsession
  4. sudo service xrdp restart


CentOS 7:
Prerequisites:
  • Update OS: sudo yum update
  • Install gnome desktop : sudo yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
Install xrdp:
  • Create a repository file: 
    1. vi /etc/yum.repos.d/xrdp.repo
    2. add these content into that file
      [xrdp]
      name=xrdp
      baseurl=http://li.nux.ro/download/nux/dextop/el7/x86_64/
      enabled=1
      gpgcheck=0
    3. yum -y install xrdp tigervnc-server
  • Start xrdp service: systemctl start xrdp.service
  • Enable service at startup: systemctl enable xrdp.service
  • Config firewall: 
    1. firewall-cmd --permanent --zone=public --add-port=3389/tcp
    2. firewall-cmd --reload
  • Configure SELinux:
    1. chcon --type=bin_t /usr/sbin/xrdp
    2. chcon --type=bin_t /usr/sbin/xrdp-sesman
Resume to the same connection:
  1.  sudo vi /etc/xrdp/xrdp.ini
[xrdp1] 
name=sesman-vnc 
lib=libvnc.so 
username=ask 
password=ask 
ip=127.0.0.1 
port=-1  ⇐ change to 5912, so the connect will resume.

2015年8月15日 星期六

Tech/Tool links



Javascripts:
Meteor, the JavaScript App Platform: https://www.meteor.com/

Python:
Flask, a microframework for Python: http://flask.pocoo.org/
Testing frameworks:


Tools:
Upsidedown, make word upside down: http://www.upsidedowntext.com/
VS code: https://code.visualstudio.com/
Business plan: http://leanstack.com/
Diffchecker: https://www.diffchecker.com/diff
XML viewer: http://codebeautify.org/xmlviewer

Programming language tutorials:

Java:

Vision Control System:

Google: