Mac iTerm2 设置代理

1.前提已经有socks5的翻墙代理
2.安装:

brew install privoxy

3.配置

listen-address 127.0.0.1:8087  #转换http代理后的监听的端口
forward-socks5 / 127.0.0.1:1080 . #需要转换http代理的socks5代理

forward 192.168.*.*/ .
forward 10.*.*.*/ .
forward 127.*.*.*/

4.启动

privoxy /usr/local/etc/privoxy/config

lsof -i:8087 #查看端口是否启动

#设置环境变量后,当前终端页即可使用代理
export http_proxy=http://127.0.0.1:8087
export https_proxy=$http_proxy

#删除环境变量
unset http_proxy https_proxy

How to fix: MySQL not starting on MAMP (Pro)

How to fix: MySQL not starting on MAMP (Pro)
I recently had to install MAMP Pro, in order to do some separate work from my Laravel Homestead VM.

After a weird Mac crash, MAMP would no longer start the MySQL server. This was the data from the logs:

To fix this, go to MAMP, File > Edit Template > MySQL > [version] and add the line highlighted below.

# The MySQL server
[mysqld]
innodb_force_recovery = 1

The restart the server. After this you can comment out that line. Hopefully you will now be able to run the server again.

Source:http://blog.ign.uy/2017/how-to-fix-mysql-not-starting-on-mamp-pro

在Mac OS下 如何将git分支名显示在前面

先看下效果
git_branch_name

打开.bash_profile文件
如果没有先创建一个

$ touch ~/.bash_profile

打开文件并编辑

$ vim ~/.bash_profile

在最后面加入并保存并退出

# Git branch in prompt.
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ (1)/'
}
export PS1="u@h W[33[32m]$(parse_git_branch)[33[00m] $ "

最后别忘了让编辑的文件生效

source ~/.bash_profile

