Tao He

Tao He

  • Docs
  • API
  • Help
  • Blog

›Recent Posts

Recent Posts

  • Microsoft PowerPoint
  • Chrome
  • Alfred
  • Docusaurus
  • Git Commands

Reaver

April 3, 2014

{% include JB/setup %}

Kali or Ubuntu

Install

apt-get install reaver

Run

airmon-ng start wlan0
airodump-ng mon0
reaver -i mon0 -b 00:11:22:33:44:55 -c 1 -vv

macOS

Install

airmon-ng on Mac OS X is not supported.

Use GoAgent, or you will failed downloading Aircrack-ng.

export http_proxy=http://127.0.0.1:8087

Install from Homebrew.

brew install aircrack-ng
brew install reaver

Run

ifconfig
sudo wash -i en0
sudo reaver -i en0 -b 00:11:22:33:44:55 -vv
cp /etc/reaver/ABC.wpc ~/
sudo reaver --session ~/ABC.wpc -i en0 -b 00:11:22:33:44:55 -vv

Document

March 27, 2014

{% include JB/setup %}

UML

PlantUML PlantUML Vim Syntax/Plugin/FTDetect

macOS

brew install graphviz

Windows

Download Graphviz

Eclipse

Support UTF-8

Eclipse -> Preferences... -> General -> Workspace -> Text file encoding -> UTF-8

GUI

Download plantuml.jar

java -jar plantuml.jar -gui

Dounble-click not support Chinese.

C Plus Plus

March 26, 2014

{% include JB/setup %}

Graph

Graphviz - Graph Visualization Software

Debug

Valgrind

Dependency Analysis

dependency-alalysis is a part of static-code-analysis. There are several commercial products which are able to do dependency-alalysis on List of tools for static code analysis.

Here is a discuss on C++ project dependency analysis: (Visual) C++ project dependency analysis.

“Deep” header dependency analysis

Include what you use

