Skip to content

Instantly share code, notes, and snippets.

@andyyou

andyyou/cmd.sh Secret

Last active October 19, 2018 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andyyou/b88d74fc180375b9ede9 to your computer and use it in GitHub Desktop.
Save andyyou/b88d74fc180375b9ede9 to your computer and use it in GitHub Desktop.
Common commands collection
# 1. Create empty branch and copy file from another branch
# 這種方式複製檔案路徑會跟原本的 repository 一樣, 有點不方便
$ git checkout --orphan <branchname>
$ git rm --cached -r .
$ rm -rf *
$ git add .
$ git ci -m 'comment'
$ git checkout <branch_name> path/to/new/file
# 2. Splite a folder or module to another new branch
$ git subtree split --prefix=<your_folder_or_module> -b <branchname>
# Same with above but more concise
$ git subtree split -P <foldername> -b <branchname>
@andyyou
Copy link
Author

andyyou commented Sep 15, 2015

Just push dist to gh-pages

$ git subtree push --prefix dist origin gh-pages

@andyyou
Copy link
Author

andyyou commented Sep 15, 2015

@andyyou
Copy link
Author

andyyou commented Dec 10, 2015

> npm run build-npm
> npm run build-site
> git subtree push --prefix site origin gh-pages
> npm version patch
> npm publish
> git push origin `git subtree split --prefix site master`:gh-pages --force

@andyyou
Copy link
Author

andyyou commented Dec 11, 2015

Install npm from private gitlab

> npm install git+ssh://git@192.168.1.1:andyyou/react-coverflow.git

@andyyou
Copy link
Author

andyyou commented Dec 11, 2015

Delete remote tag and branch

> git push origin :refs/tags/[tagname]
> git push origin :[branch_name]

Pull specific branch

$ git checkout -b serverfix origin/serverfix

@andyyou
Copy link
Author

andyyou commented Dec 23, 2015

只 Merge 單一其他支線的檔案

$ git checkout --patch [branch_name] [filename]

建立空白分支

$ git checkout --orphan <branchname>
$ git rm --cached -r .

stackoverflow

@andyyou
Copy link
Author

andyyou commented Feb 15, 2016

