guangningyu | 发布于 2016-11-16 14:03:34 | 阅读量 269 | Docker
发布于 2016-11-16 14:03:34 | Docker

在国内build Docker镜像是一件痛苦的事情。
不过,如果恰好有一位同事已经在本地build好了一个镜像,那么我们可以通过以下方式将镜像存储成一个文件,再拷贝到自己的电脑里面,从而避免再次build的麻烦。

  1. 将Docker镜像保存为一个文件

    1. docker save -o <save image to path> <image name>
  2. 通过cpscp命令将镜像文件拷贝至本地

  3. 导入Docker镜像文件

    1. docker load -i <path to image tar file>
继续阅读
guangningyu | 发布于 2016-11-07 22:59:15 | 阅读量 281 | MySQL
发布于 2016-11-07 22:59:15 | MySQL

安装MySQL

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install mysql-server-5.6

安装phpmyadmin

  1. sudo apt-get install phpmyadmin
  2. php5enmod mcrypt
  3. service apache2 restart

注意:安装phpmyadmin时,会有一步需要配置apache2,要按space选中,然后按tab将光标移动到OK的位置

phpmyadmin的安全设置

  1. vi /etc/apache2/conf-available/phpmyadmin.conf
  1. <Directory /usr/share/phpmyadmin>
  2. Options FollowSymLinks
  3. DirectoryIndex index.php
  4. AllowOverride All // 添加这一行
  5. . . .
  1. sudo service apache2 restart

设置如下:

  1. vi /usr/share/phpmyadmin/.htaccess
  1. AuthType Basic
  2. AuthName "Restricted Files"
  3. AuthUserFile /etc/phpmyadmin/.htpasswd
  4. Require valid-user

设置登陆名和密码:

    apt-get install apache2-utils
  1. htpasswd -c /etc/phpmyadmin/.htpasswd username // username改为自己的登陆名

Python安装MySQL接口

  1. sudo apt-get install python-pip python-dev libmysqlclient-dev
  2. pip install MySQL-python
继续阅读
guangningyu | 发布于 2016-12-07 09:48:26 | 阅读量 28 |
发布于 2016-12-07 09:48:26 |

1.安装PPTP

Ubuntu:

  1. apt-get install pptpd

CentOS:

  1. rpm -i http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
  2. yum -y install pptpd

2.配置PPTP的IP段

/etc/pptpd.conf文件中添加如下两行:

  1. localip 10.0.0.1
  2. remoteip 10.0.0.100-200

其中localip是分配给服务器的内部网关地址,remoteip是分配给客户端的内网IP

3.配置PPTP的访问权限

/etc/ppp/chap-secrets中设置访问用户的用户名和密码:

  1. # client server secret IP addresses
  2. user1 pptpd dal1Diksa *
  3. user2 pptpd ak91Kdzc0 *

4.配置PPTP的DNS服务器

/etc/ppp/pptpd-options (CentOS: /etc/ppp/options.pptpd)中添加Google的DNS:

  1. ms-dns 8.8.8.8
  2. ms-dns 8.8.4.4

5.开启PPTP后台程序

在命令行中输入以下命令,开启PPTP后台程序:

  1. service pptpd restart

为了验证PPTP服务已正常开启,输入以下命令:

  1. netstat -alpn | grep :1723

如果显示以下结果,则证明PPTP服务运行正常:

  1. tcp 0 0 0.0.0.0:1723 0.0.0.0:* LISTEN 5326/pptpd

6.配置IP转发

/etc/sysctl.conf文件中添加以下设置:

  1. net.ipv4.ip_forward = 1

在命令行中执行下列命令,使配置生效:

  1. sysctl -p

7.添加iptables转发规则

在命令行中执行以

继续阅读
guangningyu | 发布于 2016-11-02 15:36:04 | 阅读量 20 | Git
发布于 2016-11-02 15:36:04 | Git

Showing remotes

  1. git remote -v

Pulling from remotes

  1. git pull origin master

Pushing to remotes

  1. git push origin master

Commit using default message

  1. git commit --no-edit

Cancel last commit

  1. git reset HEAD~

Undo a git add

  1. git reset filename.txt
继续阅读
guangningyu | 发布于 2016-11-02 13:39:18 | 阅读量 26 | NodeJS
发布于 2016-11-02 13:39:18 | NodeJS

