Tao He

Tao He

  • Docs
  • API
  • Help
  • Blog

›Recent Posts

Recent Posts

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

React

January 15, 2016

{% include JB/setup %}

Webpack and React

Node

  • Init
npm init -y

React

  • Install React
npm install --save react react-dom

Babel

  • Install Babel

Method 1:

npm install --save-dev babel-cli babel-preset-es2015 babel-preset-react

Method 2:

npm install -g babel-cli babel-preset-es2015 babel-preset-react
  • Presets

Method 1: Add .babelrc

{
    "presets": ["es2015", "react"]
}

Method 2: Use via package.json

{
  ...
  "babel": {
    "presets": ["es2015", "react"]
  }
  ...
}

Plugins

  • Run Babel to precompile jsx

For directory run this. By default JSX files with a .js extension are transformed.

./node_modules/babel-cli/bin/babel.js --presets es2015,react --watch src/ --out-dir lib/

For single file run this.

./node_modules/babel-cli/bin/babel.js example.js --presets es2015,react --out-dir lib/

Tooling Integration

webpack

  • Install webpack
npm install webpack webpack-dev-server -g
  • Install loader
npm install --save-dev babel-loader babel-core css-loader style-loader
  • Edit config
vi webpack.config.js
module.exports = {
  // add resolve.extensions. '' is needed to allow imports
  // without an extension. Note the .'s before extensions!!!
  // the matching will fail without!
  resolve: {
    // auto append extensions. we can require modules without extensions
    extensions: ['', '.js', '.jsx']
  },
  entry: "./entry.js",
  output: {
    path: __dirname,
    filename: "bundle.js"
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: "style!css"
      },

      // Set up jsx. This accepts js too thanks to RegExp
      {
        test: /\.jsx?$/,
        // Enable caching for improved performance during development
        // It uses default OS directory by default. If you need something
        // more custom, pass a path to it. I.e., babel?cacheDirectory=<path>
        loader: "babel?cacheDirectory"
      }
    ]
  }
};
  • Build bundle
webpack-dev-server --progress --colors

Or

webpack --progress --colors --display-error-details

webpack

Browsersync (Use webpack Instead)

  • Install Browsersync
npm install -g browser-sync
  • Add to package.json
{
  ...
  "scripts": {
    "dev": "browser-sync start --server --files \"*.*\""
  },
  ...
}
  • Run Browsersync
npm run dev

React Examples

  • basic-jsx-precompile
npm install --save-dev babel-cli babel-preset-es2015 babel-preset-react
cd ~/local/src/react-0.14.6/examples/basic-jsx-precompile/
./node_modules/babel-cli/bin/babel.js example.js --presets es2015,react --out-dir build/
cd ~/local/src/react-0.14.6/
browser-sync start --server --files "*.*"

Redux

npm install --save redux react-redux
npm install --save-dev redux-devtools

Redux Examples

Redux Examples

Xcode

May 23, 2015

{% include JB/setup %}

XVim

XVim

Solarized

Solarized-Dark-for-Xcode

cp Solarized\ Dark\ @ArtSabintsev.dvtcolortheme ~/Library/Developer/Xcode/UserData/FontAndColorThemes

Settings

Default output

~/Library/Developer/Xcode/DerivedData/cegui-test-hbelnfnfnfsjsabxmdgyqryiiqsi/Build/Products/Debug

Change current project output to project directory

XCode -> File -> Project Settings... -> Advanced... -> Legacy

Change all project output to project directory

XCode -> Prefs... -> Locations -> Advanced... -> Legacy

Import 3rd library

Click project name in the Project navigator. Select a target in the main panel.

Build Settings -> All -> Search Paths -> Header Search Paths -> Add 3rd header paths

Build Settings -> All -> Linking -> Other Linker Flags -> Add 3rd dylib (one per line)

Build Settings -> All -> Search Paths -> Library Search Paths -> Add 3rd library paths

Change library to reference location

Click project name in the Project navigator. Select the library to build in the main panel.

Build Settings -> All -> Deployment -> Installation Directory -> "@executable_path/../Frameworks"

Xcode 及 iOS 常用宏和常量

OpenGL

May 22, 2015

{% include JB/setup %}

BUILD

macOS

