Mac 使用笔记(二)

1. iPhone每次连接Mac都会弹出iPhoto

解决办法:

  1. Plug in your iPad/iPhone
  2. Open Image Capture
  3. Select your device (“devMikePad”)
  4. Press the triangle in square symbol in the lower left corner.
  5. Select “No application” in the menu.

iPhoto: Preferences > General > “Connecting Camera Opens …” set it to “No Application”

2. Add environment variable

1
2
// ~/.bash_profile
export var=value

3.SSH ask passpharse every time I use SSH key.

A:

1
$echo -e "AddKeysToAgent yes\nUseKeychain yes" >> ~/.ssh/config

4.Fix the Enable and Disable install software from anywhere in macOS Sierra

A:

1
2
3
4
5
// Enable
$ sudo spctl --master-disable

// Disable
$sudo spctl --master-enable

Reference:Fix the Enable and Disable install software from anywhere in macOS Sierra problem

5.Mac 上批量替换文件中的字符串

A:

1
$ grep -rl discription source/_posts | xargs sed -i ''  "s/discription/description/g"

Reference:linux 批量替换文件内容及查找某目录下所有包含某字符串的文件(批量修改文件内容)
论mac使用sed修改文件的正确姿势

6.如何查看占用指定端口的进程?

A:

1
$ lsof -i :[port]

结果输出中有进程的 pid, 之后我们可以用这个 pid 来杀掉该进程:

1
$ kill -9 [pid]

这些进程很可能是系统启动时就启动了,可以通过:

1
$ launchctl list | grep [pid]

来确认。如果找到有,而我们又不想它自启动了,可以在以下目录中找到配置文件:

1
2
3
~/Library/LaunchAgents         Per-user agents provided by the user.
/Library/LaunchAgents          Per-user agents provided by the administrator.
/Library/LaunchDaemons         System wide daemons provided by the administrator.

找到之后,可以用命令:

1
2
3
$ launchctl unload -w paths
// eg:
$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist

查看启动进程的命令:

1
ps -p <pid> -wwf
继续阅读

Web 开发问题汇总(二)

1.Uncaught TypeError: Cannot read property ‘msie’ of undefined

A:The $.browser method has been removed as of jQuery 1.9.

jQuery.browser() removed

The jQuery.browser() method has been deprecated since jQuery 1.3 and is removed in 1.9. If needed, it is available as part of the jQuery Migrate plugin. We recommend using feature detection with a library such as Modernizr.

— jQuery Core 1.9 Upgrade Guide.

As stated in the Upgrade Guide you can try using the jQuery Migrate plugin to restore this functionality and let jQuery Tools work.

Reference:Uncaught TypeError: Cannot read property ‘msie’ of undefined - jQuery tools

2.The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path in Eclipse

A:To include http-servlet into your class path, you have two options:

1. In this solution, you can add desired server runtime into your application as project facet. As runtime servers have already servlet runtime dependencies, they get included into your project and hence error is gone.
2. Another option is include the servlet dependency through maven itself. This will also fix the error.
1
2
3
4
5
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

Reference:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path in Eclipse

3.Dynamic Web Module 3.1 requires Java 1.7 or newer

A:

Step1:
Make sure your Java Project is configured probably to use Java 1.7. Right click your project > Properties > Java Compiler and set “Compiler compliance level” to 1.7

Step2:
Java Build Path. Click “Edit“. And change it to “Java 7”

Step3:
Next from the menu on the left select Project Facets > Java and set its version to 1.7

Extra Tips:
If you have maven project try updating source and target version of java compiler to 1.7 in pom.xml file.

Reference:How to solve “Dynamic Web Module 3.1 requires Java 1.7 or newer” in Eclipse

4.How to display available goals of maven plugin?

A:

Recent Maven plugins have generally an help goal to have in the command line the description of the plugin, with their parameters and types. For instance, to understand the javadoc goal, you need to call:

1
$ mvn javadoc:help -Ddetail -Dgoal=javadoc

It works of course for Maven core plugins. to list all goals of the archetype plugin :

1
$ mvn archetype:help

And it works also for third party plugins. For example, to display all goals of the spring-boot plugin :

1
$ mvn spring-boot:help

Reference:How to display a list of available goals?

5.Not a java source folder

A:以 maven-archetype-webapp 为原型新建工程,建好的工程没有 java 目录,于是在 src/main 下新建 java 目录,之后新建 Filter 或 Servlet 时提示 Not a java source folder.尝试右击 java 目录 > Build Path > Use as Source Folder 依然未生效,只得将目录删除恢复原状想其他办法。

于是选中工程 > Properties > Java Build Path > Source, 里面提示 src/main/java build path entries are missing, 嗯,有了新的线索,于是将这些丢失的入口都删除了,再重新创建 java source folder, 这样问题得到了解决,感觉这个问题像是 eclipse 的一个 bug.

继续阅读

How to Setup an IKEv2 VPN Server on CentOS 8

由于 Debian 8 官方不再支持,经过一番考虑和准备,最近将 VPS 的系统换成了 CentOS 8。Libreswan 的文档没有 VPN 时打不开,这就形成了一个死循环,所以将她换成了 StrongSwan 。StrongSwan 的文档个人觉得对新手不是很友好,我是看了好一会才看明白些,另外在支持 macOS,iOS,Windows 10 的过程中也遇到不少问题,所以这里记录下来,以备日后参考。

StrongSwan 的文档入口页有安装指南可用的配置示例。我个人建议先看下 Introduction to strongSwan,这对安装和配置很有帮助。

CentOS 8 中的 epel 仓库中有预编译的 strongswan 二进制安装包,我们直接安装就可以了。接下来就是配置,strongswan 有四种认证方式,出于安全和便捷的考虑,我选择了 Extensible Authentication Protocol (EAP)。

首先是准备证书。我们可以使用自签名证书或者通用证书颁发机构签发的证书,后者不需要在各个终端上安装自签名根证书,所以部署上更简单。

我们先来看看下自签名证书。

生成根证书:

1
2
3
cd /etc/strongswan/swanctl
strongswan pki --gen --outform pem > rsa/ca.pem
strongswan pki --self --ca --in rsa/ca.pem --type rsa --dn "C=CH, O=strongSwan, CN=strongSwan Root CA" --outform pem > x509ca/ca-cert.pem

生成服务器证书:

1
2
3
cd /etc/strongswan/swanctl
strongswan pki --gen --outform pem > rsa/server.pem
strongswan pki --pub --in rsa/server.pem --type rsa | strongswan pki --issue --cacert cacerts/ca.cert.pem --cakey rsa/ca.pem --dn "C=CH, O=strongSwan, CN=swan.tenneshop.com" --san swan.tenneshop.com --flag serverAuth --flag ikeIntermediate --outform pem > x509/server-cert.pem
继续阅读