Notice:
[33[32m] 这部分设置分支的文本的颜色,如果你喜欢另一种颜色,修改斜杠内的色值。

Mac OS X wifi 休眠后自动断网的问题

自从OS X 10.8 发布一来一直有个小问题就是长时间不使用的时候系统会自动进入休眠状态并且断开wifi网络连接.这样会造成下载的数据暂停等. 有些小不方便.
经过搜索, 可以在终端内输入如下命令暂停这个休眠. 
新版的支持一个Standby的模式的,在GUI界面是看不见的,也没有休眠的设置,所以需要使用命令。

sudo pmset -a standby 0 sleep 20 hibernatemode 3 networkoversleep 0 force

要恢复只需要在终端输入

sudo pmset -a standby 1 sleep 20 hibernatemode 3 networkoversleep 0 force

这样的设置可能会造成如果没有连接电源情况下比较费电. 大家请酌情使用吧..

转自:http://blog.sina.com.cn/s/blog_71715bf80101ebhk.html

git hooks pre-commit git挂钩防范于未然 提交前的自我检查

这几天抽空看了一下git文档,发现有个hooks的好东西,在开发过程中常常不小心会把一些不想提交的文件给提交进去,也常常在提交代码后发现 文件有语法错误,这样的提交一旦上线后很可能会导致正式环境出现严重的问题。

今天就说一下 pre-commit 这个hook,它会在你执行 git commit 操作的时候触发,如果该hook返回1,那么这次的 commit 将会被终止。

hook 位于 .git/hooks/ 目录下,可以看到很多 .sample 的文件这些都是示例文件,我们自己建一个 pre-commit 文件,里面可以写shell脚本,比如我写了一个检查php语法错误和config文件不可被提交进去的脚本

#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

ROOT_DIR="$(pwd)/"
LIST=$(git diff-index --name-only --diff-filter=ACMR HEAD)
ERRORS_BUFFER=""
for file in $LIST
do
    EXTENSION=$(echo "$file" | grep "config.php$")
    if [ "$EXTENSION" != "" ]; then
        echo "注意:有config文件要提交!如果确定要提交可用 git commit --no-verify 来忽略";
        exit 1
    fi
    EXTENSION=$(echo "$file" | grep ".php$")
    if [ "$EXTENSION" != "" ]; then
        ERRORS=$(php -l $ROOT_DIR$file 2>&1 | grep "Parse error")
        if [ "$ERRORS" != "" ]; then
            if [ "$ERRORS_BUFFER" != "" ]; then
                ERRORS_BUFFER="$ERRORS_BUFFERn$ERRORS"
            else
                ERRORS_BUFFER="$ERRORS"
            fi
            echo "检测到有语法错误的php文件: $file "
        fi
    fi
done
if [ "$ERRORS_BUFFER" != "" ]; then
    echo
    echo "Found PHP parse errors: "
    echo -e $ERRORS_BUFFER
    echo
    echo "PHP parse errors found. Fix errors and commit again."
    exit 1
else
    echo "No PHP parse errors found. Committed successfully."
fi

大功告成,测试一下:

pre-commit

pre2

php cgi socket: Too many open files

Too many open files经常在使用linux的时候出现,大多数情况是您的程序没有正常关闭一些资源引起的,所以出现这种情况,请检查io读写,socket通讯等是否正常关闭 错误信息:


create_debugger_socket("127.0.0.1", 9002) socket: Too many open files

用 ulimit -a  查看了一下 只有 256


ulimit -a

open files                      (-n) 256

使用 ulimit -n 命令来提高 open files 数


ulimit -n 1024

当然这个只是临时的修改,关闭终端后就失效了 我们可以通过修改 /etc/launchd.conf 文件来使其永久生效 如果系统中不存在launchd.conf我们就创建一个,如果已存在 则在最后添加

sudo vim /etc/launchd.conf

添加以下内容 limit maxfiles 65536 65536 修改后重启电脑然后再通过 ulimit -a 查看

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited

参考文章:http://artincube.com/too-many-open-files-limit-on-mac-os-x-ptgui-pro/

在VirtualBox中设置ubuntu虚拟机挂载共享宿主机的方法

有时需要在虚拟机中共享宿主机的文件,但是发现选择了宿主机的文件夹进行共享后,并没有效果,这让我们非常头疼。

接下来给大家演示一下如何在ubuntu虚拟机中加载宿主机的共享文件夹

1

2 3 4

 

注意!此时的Folder Name 必须和共享的文件夹名不一致,否则无法加载进来,比如我选的文件夹是 sites ,命名的Folder Name 是 macsites

执行完以后,进入ubuntu虚拟机,打开终端进行以下操作


sudo mkdir /mnt/shared

sudo mount -t vboxsf macsites /mnt/shared

操作完以后就可以了,快去看看吧

6

是不是挂载进来了~!

Mac用port安装nginx

安装macport

到http://www.macports.org/install.php下载macports
安装nginx:运行

sudo port install nginx spawn-fcgi

安装php:运行

sudo port install php53 fcgi php53-cgi php53-mysql php53-curl php53-iconv php53-mcrypt

安装imagick: 运行

sudo port install php53-imagick

nginx配置
进入

cd /opt/local/etc/nginx

创建sites-avalaible和sites-enabled文件夹
参考附件的配置文件,编辑nginx.conf, fastcgi.conf, mime.types
参考附件的配置文件在sites-available中创建web配置文件

php 配置


 error_reporting = E_ALL & ~E_NOTICE
 display_errors = On
 date.timezone = Asia/Shanghai
 short_open_tag = On



开启自启动配置
将以下代码保存至/Library/LaunchDaemons/org.macports.nginx.plist

 <?xml version='1.0' encoding='UTF-8'?>
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
 "<span style="text-decoration: underline;">http://www.apple.com/DTDs/PropertyList-1.0.dtd</span>" >
 <plist version='1.0'>
 <dict>
 <key>Label</key><string>org.macports.nginx</string>
 <key>ProgramArguments</key>
 <array>
         <string>/opt/local/bin/daemondo</string>
         <string>--label=nginx</string>
         <string>--start-cmd</string>
         <string>/opt/local/sbin/nginx</string>
         <string>;</string>
         <string>--pid=fileauto</string>
         <string>--pidfile</string>
         <string>/opt/local/var/run/nginx/nginx.pid</string>
 </array>
 <key>Debug</key><false/>
 <key>Disabled</key><true/>
 <key>KeepAlive</key><true/>
 </dict>
 </plist>

将以下代码保存至/Library/LaunchDaemons/org.macports.phpfcgi.plist

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "<span style="text-decoration: underline;">http://www.apple.com/DTDs/PropertyList-1.0.dtd</span>">
 <plist version="1.0">
 <dict>
   <key>Label</key><string>org.macports.phpfcgi</string>
   <key>Debug</key><false />
   <key>OnDemand</key><false />
   <key>RunAtLoad</key><false />
   <key>EnvironmentVariables</key>
   <dict>
     <key>PHP_FCGI_CHILDREN</key><string>2</string>
     <key>PHP_FCGI_MAX_REQUESTS</key><string>5000</string>
   </dict>
   <key>LaunchOnlyOnce</key><true />
   <key>ProgramArguments</key>
   <array>
     <string>/opt/local/bin/spawn-fcgi</string>
     <string>-C 2</string>
     <string>-p 9000</string>
     <string>-f /opt/local/bin/php-cgi53</string>
   </array>
 </dict>
 </plist>

运行

sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist

运行

sudo launchctl load -w /Library/LaunchDaemons/org.macports.phpfcgi.plist

运行

sudo lsof -i:80

sudo lsof -i:9000

检查nginx和fastcgi是否分别正常监听80和9000端口
如果安装php扩展,安装后重启fastcgi即可

sudo killall php-cgi53
sudo php-cgi53 -b 127.0.0.1:9000  &

Mac下用alias自定义命令

由于在终端里用命令alias ll=”ls -l”只能是当时起到效果,等重新启动mac的时候就提示命令不在了,也就是说是临时的,所以就在.bash_profile文件里面设置一下:

1. 启动终端Terminal

2. 进入当前用户的home目录

输入cd ~

3. 创建.bash_profile

输入touch .bash_profile

4. 编辑.bash_profile文件

输入open -e .bash_profile

在打开的文件中输入: alias ll=”ls -l”

5. 保存文件,关闭.bash_profile

6. 更新刚配置的环境变量

输入source .bash_profile

7. 验证配置是否成功

在终端输入ll查看效果,重启mac试试

Mac完整移除Dropbox

在Mac Air使用Dropbox,對於空間本來就不大的SSD,是一個不容忽視的存在,
因此決定把它移除,有需要再透過網頁去下載需要的檔案。

# 首先先把Dropbox的App從應用程式拖進垃圾桶,再刪除以下檔案及資料夾
rm -rf /Applications/Dropbox.app/*
rm -rf ~/Dropbox/