brew tap homebrew/versions
brew install glfw3
brew install glew

Beginning OpenGL Development on OS X

CEGUI

May 10, 2015

{% include JB/setup %}

BUILD

Building from source

macOS

  • Install OpenGL

OpenGL

  • Download CEGUI source and dependencies from CEGUI release
cd ~/local/src/cegui-deps-0.8.x-src/
mkdir build/
cd build/
cmake -G Xcode ..
xcodebuild -configuration Debug
xcodebuild -configuration Release
ls dependencies/lib

cd ~/local/src/cegui-0.8.5/
ln -s ../cegui-deps-0.8.x-src/build/dependencies .
mkdir build/
cd build/
cmake -G Xcode ..
xcodebuild -configuration Debug -jobs 4
xcodebuild -configuration Release -jobs 4
``

Copy `~/local/src/cegui-0.8.5/build/bin/CEGUISampleFramework-0.8_d.app/Contents/Frameworks/` to `~/local/src/cegui-0.8.5/build/` with mouse.

Because binary runtime read `../Frameworks/`.

* Run

```sh
# will load `datafiles/` from this directory
cd ~/local/src/cegui-0.8.5/
# ok
./build/bin/CEGUITemplate_GLFW3
# crash, don't know why
./build/bin/CEGUISampleFramework-0.8_d.app/Contents/MacOS/CEGUISampleFramework-0.8_d
  • Tools

find dylib location

otool -l ~/local/src/cegui-0.8.5/build/bin/CEGUITemplate_GLFW3
otool -l ~/local/src/cegui-0.8.5/build/bin/CEGUISampleFramework-0.8_d.app/Contents/MacOS/CEGUISampleFramework-0.8_d

change dylib location

install_name_tool -change

runtime dylib location

lsof -p PID

Windows

  • Download CEGUI source and dependencies from CEGUI release

  • Download CMake GUI

  • CMake and VSBuild cegui-deps-0.8.x-src into cegui-deps-0.8.x-src\build

  • Copy cegui-deps-0.8.x-src\dependencies into cegui-0.8.5

  • CMake and VSBuild cegui-0.8.5 into cegui-0.8.5\build

  • Copy all files in cegui-deps-0.8.x-src\dependencies into cegui-0.8.5\build\bin

  • Copy cegui-0.8.5\build\datafiles\samples\samples.xml into cegui-0.8.5\datafiles\samples\samples.xml

  • Copy cegui-deps-0.8.x-src\dependencies\* into cegui-0.8.5\build\bin

  • Run cegui-0.8.5\build\bin\CEGUISampleFramework-0.8_d.exe

Neovim

April 22, 2015

{% include JB/setup %}

Compile

macOS

pip install --upgrade pip
pip3 install --upgrade pip
pip -V
pip3 -V
pip install --upgrade neovim
pip3 install --upgrade neovim
gem install neovim
brew tap neovim/neovim
brew update
brew reinstall --HEAD neovim
brew install global

Add these line to ~/.zshrc

alias vi='nvim'
alias vim="nvim"
alias vimdiff="nvim -d"

Configuration

Navim

Plugins

lightline-buffer

Check

run :CheckHealth

Profile

vim --cmd "profile start profile.txt" --cmd "profile file ~/.config/nvim/core/main.vim" +q && vim profile.txt

Tags

Build from LLVM

tar xf libcxx.src.tar.xz
cp -R libcxx/include ~/.config/nvim/tags/libcxx
ctags -f libcxx.tags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ --sort=foldcase -I _NOEXCEPT libcxx

Building libc++

Build from GCC

cp -R gcc/libstdc++-v3/include ~/.config/nvim/tags/libstdcpp
find libstdcpp -type f -print0 | xargs -0 sed -i '' 's/namespace std _GLIBCXX_VISIBILITY(default)/namespace std/g'
ctags -f libstdcpp.tags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ --sort=foldcase -I _GLIBCXX_NOEXCEPT libstdcpp

Build from system or Modified Headers

cp -R /usr/include/c++/$GCC_VERSION ~/.config/nvim/tags/old_libstdcpp
# it is not necessary to rename headers without an extension
# replace the "namespace std _GLIBCXX_VISIBILITY(default)" with "namespace std"
find old_libstdcpp -type f -print0 | xargs -0 sed -i '' 's/namespace std _GLIBCXX_VISIBILITY(default)/namespace std/g'
ctags -f old_libstdcpp.tags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ --sort=foldcase -I _GLIBCXX_NOEXCEPT old_libstdcpp

Generate ctags

Generate CTAGS for libstdc++ Changing All Occurrences in a Folder

Linux破解无线网络

January 18, 2015

{% include JB/setup %}

Ubuntu破解WEP加密无线网络

http://www.net527.cn/a/anquan/Backtrack/7461.html

Google Maps

January 18, 2015

{% include JB/setup %}


查看大图

Python

January 3, 2015

{% include JB/setup %}

macOS

Install Python

brew install python3
which python3
ll /usr/local/bin/python3
brew install python2
which python2
ll /usr/local/bin/python2

Use Pip

Upgrade Pip

pip3 install --upgrade pip setuptools wheel
pip2 install --upgrade pip setuptools

Install packages

pip3 install <package>
pip2 install <package>

Install packages to user path

pip3 install --user mercurial
pip install --user mercurial

This should result in the hg script being installed in $HOME/.local/bin/hg and the rest of the hg package in $HOME/.local/lib/pythonx.y/site-packages/.

The location on macOS was changed from $HOME/.local to $HOME/Library/Python

https://stackoverflow.com/questions/7143077/how-can-i-install-packages-in-my-home-folder-with-pip

Install Scrapy

pip3 install scrapy

Ubuntu

Install Pip

sudo apt-get install python-pip
sudo apt-get install python3-pip
pip2 install --upgrade pip
pip3 install --upgrade pip
pip2 --version
pip3 --version

Install MySQL Connector/Python

sudo apt-get install python-dev libmysqlclient-dev
sudo pip install MySQL-python

Install Scrapy

sudo apt-get install python-dev libffi-dev libssl-dev libxml2-dev libxslt-dev
sudo pip install scrapy

Nagios

December 28, 2014

{% include JB/setup %}

Ubuntu Apache

linux-dash

sudo apt-get install php5 curl php5-curl php5-json
cd /var/www/html/
git clone https://github.com/afaqurk/linux-dash.git

<123.123.123.123/linux-dash/index.html>

Nagios

How do I install nagios?

Ubuntu Nginx

linux-dash

sudo apt-get install php5 curl php5-curl php5-json
cd /usr/share/nginx/html/
git clone https://github.com/afaqurk/linux-dash.git

<123.123.123.123/linux-dash/index.html>

Nagios (Failed)

sudo apt-get install fcgiwrap spawn-fcgi
sudo apt-get install nagios3

Add two upstream clauses in the http section

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo vi /etc/nginx/nginx.conf
upstream php {
    server unix:/var/run/php5-fpm.sock;
}

upstream fcgiwrap {
    server unix:/var/run/fcgiwrap.sock;
 }

Add a new virtualhost

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/nagios
ln -s /etc/nginx/sites-available/nagios /etc/nginx/sites-enabled/nagios
sudo vi /etc/nginx/sites-available/nagios
server {
    listen   80;
    server_name  nagios.example.tld;

    access_log  /var/log/nginx/nagios.access.log;
    error_log   /var/log/nginx/nagios.error.log info;

    expires 31d;

    root /usr/share/nagios3/htdocs;
    index index.php index.html;

    auth_basic "Nagios Restricted Access";
    auth_basic_user_file /etc/nagios3/htpasswd.users;

    location /stylesheets {
        alias /etc/nagios3/stylesheets;
    }

    location ~ \.cgi$ {
        root /usr/lib/cgi-bin/nagios3;

        rewrite ^/cgi-bin/nagios3/(.*)$ /$1;

        include /etc/nginx/fastcgi_params;

        fastcgi_param AUTH_USER $remote_user;
        fastcgi_param REMOTE_USER $remote_user;
        fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/nagios3$fastcgi_script_name;

        fastcgi_pass fcgiwrap;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass php;
    }
}

Restart

sudo service nginx restart
sudo service php5-fpm restart
sudo service fcgiwrap restart

<123.123.123.123/nagios/index.php>

How do I install nagios

How to serve nagios with nginx

Nagios

Nginx

December 27, 2014

{% include JB/setup %}

macOS

Install NGINX with PHP7-FPM on Mac OS X with Homebrew

Install

brew tap homebrew/dupes
brew tap homebrew/php
brew install nginx
brew info php71
brew options php71
brew install php71 --with-imap --without-apache --with-debug --with-phpdbg --with-postgresql
ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
php -v
php-fpm -v
lsof -Pni4 | grep LISTEN | grep php
sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Load PHP (Deprecated)

Option 1 (suggested)

sudo gem install lunchy
lunchy list
lunchy stop php
lunchy start php

Option 2

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

Test http://localhost:8080

Stop

nginx -s stop

Configure

mkdir -p /usr/local/etc/nginx/logs
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl
sudo mkdir -p /var/www

sudo chown :staff /var/www
sudo chmod 775 /var/www

rm /usr/local/etc/nginx/nginx.conf

curl -L https://gist.github.com/frdmn/7853158/raw/nginx.conf -o /usr/local/etc/nginx/nginx.conf
curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default -o /usr/local/etc/nginx/sites-available/default
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default-ssl -o /usr/local/etc/nginx/sites-available/default-ssl
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_phpmyadmin -o /usr/local/etc/nginx/sites-available/phpmyadmin
git clone http://git.frd.mn/frdmn/nginx-virtual-host.git /var/www
mkdir -p /usr/local/etc/nginx/ssl
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=localhost" -keyout /usr/local/etc/nginx/ssl/localhost.key -out /usr/local/etc/nginx/ssl/localhost.crt
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=phpmyadmin" -keyout /usr/local/etc/nginx/ssl/phpmyadmin.key -out /usr/local/etc/nginx/ssl/phpmyadmin.crt
ln -sfv /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default
ln -sfv /usr/local/etc/nginx/sites-available/default-ssl /usr/local/etc/nginx/sites-enabled/default-ssl
ln -sfv /usr/local/etc/nginx/sites-available/phpmyadmin /usr/local/etc/nginx/sites-enabled/phpmyadmin

sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

"Nginx works" page: http://localhost phpinfo(): http://localhost/info "Not Found" page: http://localhost/nope "Nginx works" page (SSL): https://localhost:443 phpinfo() (SSL): https://localhost:443/info "Not Found" page (SSL): https://localhost:443/nope

Default configuration: /usr/local/etc/nginx/nginx.conf.default

Control

curl -L https://gist.github.com/frdmn/7853158/raw/bash_aliases -o /tmp/.bash_aliases
cat /tmp/.bash_aliases >> ~/.bash_aliases
echo "source ~/.bash_aliases" >> ~/.zshrc

Start, stop and restart Nginx with

nginx.start
nginx.stop
nginx.restart

Quickly tail the latest error or access logs

nginx.logs.access
nginx.logs.default.access
nginx.logs.phpmyadmin.access
nginx.logs.default-ssl.access
nginx.logs.error
nginx.logs.phpmyadmin.error

Check config

sudo nginx -t

phpMyAdmin

brew install autoconf
echo 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.zshrc && . ~/.zshrc
brew install phpmyadmin
cp /usr/local/etc/phpmyadmin.config.inc.php /usr/local/etc/phpmyadmin.config.inc.php.bak
vi /usr/local/etc/phpmyadmin.config.inc.php

Change this AllowNoPassword to true

$cfg['Servers'][$i]['AllowNoPassword'] = true;

Login with root without password phpMyAdmin (SSL): https://localhost:306 phpMyAdmin setup (SSL): https://localhost:306/setup/

Ubuntu

Nginx

How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04

Install

sudo apt-get install nginx
sudo apt-get install php5-fpm

Configure PHP

sudo cp /etc/php5/fpm/php.ini /etc/php5/fpm/php.ini.bak
sudo vi /etc/php5/fpm/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0

cgi.fix_pathinfo=0

Restart PHP

sudo service php5-fpm restart

Configure Nginx

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
  • Add index.php to the index line

  • Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration)

  • Change the correct lines in location ~ \.php$ { section

  • Comment the line #fastcgi_pass 127.0.0.1:9000;

phpinfo

vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>

Restart Nginx

sudo service nginx restart

If error occur, try

sudo nginx -t

Nginx failing to reload

← 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