Nmdepend is a lightweight 'link-time' dependency analyzer for C++. It uses object files and libraries instead of source-code as input. It runs UNIX and Cygwin. Nmdepend, [Nmdepend] (https://github.com/epronk/nmdepend).

Library Dependency Graphs

cppdep

CppDepend (Commercial)

ProFactor IncludeManager

Call Graph

KCachegrind CodeViz: A CallGraph Visualiser

Cygwin

December 21, 2013

{% include JB/setup %}

1. Install openssh

Select /libs/zlib, /net/openssh, /net/tcp_wrappers

ssh-host-config

When promote ... CYGWIN ..., enter ntsec

passwd taohe

Add rule inbound port 22 to firewall

net start sshd
ssh localhost

CentOS

November 21, 2013

{% include JB/setup %}

Create USB Disk

dd if= CentOS-6.5-x86_64-bin-DVD1.iso of=/dev/sdb

Enable DHCP

sudo cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
vi /etc/sysconfig/network-scripts/ifcfg-eth0

Add these lines

ONBOOT=yes
BOOTPROTO=dhcp

Start service

service network restart

check network status

ifconfig

Interface Configuration Files

User

Add User

w
userdel -f taohe
rm -rf /home/taohe
useradd taohe -r -m
passwd taohe
visudo
vi /etc/sudoers

Under root ALL=(ALL) ALL Add taohe ALL=(ALL) ALL

Delete User

userdel -f taohe
rm -rf /home/taohe/

Disable root Login SSH

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo vim /etc/ssh/sshd_config

Add

PermitRootLogin no

Restart sshd

sudo service sshd restart

Add repos

sudo yum install wget
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
sudo rpm -i rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
sudo yum update

Repositories

Mount USB

列出所有存储设备

lsblk

找到U盘大小的分区(例如根据大小来判断)。注意是分区而不是盘,例如sda1是分区,而sda盘

挂载U盘

lsblk
mkdir /mnt/usb/
mount -t vfat /dev/sdb1 /mnt/usb/
cd /mnt/usb/

这样U盘就成功mount上去了。这里sdb1是我的U盘,根据实际情况写就行。

卸载U盘

umount /mnt/usb/

设置ADSL的PPPOE拨号上网

以下操作都以root用户执行

像上面一样设置号eth0并启动

1. 安装pppoe拨号软件

下载所需软件rp-pppoe、ppp、libpcap

rpm -ivh libpcap-1.0.0-6.20091201git117cb5.el6.x86_64.rpm
rpm -ivh ppp-2.4.5-5.el6.x86_64.rpm
rpm -ivh rp-pppoe-3.10-8.el6.x86_64.rpm

2. 拨号上网

软件安装在/usr/sbin下面

cd /usr/sbin/
ls

pppoe-setup为配置pppoe-status为查看状态,adsl-start或者ifup ppp0启用连接,adsl-stop或者ifdown ppp0断开连接,

pppoe-setup
adsl-start

如果需要手动配置,可以

vi /etc/sysconfig/network-scripts/ifcfg-ppp0

ping百度可以的话就成功了。有时会拨号不成功,不一定是配置有问题。多试几次,重启一下。我曾经试过拨号不成功,只有ppp0有ipv4地址,eth0没有ipv4地址。过了半天和若干次重启之后正常了,ppp0和eth0都有ipv4地址。

Install Packages

GNOME

X Window

yum groupinstall "X Window System"

GNOME

yum groupinstall "Desktop"

Chinese Support

yum groupinstall "Chinese Support"

Start X

startx

Stop X

Press Ctrl + Alt + Backspace

PHP server

PHP Server

NTFS

sudo yum install fuse fuse-ntfs-3g

Chromium

在CentOS/RHEL 6.4上安装Chromium

Others

sudo yum install -y vim htop

Zsh

November 15, 2013

{% include JB/setup %}

zsh

macOS

brew options zsh
brew install zsh --with-gdbm --with-pcre --with-unicode9
brew install zsh-completions
chsh -s $(which zsh)

If encountered this error:

chsh: /usr/local/bin/zsh: non-standard shell

Add /usr/local/bin/zsh to /etc/shells

Ubuntu

sudo apt-get install zsh
chsh -s $(which zsh)

Operations

Exit zsh, but leave running jobs open?

Weird “jobs” behavior within zsh

oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Edit your new .zshrc file your home directory. You can select themes and plugins for usage in zsh. For a complete list of themes and plugins, look in the .oh-my-zsh folder in your home directory. This was installed with zsh. There is a themes folder here and a plugins folder.

To add new plugins, find this line in .zshrc:

plugins=(git)

I like plugins, so this is my setup:

plugins=(autojump git git-extras git-flow git-flow-avh git-hubflow git-prompt git-remote-branch gitfast github gitignore svn svn-fast-info cp brew tmux history history-substring-search terminalapp brew nanoc osx xcode zsh-syntax-highlighting)

Optionally set DEFAULT_USER in ~/.zshrc to your regular username to hide the user@hostname info when you’re logged in as yourself on your local machine. For example

DEFAULT_USER=taohe

If use brew, modify PATH

Put /usr/local/bin before /usr/bin

Put /usr/local/sbin before /usr/sbin

How to get an awesome looking terminal on mac os x

No, Really. Use Zsh.

zsh-completions

git clone https://github.com/zsh-users/zsh-completions ~/.oh-my-zsh/custom/plugins/zsh-completions

Enable it in ~/.zshrc by adding it to your plugin list and reloading the completion:

plugins=(… zsh-completions)

# zsh-completions
autoload -U compinit && compinit

zsh plugins

Method 1, install in oh-my-zsh (recommended)

cd ZSH/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
Activate the plugin in ~/.zshrc (in last position):
plugins=( [plugins...] zsh-syntax-highlighting)
source ~/.zshrc

Method 2, install in zsh

brew install zsh-syntax-highlighting
brew install zsh-history-substring-search
more "/usr/local/opt/zsh-history-substring-search/README.md"
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/local/opt/zsh-history-substring-search/zsh-history-substring-search.zsh
source ~/.zshrc

themes

Themes

set ZSH_THEME in ~/.zshrc to "agnoster".

agnoster theme shows git icons but needs patched font.

Make sure you have already downloaded powerline.

fontforge -script ~/.vim/bundle/powerline/font/fontpatcher.py /System/Library/Fonts/Menlo.ttc

If you prefer the old Monaco font, you should type

fontforge -script ~/.vim/bundle/powerline/font/fontpatcher.py /System/Library/Fonts/Monaco.dfont

For macOS, Fonts are located in '/Library/Fonts/' or '/System/Library/Fonts/'.

Menlo is the new default font in Mavericks.

OS X: Fonts included with Mavericks

After running this command, 'Monaco for Powerline.otf' or 'Menlo Regular for Powerline.otf' is generated. Install the font by double-clicking the font file in Finder and click “Install this font” from the preview window.

Font patching

Change iTerm fonts in

iTerm -> Preferences... -> Profiles -> (Select a profile) -> Text -> ChangeFont -> Menlo Regular for Powerline

macOS

November 15, 2013

{% include JB/setup %}

Overview

https://github.com/nikitavoloboev/my-mac-os

https://github.com/nikitavoloboev/my-ios

System

Set the key repeat rate

defaults write -g InitialKeyRepeat -int 10  # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1  # normal minimum is 2 (30 ms)

Turn on "three finger drag" for your Force Touch trackpad

XCode

If encountered this error:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

Run

xcode-select --install
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

homebrew

brew update
brew install
brew uninstall

doctor

brew doctor

Path

Source code in /Library/Caches/Homebrew/

Formula in /usr/local/Library/Formula/

cask

brew cask install google-chrome

Add to ~/.zshrc

plugins=(brew-cask)

git

Install git

brew install git
brew install tig
brew tap mkchoi212/fac https://github.com/mkchoi212/fac.git
brew install fac  # Easy-to-use CUI for fixing git conflicts

If encountered error:

sudo xcodebuild -license

Then 'agree' to it.

gperftools

Install

brew install gperftools

fd

fd is a simple, fast and user-friendly alternative to find.

Install

brew install fd

Usage

fd blahblahblah

The Silver Searcher

Install

brew install the_silver_searcher

Usage

ag blahblahblah ~/code

Python

Python

Emacs

brew tap d12frosted/emacs-plus
brew install emacs-plus --with-modern-icon
ln -s /usr/local/opt/emacs-plus/Emacs.app /Applications

Neovim

pip2 install neovim
pip3 install neovim
brew update
brew reinstall neovim
which nvim
nvim --version

In nvim, run :CheckHealth. It checks for common problems and best practices.

vim

brew cask install xquartz
brew options vim
brew install vim --with-client-server --with-gettext --with-luajit --with-python3
brew options macvim
brew install macvim --with-luajit --override-system-vim
which vim
vim --version
which mvim
mvim --version

iTerm

Color

Prefs... -> Profiles -> Terminal -> Terminal Emulation

Report Terminal Type: xterm-256color

Download solarized

Install iterm2-colors-solarized/Solarized\ Dark.itermcolors

Prefs... -> Profiles -> Colors -> Load Presets...

Key

Prefs... -> Profiles -> Terminal -> Check Use modern parser

If <C-h> does not work in neovim, try this.

Method 1

Add these line to ~/.zshrc

infocmp $TERM | sed 's/kbs=^[hH]/kbs=\\177/' > $TERM.ti
tic $TERM.ti

Method 2 (Incompatible with Vim. Not Recommended)

Prefs... -> Profiles -> Keys -> +

KeybindingDescription
^h[104;5u
^i[105;5u
^m[109;5u

https://github.com/neovim/neovim/issues/2048

fooCoder的iTerm2使用之道

guake

System Prefs... -> Shortcuts -> Mission Control -> Uncheck Show Dashboard

Prefs... -> Keys -> Check Show/hide system-wide hotkey -> F12 -> Check Hotkey profile

Shell Integration

Prefs... -> Profiles -> Terminal -> Check Use modern parser

tmux

Install tmux

brew options tmux
brew install tmux --with-utf8proc

Add to ~/.zshrc

plugins=(tmux)
export DISABLE_AUTO_TITLE=true

Lists out every bound key and the tmux command it runs

tmux list-keys

Default prefix is control + b.

Create a new tmux session

tmux [-CC] [-2] new -s session name

List tmux sessions

tmux list-sessions

In iTerm: iTrem -> Shell -> tmux -> Dashboard

Attach to a session

tmux [-CC] [-2] attach -t session name

Detach

prefix + d

In iTerm: iTrem -> Shell -> tmux -> Detach

Create a new window

prefix + c

In iTerm: iTrem -> Shell -> tmux -> Window or iTrem -> Shell -> tmux -> Tab

Move to the window based on index

prefix + 0-9

In iTerm: command + 0-9

Rename window

prefix + ,

Splits the window into two vertical panes

prefix + "

Splits the window into two horizontal panes

prefix + %

Using -CC will integrate tmux into iTerm2 UI. Such as split window and tab. Each tab corresponding to a window in the tmux session. iTerm2 use an arrow icon to indicate a tmux session before tab title.

Without -CC option, you should add -2 to force tmux support 256 colors.

Helpful tmux commands

iTerm2 and tmux Integration

Install and configure tmux on Mac OS X

Byobu

brew install byobu

fish

curl -L https://get.oh-my.fish | fish

oh-my-fish

omf install bobthefish

theme-bobthefish

omf install autojump
omf install brew
omf install cd
omf install code
omf install fasd
omf install fzf
omf install git-flow
omf install marlin
omf install osx
omf install proxy
omf install tab
omf install thefuck
omf install vcs
omf install z

plugin-brew plugin-cd plugin-vscode plugin-fasd plugin-git-flow marlin plugin-osx plugin-proxy plugin-tab plugin-thefuck plugin-vcs plugin-z

Set default

Append which fish to /etc/shells

sudo vi /etc/shells
chsh -s `which fish`

Awesome fish

Zsh

Zsh

color theme

export TERM=screen-256color in ~/.zshrc

set -g default-terminal "screen-256color" in ~/.tmux.conf

set t_Co=256 in ~/.vimrc

check

tput colors
echo $TERM

Download solarized

Install iterm2-colors-solarized/Solarized\ Dark.itermcolors and osx-terminal.app-colors-solarized/xterm-256color/Solarized\ Dark\ xterm-256color.terminal.

In iTerm: iTerm -> Prefs... -> Terminal -> Report Terminal Type: -> xterm-256color

In Terminal: Terminal -> Prefs... -> Settings -> Advanced -> Emulation -> Declare terminal as: -> xterm-256color

Then set as default in iTerm and Terminal.

(It seems doesn't work in Terminal. Needs manually steal every color from iTerm to Terminal?)

Solarized color scheme

Solarized colorscheme for vim

tmuxinator

gem install tmuxinator

Add to ~/.zshrc

plugins=(tmuxinator)

VSCode

Enable key repeats

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

How to enable key repeats on your Mac

Open the Command Palette (⇧⌘P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.

Running VS Code on Mac

Pass - as an argument to explicitly signal that the output of a piped command is coming in through stdin. For example:

ps aux | grep code | code -

The Fuck

brew install thefuck

Add to ~/.zshrc

plugins=(... thefuck)

autojump

brew install autojump

Add to ~/.zshrc

plugins=(... autojump)

Go to recent directories just write

j $DIRECTORY

And it will jump to the most frequently used directory with that name.

k

brew install k
git clone https://github.com/supercrabtree/k $HOME/.oh-my-zsh/custom/plugins/k

Add to ~/.zshrc

plugins=(k)

openssh

System Prefrences... -> Sharing -> Remote Login

gcc

Down Command Line Tools from Apple website and install it.

gdb

brew options gdb
brew install gdb --with-all-targets --with-python
brew info gdb
echo "set startup-with-shell off" >> ~/.gdbinit

Code Sign

If you try to use your freshly built gdb, you will get an error message such as:

Starting program: /x/y/foo
Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))

This is because the Darwin kernel will refuse to allow gdb to debug another process if you don't have special rights, since debugging a process means having full control over that process, and that isn't allowed by default since it would be exploitable by malware. (The kernel won't refuse if you are root, but of course you don't want to be root to debug.)

The most up to date method to allow gdb to control another process is to sign it with any system-trusted code signing authority. This is an easy process once you have a certificate (see the link below). If the certificate is known as gdb-cert, just use:

codesign -s gdb-cert `which gdb`

BuildingOnDarwin

gdbgui

gdbgui

CMake

brew options cmake
brew install cmake --with-completion

Go

brew install go

Add to ~/.zshrc

plugins=(go golang)

Mac OSX下Golang交叉编译

Rust

brew install rust  # --with-llvm

Add to ~/.zshrc

plugins=(rust cargo)
cargo install exa

Ruby

Don't use rbenv zsh plugin for a bug https://github.com/lewagon/setup/issues/40.

brew install ruby
rbenv which gem  # should be `/usr/local/lib/ruby/gems/2.5.0`
brew install rbenv ruby-build

Run rbenv init and follow the instructions to set up rbenv integration.

Close your Terminal window and open a new one so your changes take effect.

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

Install Ruby

rbenv versions
rbenv install 2.5.1
rbenv rehash

Write 2.5.1 to ~/.ruby-version

rbenv which gem  # should be `/Users/xxx/.rbenv/versions/2.5.1/bin/gem`
gem env home  # should be `/Users/xxx/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0`
gem install bundler
gem install colorls

https://github.com/rbenv/rbenv#homebrew-on-macos

Add to ~/.zshrc

# colorls
source $(dirname $(gem which colorls))/tab_complete.sh

Docker

Docker

fzf

brew install fzf
/usr/local/opt/fzf/install

gnu

How to replace Mac OS X utilities with GNU core utilities? Install and Use GNU Command Line Tools on Mac OS X

brew install coreutils --with-gmp
brew install binutils
brew install diffutils
brew install findutils --with-default-names
brew install gawk
brew install gnu-indent --with-default-names
brew install gnu-sed --with-default-names
brew install gnutls --with-guile --with-unbound
brew install grep --with-default-names
brew install gnu-tar --with-default-names

The --default-names option is optional, turn on this if you really need to use these GNU commands as default ones, or they will be compiled with a g prefix.

dircolors-solarized

Add to ~/.zshrc

alias l='gls --color -ap'
alias ll='gls --color -lahsp'

# dircolors
eval `gdircolors ~/.dircolors/dircolors.ansi-dark`

dev tools

Tools list https://github.com/trimstray/the-book-of-secret-knowledge

https://ivarch.com/programs/pv.shtml

Pipe Viewer - is a terminal-based tool for monitoring the progress of data through a pipeline.

brew install clang-format  # <https://clang.llvm.org/docs/ClangFormatStyleOptions.html>
brew install sift
brew install ag
brew install ack
brew install pt
brew install cgrep
brew install editorconfig
brew install htop --with-ncurses
brew install hping  # <http://www.hping.org/>
brew install mosh
brew install hping
brew install ccat
brew install catimg
brew install tree
brew install hub
brew install grc
brew install spark
brew install z
brew install magic-wormhole
brew install pstree
brew install sysdig
brew install yarn
brew install tldr  # Simplified and community-driven man pages
brew install micro
brew install httpie  # [Modern command line HTTP client](https://github.com/jakubroztocil/httpie)
brew install lrzsz
brew install wget --with-gpgme --with-libmetalink --with-pcre

# <https://github.com/BurntSushi/ripgrep>
brew install ripgrep

# <https://github.com/BurntSushi/xsv>
# A fast CSV command line toolkit written in Rust
brew install xsv

# <https://github.com/tidwall/jj>
brew tap tidwall/jj
brew install jj  # JSON Stream Editor (command line utility)

# <https://github.com/rgcr/m-cli>
# Swiss Army Knife for macOS
brew install m-cli

pip3 install 'glances[action,browser,cloud,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi]'  # An Eye on your system
pip3 install cheat
pip3 install crocs  # Regex for humans

Glances

# <https://github.com/sindresorhus/trash>
# Move files and directories to the trash
yarn glabal add trash-cli

yarn global add gtop  # System monitoring dashboard for terminal
yarn global add html-primer  # generates HTML5 boilerplates

Method 1 (Recommended)

Add to ~/.zshrc

plugins=(catimg mosh)

Method 2

. `brew --prefix`/etc/profile.d/z.sh

Apps

App Tamer

Reduce invisible apps' cpu usage.

Moom

Dock window to one side in Windows style.

SizeUp

Dock window to one side in Windows style.

Manico

Use Option + Number to switch app.

Peep

View and modify file encode.

Popcorn-Time

P2P movie.

NoSleep

Caffeine

Prevent your Mac from going to sleep and displaying the screen saver.

iTools Pro

Manage iPhone.

Tongbu Assistant

Manage iPhone.

iExplorer

Manage iPhone.

PhoneView

Manage iPhone.

Finder

System Prefs... -> Keyboard -> Keyboard -> -> Check Use all F1, F2, etc. keys

System Prefs... -> Keyboard -> Shortcuts -> Mission Control -> Select All controls

System Prefs... -> Keyboard -> Shortcuts -> Mission Control -> Uncheck all F1 ~ F12 shortcuts

XtraFinder

http://www.trankynam.com/xtrafinder/

Shortcat

https://shortcatapp.com/

Keyboard control

Bartender

Arrange status bar icon

midnight commander

brew install midnight-commander
mc

Fantastical

Calendar

Dash

AP reference

FUSE for macOS

https://github.com/osxfuse/osxfuse/releases

VeraCrypt

https://veracrypt.codeplex.com/

Tad

A desktop application for viewing and analyzing tabular data

https://github.com/antonycourtney/tad

Seil

https://pqrs.org/osx/karabiner/seil.html.en

Proxy

https://www.proxifier.com/mac_download.htm

SN: P427L-9Y552-5433E-8DSR3-58Z68

ClashX

Aria2

brew install aria2

https://github.com/alanzhangzm/Photon

Motrix

https://github.com/agalwood/Motrix

Youtube

docker run -d -p 3000:3000 algram/ytdl-webserver

ytdl-webserver

Preference Panes

RCDefaultApp

Set the default application used for various URL schemes, file extensions, file types, MIME types, and Uniform Type Identifiers.

Beautify

The Matrix

https://github.com/will8211/unimatrix

矮矬穷Mac桌面美化得瑟教程 Mac亲们!Mac的桌面也有神美化效果啊!GeekTool... 继Geek Tool后的第二弹后续萌化~~

Delete Caches

brew cleanup
rm -rf ~/Library/Caches/Homebrew/

迁移

复制 ~/Library/Application Support/iTerm2/Scripts/ 微信聊天记录、企业微信聊天记录、RTX聊天记录、iTerm配置、VS Code配置、Bartender配置、OneTab记录、Proxy SwitchyOmega配置、Tamper Monkey配置、Tab Modifier配置、The Great Suspender配置、Alfred配置、vim、spacemacs

https://github.com/zenorocha/alfred-workflows https://www.alfredapp.com/workflows/ https://github.com/isometry/alfred-tty

macOS Server

November 15, 2013

{% include JB/setup %}

PHP

Nginx

MySQL

Install MySQL

brew options mysql
brew install mysql --enable-debug

Let launchd Start MySQL at Login

CAUTION: mysqld takes up 500 MB memory!

ln -sfv /usr/local/Cellar/mysql/5.6.17_1/*.plist ~/Library/LaunchAgents/

Load MySQL

Option 1 (suggested)

sudo gem install lunchy
lunchy list
lunchy stop mysql
lunchy start mysql

Option 2

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Brew’ing PHP, MySQL & Nginx on Mac OS X

Redis

brew install redis

To have launchd start redis at login:

ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

Then to load redis now:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Or, if you don't want/need launchctl, you can just run:

redis-server /usr/local/etc/redis.conf

PostgreSQL

October 5, 2013

{% include JB/setup %}

macOS

Install postgres

brew update
brew remove postgresql
brew install postgresql

Create a database

initdb /usr/local/var/postgres -E utf8

Serve that database

postgres -D /usr/local/var/postgres

To have launchd start postgresql at login

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

Then to load postgresql now.

Option 1 (suggested)

sudo gem install lunchy
lunchy list
lunchy stop postgres
lunchy start postgres

Option 2

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

How to Install PostgreSQL on a Mac With Homebrew and Lunchy

CentOS

Configure your YUM repository

sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
sudo vim /etc/yum.repos.d/CentOS-Base.repo

Add the following line to /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections

exclude=postgresql*

Download and install PGDG RPM files

mkdir ~/bin/
cd ~/bin/
curl -O http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm

Now install RPM distribution

sudo rpm -ivh pgdg-centos93-9.3-1.noarch.rpm

Install PostgreSQL

sudo yum list postgres*
sudo yum install postgresql93-server

Initialize

sudo service postgresql-9.3 initdb

Startup

sudo chkconfig postgresql-9.3 on

Control service

sudo service postgresql-9.3 restart
su postgres

YUM Installation

Remote Access

Disable Firewall

Linux Firewall

Edit conf File

To be able to reach the server remotely

sudo cp /var/lib/pgsql/9.3/data/postgresql.conf /var/lib/pgsql/9.3/data/postgresql.conf.bak
sudo vim /var/lib/pgsql/9.3/data/postgresql.conf

Add the line listen_addresses = '*'

PostgreSQL, by default, refuses all connections it receives from any remote address. You have to relax these rules by adding this line to /var/lib/pgsql/9.3/data/pg_hba.conf

sudo cp /var/lib/pgsql/9.3/data/pg_hba.conf /var/lib/pgsql/9.3/data/pg_hba.conf.bak
sudo vim /var/lib/pgsql/9.3/data/pg_hba.conf

IMPORTANT: You must delete the origin corresponding lines, or your configure won't take effect!

If password is not needed

host all all  0.0.0.0/0 trust

If password is not needed

host all all  0.0.0.0/0 md5

IMPORTANT: You can't change user postgres' password through command passwd. Instead, it can be changed by SQL command in psql prompt

ALTER USER postgres with encrypted password 'your_password'

Configure Firewall

CentOS

sudo cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
sudo vim /etc/sysconfig/iptables

Add these lines before -A INPUT -j REJECT line

-A INPUT -p tcp -s 0/0 --sport 1024:65535 --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp --sport 5432 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

Enable Firewall

Linux Firewall

Control Service

sudo service postgresql-9.3 restart

Test

psql -h 192.168.0.81 -U postgres -d weibominer

How Do I Enable remote access to PostgreSQL database server?

Tuning

Tuning Your PostgreSQL Server

PostgreSQL Studio

Download pgstudio_*.tar.bz2 from PostgreSQL Studio

Uncompress and put the *.war under

CentOS Tomcat6

cp pgstudio.war /var/lib/tomcat6/webapps/

Add PostgreSQL JDBC Driver (Not a must because PostgreSQL Studio owns it)

Download from PostgreSQL JDBC Driver

Put the postgresql-*-jdbc*.jar under

CentOS Tomcat6

/usr/share/tomcat6/lib/

Start Tomcat

service tomcat6 restart

Browse in browser.

PostgreSQL Studio

Installation Guide

PgAdmin

Install from yum

yum search pgadmin
yum install pgadmin3_93

SQL

psql -l
psql postgres
\?

SET time_zone = "+08:00";
CREATE DATABASE weibominer;

\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]
\c weibominer
\l+
\encoding [ENCODING]

DROP TABLE IF EXISTS sina_user_filter;

CREATE TABLE IF NOT EXISTS sina_user_filter
(uid SERIAL4, ui INT8 NOT NULL UNIQUE, un INT8 NOT NULL UNIQUE, sn TEXT, sx CHAR(1), ad TEXT, de TEXT, iu TEXT, an INT8, fn INT8, mn INT8, iv BOOLEAN, id INT2, vi TEXT, wt TIMESTAMP, tg TEXT, at TIMESTAMP, fui TEXT);

DROP TABLE IF EXISTS sina_friendship;

CREATE TABLE IF NOT EXISTS sina_friendship 
(fid SERIAL4, 
friend_uid INT8 NOT NULL, follower_uid INT8 NOT NULL, 
hit INT4 NOT NULL DEFAULT 0, crawl_time TIMESTAMP, 
PRIMARY KEY (fid), UNIQUE (friend_uid, follower_uid));

DROP TABLE IF EXISTS sina_user;

CREATE TABLE IF NOT EXISTS sina_user 
(uid SERIAL4, 
user_uid INT8 NOT NULL UNIQUE, 
screen_name TEXT, name TEXT, province INT2, 
city INT2, location TEXT, description TEXT, 
url TEXT, profile_image_url TEXT, 
domain TEXT, gender BOOLEAN, 
followers_count INT8, friends_count INT8, bi_followers_count INT8, 
statuses_count INT8, favourites_count INT8, 
group_count INT8, 
created_at TIMESTAMP, allow_all_act_msg BOOLEAN, 
remark TEXT, geo_enabled BOOLEAN, verified INT2, 
allow_all_comment BOOLEAN, verified_reason TEXT, 
online_status INT2, 
status_id INT8, 
friend_uid INT8, follower_uid INT8, rank INT2, 
visited_user INT4 NOT NULL DEFAULT 0, 
visited_friend INT8 NOT NULL DEFAULT 0, 
visited_follower INT8 NOT NULL DEFAULT 0, 
visited_follower_active INT8 NOT NULL DEFAULT 0, 
visited_bilateral INT8 NOT NULL DEFAULT 0, 
visited_timeline INT8 NOT NULL DEFAULT 0, 
visited_user_info INT8 NOT NULL DEFAULT 0, 
visited_microblog INT8 NOT NULL DEFAULT 0, 
visited_repost INT8 NOT NULL DEFAULT 0, 
hit INT8 NOT NULL DEFAULT 0, crawl_time TIMESTAMP, 
PRIMARY KEY (uid));

DROP TABLE IF EXISTS sina_status_info;

CREATE TABLE IF NOT EXISTS sina_status_info 
(sid SERIAL4, 
status_id INT8 UNIQUE, 
status_mid TEXT UNIQUE, 
source_url TEXT, source_rel TEXT, source_name TEXT, url TEXT, created_at TIMESTAMP, 
previous_id INT8, origin_id INT8, 
previous_mid TEXT, origin_mid TEXT, 
previous_idstr TEXT, origin_idstr TEXT, 
repost_count INT4 NOT NULL DEFAULT 0, 
comment_count INT4 NOT NULL DEFAULT 0, 
attitude_count INT4 NOT NULL DEFAULT 0, 
user_uid INT8 NOT NULL, 
retweeted_status_id INT8, 
visited_query_mid INT4 NOT NULL DEFAULT 0, 
visited_query_id INT4 NOT NULL DEFAULT 0, 
hit INT4 NOT NULL DEFAULT 0, crawl_time TIMESTAMP, 
PRIMARY KEY (sid));

DROP TABLE IF EXISTS sina_status_detail;

CREATE TABLE IF NOT EXISTS sina_status_detail 
(sid SERIAL4, 
status_id INT8 UNIQUE, 
text TEXT, 
hit INT4 NOT NULL DEFAULT 0, crawl_time TIMESTAMP, 
PRIMARY KEY (sid));

\dt+

UPDATE sina_user SET visited_friendship=0;
UPDATE sina_user SET visited_follower=0;
UPDATE sina_user SET visited_follower_active=0;
UPDATE sina_user SET visited_bilateral=0;

DELETE FROM sina_user *;
SELECT NOW(); SELECT COUNT(uid) FROM sina_user; SELECT COUNT(fid) FROM sina_friendship; SELECT COUNT(uid) FROM sina_user WHERE visited_friend>0; SELECT COUNT(uid) FROM sina_user WHERE visited_follower>0; SELECT COUNT(sid) FROM sina_status_info; SELECT COUNT(sid) FROM sina_status_detail;
INSERT INTO test1 VALUES ('ok');
INSERT INTO test2 VALUES ('too long'::varchar(5)); -- explicit truncation

\q

Linux Java

October 5, 2013

{% include JB/setup %}

Oracle JDK

Ubuntu

sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

CentOS

mkdir ~/bin/
cd ~/bin/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.rpm"
sudo rpm -Uvh jdk-8u5-linux-x64.rpm
java -version
export JAVA_HOME="/usr/java/latest"
export JRE_HOME="$JAVA_HOME/jre"
export PATH="$PATH:$JAVA_HOME/bin:$JRE_HOME/bin"

Install Oracle Java JDK/JRE 8u5 on Fedora 20/19, CentOS/RHEL 6.5/5.10

Install Oracle Java JDK/JRE 7u40 on Fedora 19/18, CentOS/RHEL 6.4/5.9

Properly installing Oracle's JDK on CentOS, RHEL or Scientific Linux

Open JDK

CentOS

yum search java | grep java-
sudo yum install java-1.7.0-openjdk-devel
sudo yum install java-1.6.0-openjdk-devel

Ubuntu

sudo apt-get install openjdk-7jdk

Apache Tomcat

yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
chkconfig tomcat6 on
service tomcat6 restart
http://[IP]:8080/

Apache Tomcat Installation on Linux (RHEL and clones)

How to install Tomcat 6 on RHEL 6 or CentOS 6

Remote Access

Disable Firewall

This is the most important step.

Ubuntu

ufw disable

CentOS

service iptables stop

Enable Firewall

CentOS

Add these lines before -A INPUT -j REJECT line

-A INPUT -p tcp --dport 8080 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 8009 -m state --state NEW -j ACCEPT

Now restart service

service iptables restart

Enable list directories

vim conf/web.xml
<init-param>
    <param-name>listings</param-name>
    <param-value>true</param-value>
</init-param>

Change true to false.

IntelliJ IDEA

IdeaVim

Download the *.zip file.

Intellij IDEA -> Preferences... -> Plugins -> Install plugin from disk...

← PrevNext →
Tao He
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Your Name or Your Company Name