Install nvm

  1. brew update
  1. brew install nvm

Then edit ~/.bashrc:

  1. export NVM_DIR=~/.nvm
  2. source $(brew --prefix nvm)/nvm.sh

Install node

  1. nvm ls-remote
  1. nvm install 4.5.0
  1. nvm ls
  1. nvm use 5.10.1
  1. nvm alias default 4.5.0

Uninstall node

  1. nvm uninstall 4.5.0
继续阅读
guangningyu | 发布于 2016-12-07 09:36:10 | 阅读量 13 | Ruby
发布于 2016-12-07 09:36:10 | Ruby
  1. curl -L https://get.rvm.io | bash -s stable
  1. rvm install ruby-2.2.0
  2. rvm use --default ruby-2.2.0
继续阅读
guangningyu | 发布于 2016-12-07 09:36:10 | 阅读量 13 | Ruby
发布于 2016-12-07 09:36:10 | Ruby

We’re going to use rbenv to install and manage our Ruby versions.

To do this, run the following commands in your Terminal:

  1. brew install rbenv ruby-build
  1. # Add rbenv to bash so that it loads every time you open a terminal
  2. echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
  3. source ~/.bash_profile

Install Ruby

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v
“`

继续阅读
guangningyu | 发布于 2016-08-07 18:45:14 | 阅读量 265 | Ruby
发布于 2016-08-07 18:45:14 | Ruby

scope

An important aspect of Ruby classes is scope. The scope of a variable is the context in which it’s visible to the program.

When dealing with classes, you can have variables that are
1. available everywhere (global variables), like $manufacturer
2. only available certain methods (local variables)
3. members of a certain class (class variables), like @@files
4. only available to particular instances of a class (instance variables), like @username

  1. class Computer
  2. $manufacturer = "Mango Computer, Inc."
  3. @@files = {hello: "Hello, world!"}
  4. def initialize(username, password)
  5. @username = username
  6. @password = password
  7. end
  8. def current_user
  9. @username
  10. end
  11. def self.display_files
  12. @@files
  13. end
  14. end
  15. # Make a new Computer instance:
  16. hal = Computer.new("Dave", 12345)
  17. puts "Current user: #{hal.current_user}"
  18. # @username belongs to the hal instance.
  19. puts "Manufacturer: #{$manufacturer}"
  20. # $manufacturer is global! We can
继续阅读
guangningyu | 发布于 2016-08-07 18:10:28 | 阅读量 265 | Ruby
发布于 2016-08-07 18:10:28 | Ruby

Blocks

.collect (和.map等价)

The collect method takes a block and applies the expression in the block to every element in an array.

  1. my_nums = [1, 2, 3]
  2. my_nums.collect { |num| num ** 2 }
  3. # ==> [1, 4, 9]
  4. # my_nums hasn't changed:
  5. my_nums
  6. # ==> [1, 2, 3]
  1. my_nums.collect! { |num| num ** 2 }
  2. # ==> [1, 4, 9]
  3. # my_nums has changed:
  4. my_nums
  5. # ==> [1, 4, 9]

yield

Why do some methods accept a block and others don’t? It’s because methods that accept blocks have a way of transferring control from the calling method to the block and back again. We can build this into the methods we define by using the yield keyword.

Example 1

  1. def block_test
  2. puts "We're in the method!"
  3. puts "Yielding to the block..."
  4. yield
  5. puts "We're back in the method!"
  6. end
  7. block_test { puts ">>> We're in the block!" }

return

  1. We're in the method!
  2. Yielding to the block...
  3. >>> We're in the block!
  4. We're back in the method!
  5. nil

Example 2: with parameter

  1. def yield
继续阅读
guangningyu | 发布于 2016-12-07 09:20:04 | 阅读量 9 | Ruby
发布于 2016-12-07 09:20:04 | Ruby
  1. def a
  2. puts "A was evaluated!"
  3. return true
  4. end
  5. def b
  6. puts "B was also evaluated!"
  7. return true
  8. end
  9. puts a || b
  10. puts "------"
  11. puts a && b

return

  1. A was evaluated!
  2. true
  3. ------
  4. A was evaluated!
  5. B was also evaluated!
  6. true
  7. nil
继续阅读