[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p

@andyyou
Copy link
Author

andyyou commented Mar 25, 2016

# vim hex edit
> :%! xxd
# back to normal mode
> :%! xxd -r
  • UTF-8 BOM 0xEF,0xBB,0xBF
  • UTF-16 U+FEFF

@andyyou
Copy link
Author

andyyou commented Mar 25, 2016

Run docker in iTerm2 Details

> eval "$(docker-machine env default)"
# 執行映像檔
> docker run [repository_name]/[image_name]
> docker run docker-whale

# 列出本地的映像檔
> docker images

# 製作映像檔目錄與 Dockerfile 後編譯
> docker build -t [name] [path]
> docker build -t docker-whale .

# 打上標簽
> docker tag 7d9495d03763 andyyou/docker-whale:latest
> docker tog [image_id] [repository_name/account]/[image_name]

# push 前需要登入
> docker login

# push
> docker push andyyou/docker-whale

# 移除映像檔
> docker rmi -f 7d9495d03763
> docker rmi -f andyyou/docker-whale
> docker rmi -f [image_name or image_id]
# 重建
> docker-machine create --driver virtualbox default

[Error checking TLS connection: machine does not exist](docker-machine stop default && docker-machine start default)

# 重開
$ docker-machine stop default && docker-machine start default

# 砍掉重建
$ docker-machine rm default
$ docker-machine create --driver virtualbox default

@andyyou
Copy link
Author

andyyou commented Apr 11, 2016

產 SSL 憑證

> openssl genrsa -out server.key 2048
> openssl req -new -key server.key -out server.csr
> openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

@andyyou
Copy link
Author

andyyou commented May 23, 2016

查版號

$ npm show [library name] version // 顯示某 library 最新版本
$ npm view [library name] versions // 看某 library 所有版本
$ nvm ls
$ nvm ls-remote // 顯示 node 可用版本
$ npm config set init.author.name "andyyou"
$ npm config set init.author.email andyyu0920@gmail.com
$ npm config set init.author.url http://andyyou.github.io
$ npm config set init.license MIT
#  Remote version of package
$ npm view [package] version

# Locally in project
$ npm ls

# Locally in project specify a package name
$ npm ls [lodash] 

# Client global
$ npm ls -g

$ npm ls --depth 0

@andyyou
Copy link
Author

andyyou commented May 23, 2016

# npm 打包
$ npm adduser
$ npm login
$ npm config ls
$ npm version 0.0.2
$ npm version patch
$ npm publish

@andyyou
Copy link
Author

andyyou commented May 26, 2016

npm 更新

# 更新全域
$ npm install -g jshint
# 檢查哪些過期
$ npm outdated -g --depth=0
# 全部更新
$ npm update -g

@andyyou
Copy link
Author

andyyou commented May 26, 2016

Check port

$ netstat -na | grep 8080
$ lsof -i tcp:3000 

@andyyou
Copy link
Author

andyyou commented Jun 1, 2016

osx copy

$ pbcopy < ~/.ssh/id_rsa.pub

@andyyou
Copy link
Author

andyyou commented Jul 6, 2016

Fix could not connect to server: Connection refused

$ rm /usr/local/var/postgres/postmaster.pid

@andyyou
Copy link
Author

andyyou commented Aug 22, 2016

# 備份 MongoDB
$ mongodump --db [name]
$ mongodump --db [name] --collection [name]
$ mongodump --db [name] --collection [name] --out 'path'

# 還原
$ mongorestore --db [name] [/path/file.bson]
$ mongorestore --db [name] [/path/folder]

@andyyou
Copy link
Author

andyyou commented Aug 23, 2016

$ heroku create [app_name]
# Setting buildpacks
$ git push heroku master
$ figaro heroku:set -e production
$ heroku run rails db:migrate
$ heroku run rake assets:precompile
$ heroku pg:reset database

@andyyou
Copy link
Author

andyyou commented Aug 25, 2016

# 安裝 ngrok
$ brew cask install ngrok
# 先記得登入安裝憑證
# 使用
$ ngrok http 8080

@andyyou
Copy link
Author

andyyou commented Oct 9, 2016

New ssh key

$ ssh-keygen -o -a 100 -t ed25519

@andyyou
Copy link
Author

andyyou commented Nov 1, 2016

$ hexo new draft [draft-article-name] # No date necessary
$ hexo publish [draft-article-name]
$ hexo server

$ hexo generate # 產生靜態檔案
$ hexo deploy
$ hexo generate -d # 產完檔案及部署
$ hext deploy -g # 部署之前先產檔

@andyyou
Copy link
Author

andyyou commented Nov 3, 2016

$ system_profiler SPSoftwareDataType

@andyyou
Copy link
Author

andyyou commented Nov 9, 2016

macOS serria 使用來源未知軟體

$ sudo spctl --master-disable

@andyyou
Copy link
Author

andyyou commented Dec 13, 2016

Copy entire static website

>  wget --mirror -p --html-extension --convert-links tnyummy.tw

@andyyou
Copy link
Author

andyyou commented Dec 20, 2016

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start

@andyyou
Copy link
Author

andyyou commented Feb 12, 2017

#!/bin/bash
echo "ctime: $(ls -lc a | awk '{print $6, $7, $8}')"
echo "atime: $(ls -lu a | awk '{print $6, $7, $8}')"
echo "mtime: $(ls -l a | awk '{print $6, $7, $8}')"

exit 0;

atime: Access Time 檔案上次被讀取的時間
ctime: Change Time 檔案的屬性內容上次被修改的時間
mtime: Modify Time 檔案的內容上次被修改的時間

$ echo 'a sentence' > a.txt # ctime, mtime updated
$ cat a.txt # # atime updated
$ chmod 644 a.txt # ctime updated

@andyyou
Copy link
Author

andyyou commented Nov 2, 2017

Add https://localhost to OSX

$ cd; mkdir .ssl

$ openssl req -newkey rsa:2048 -x509 -nodes -keyout .ssl/localhost.key -new -out .ssl/localhost.crt -subj /CN=localhost -reqexts SAN -extensions SAN -config <(cat /System/Library/OpenSSL/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:localhost')) -sha256 -days 3650

$ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain .ssl/localhost.crt
            

@andyyou
Copy link
Author

andyyou commented Nov 16, 2017

# 查詢資訊 (包含設定檔案路徑)
$ gcloud info

# 設定
$ gcloud init 

# 列出所有設定檔
$ gcloud config configurations list 

#  刪除設定
$ gcloud config configurations delete <name> 

# 切換設定
$ gcloud config configurations activate <name>

# 列出已安裝的元件
$ gcloud components list

# 安裝元件
$ gcloud components install

# 更新
$ gcloud components update

# 移除元件
gcloud components remove <component_name>

@andyyou
Copy link
Author

andyyou commented Jan 2, 2018

OSX mount

$ diskutil list
$ diskutil mount /dev/disk1
$ diskutil unmount /dev/disk1s2

@andyyou
Copy link
Author

andyyou commented Oct 18, 2018

Change filename access right for git:

$ git ls-files -m | xargs chmod 644

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment