申请startssl免费一年ssl证书(转载)

申请过程步骤蛮多的,对于像我这样的小白来说还是截图+文字记录下比较好。浏览器是firefox。
1、打开http://www.startssl.com/
2、点击StartSSL Free(Class 1)

3、点击Certificate Control Panel进入控制面板,或直接访问http://www.startssl.com/?app=12也可以。
4、点击sign-up注册一个帐号

5、填写注册信息,要用英文格式填写

6、信息填写完成后,会给注册的邮箱发送一封电子邮件,此时不要关闭startssl的这个页面,检查邮箱输入验证码

7、等待StartComm人工审核注册的个人信息,如果审核成功会收到第二个邮件
例如:

StartSSL Account Request

To XXXX,
Your request for an account at StartSSL (www.startssl.com) has been approved and is available during the next 24 hours at the following location:
https://www.startssl.com/?app=12&action=release&id=XXXXXX&auth=XXXXXXXXXXXXXXXX
The verification code in order to continue the process is XXXXXXXXXXXXXXXX
Thank you!

startssl审批很快,稍等会儿就能收到邮件。访问邮件中的链接地址,再次输入验证码。
8、建立私钥

选择高级,点击continue。
9、安装证书

10、安装完成
安装完成后,会有一个提示框:

页面会提示:

Your first client certificate has been installed into your browser. This is a bootstrapping certificate for authentication purpose.
Backup this certificate to an external media, otherwise you might not be able to regain access to your account. Please read these instructions from our FAQ page on how to do that.

点击页面上的Finish。
11、随后页面会跳到F.A.Q.页面
点击How do I backup my client certificates?看下如何备份证书
firefox:工具-选项-高级-查看证书-您的证书,下面就有需要备份的证书。以后登录startssl要凭浏览器上前面安装的证书登录。丢失证书后只能重新注册。
以后要登录,点击Authenticate凭证书登录:

12、开始申请免费ssl证书
回到startssl的控制面板,我们看到有三个选项卡:

大致流程如下:
1)先到Validations Wizard验证域名的所有权
2)再到Certificates Wizard选择要申请证书的类型
3)再到Tool Box选项卡,使用里面的小工具生成证书
13、点击Validations Wizard
选择Domain name validation,点击Continue。

输入要申请的域名,点击Continue。

选择一个验证的邮箱,有[email protected]域名、[email protected]域名、[email protected]域名、和注册域名时的邮箱。

检查邮箱,输入验证码:

验证成功:

域名验证成功,这次验证在30天内有效,过期了要重新验证。点击Finish回到控制面板。
14、点击Certificates Wizard
选择WEB Server SSL/TSL Certifites:

生成私钥,为私钥提供一个密码,最少10位,最大32位:

将显示内容保存为ssl.key(这个私钥是加密的):

选择域名:

输入一个需要ssl证书的子域名:

然后确认前面用于申请证书的域名。
最后会提示:

Additional Check Required!

You successfully finished the process for your certificate. However your certificate request has been marked for approval by our personnel. Please wait for a mail notification from us within the next 3 hours (the most). We might contact you for further questions or issue the certificate within that time. Thank you for your understanding!

随后就等邮件通知。
15、收到邮件后点击Tool Box
使用Tool Box – Decrypt Private Key,将前面生成的ssl.key的内容解密。将结果保存为.key文件。比如ssl2.key。
保存证书:
Tool Box – Retrieve Certificate,选择申请证书的域名,将框中的内容保存为.crt文件。比如ssl.crt。这个就是证书文件啦。
apache服务器,上传ssl2.key和ssl.crt这两个文件,修改配置文件设置。

使用jcenter发布jar包

传说使用maven库发布jar包是一件非常麻烦的事情,安卓的gradle构建已经默认使用了jcenter,而且现在很多jar包只在jcenter上有,在maven上面没有,因此开始尝试使用jcenter来代替maven。

也许是习惯问题,感觉jcenter的搜索功能感觉很糟糕,没有 http://search.maven.org/ 这么方便,搜出来的结果乱七八糟的一大堆,暂时还是只用jcenter来下载和上传jar包,搜索包及版本还是在maven上面进行。国内的网络访问jcenter比maven要快不少。

使用jcenter来下载依赖包非常简单,在gradle脚本中,将全部 mavenCentral() 的地方改成jcenter()就可以了。

主要来说说将自己的包打包上传到jcenter的流程。

进入https://bintray.com/,注册一个账号,bintray支持很多第三方账号登陆,不论是用那种方式登陆,都建议关联一下自己的github账号,因为后面申请将自己的jar包投放到jcenter时,管理员会让你提供一些信息来证明你拥有该jar包代码的贡献者权限。

Can you please provide an online reference showing you’re a contributor to this project? Thanks, Bintray Team。

注册完成后,进入自己的maven库,创建一个新的package,填写详细的package信息,最好能在github上面有项目地址,申请发布到jcenter时会方便很多。

bintray项目截图

 

Package创建后,上图红色圈起来的部分是 Add to JCenter的按钮 ,点击申请将该包添加到jcenter,否则上传上去的内容别人不能通过jcenter()来下载到。

Request to include the package in jcenter

 

jcenter是不提供snapshot版本发布的,如果需要托管snapshot版本,需要在申请时勾上“Host my snapshot build artifacts on the OSS Artifactory at”的选项,这样审核通过后,可以使用bintray的账号登陆https://oss.jfrog.org,并且可以将snapshot版本托管到jfrog。

接下来就等待bintray工作人员的审核了,由于时区不同,他们审核最长可能需要大半天时间。等待审核的这段时间可以先写写发布脚本。

apply plugin: 'maven-publish'
apply plugin: "com.jfrog.bintray"
apply plugin: "com.jfrog.artifactory"
//通过该插件,生出来的pom.xml文件依赖项中才会有<optional>true</optional>的选项
apply plugin: 'optional-base' 
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2"
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
        classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:2.2.+'
    }
}

allprojects {
    apply plugin: 'java'
    repositories {
        jcenter()
    }
}

task sourceJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allJava
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            artifact sourceJar
        }
    }
}
Properties properties = new Properties()
properties.load(new FileInputStream("${System.properties['user.home']}/bintray.properties"))
artifactory {
    contextUrl = 'http://oss.jfrog.org/artifactory'
    resolve {
        repository {
            repoKey = 'libs-release'
        }
    }
    publish {
        repository {
            repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
            username =  properties.getProperty("bintray.user")
            password = properties.getProperty("bintray.apikey")
            maven = true
        }
        defaults {
//这里的名字和上面红色的名字一致即可,会将其包含的输出上传到jfrog上去
            publications('mavenJava')
            publishArtifacts = true
        }
    }
}
bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    publications('mavenJava')
    pkg {
        repo = "maven"
        name = "java-utils"	//发布到JCenter上的项目名字
        websiteUrl = "http://wujc.cn"
        licenses = ["Apache-2.0"]
        publish = true
    }
}

dependencies {
    compile "org.jasig.cas.client:cas-client-core:3.2.1"
    compile "org.apache.shiro:shiro-cas:${shiroVersion}", optional
    compile "org.apache.shiro:shiro-spring:${shiroVersion}", optional
}

执行gradle artifactoryPublish就可以发布到oss.jfrog.org上去了。

gradle可以通过这种方式下载到发布的snapshot包:

maven { url "http://oss.jfrog.org/oss-snapshot-local/" }

域名切换后wordpress需要做的相应改动

以前买了一个索马里的域名,88元/年,价格还算厚道,忽然so域名的注册局变了,移交给了海盗当局,以后续费就要350一年了,考虑了一下,决定还是重新申请一个cn的域名用用。虽然网站几乎还没什么流量,但是毕竟搜索引擎已经有收录了,因此还是得做一些域名切换的操作。

WordPress:

登陆管理后台,在设置中,将WordPress地址设置为新的域名。

百度sitemap插件中,将系统安装的URL路径重新校验为新的域名。

百度站长工具:

在百度站长工具中新增新的域名,否则百度sitemap插件会停止提交站内索引。

百度统计:

如果用了百度统计,需要在百度统计中新增站点,并在wordpress中更新站点统计JS代码。

Nginx:

1、将以前配置中的server_name修改为新的域名:

server_name  wujc.cn www.wujc.cn;

2、增加一个server节点,用来配置老的域名并重定向到新的域名:

server {
    listen       80;
    server_name  wjc.so www.wjc.so;

    location / {
        rewrite ^/(.*) http://wujc.cn/$1 permanent;
    }
}

重新加载nginx即可,至此所有搜索引擎中老域名过来的请求都会被重新定向到新域名。传说聪明的搜索引擎检测到后会逐渐自动将老的域名PR值切换到新的域名去,不过没有验证过,但是Google很快会自动收录新域名的内容,百度不会很快主动收录。

WordPress 添加统计代码两种方法

有两种方法可以添加统计代码

1、可以直接修改footer.php文件
或者在你的functions.php文件中添加一个函数挂载到页脚中执行。
下面我们来分别演示一下:

修改footer.php文件添加统计代码

找到页脚文件(footer.php)中标签的位置,并在其之前直接添加你获得的统计代码。
functions.php中添加函数并挂载到页脚中执行
将如下的代码添加到functions.php最后

 代码如下
function add_tj_code(){ ?>
//这里天加上你的统计代码
<?php }

add_action

这种方法会有一个问题,就是换了网站皮肤,或者升级了皮肤版本后,统计代码就丢失了,又得重新设置一次。

2、在小工具中添加统计代码

这是一种最简单的方法,由于百度统计的JS使用了异步加载,因此虽然小工具一般都在页面的侧边栏中,但是统计代码的加载不会对页面加载速度造成太大的影响。
在 仪表盘->外观->小工具中,将文本小工具拖动至小工具区域中,

小工具-html

将统计代码添加在其中

Java 8: Replace traditional for loops with IntStreams

I’ve previously looked at how to work on a higher level by replacing loops with streams. In this post I want to continue this by looking at IntStream and how it could replace the traditionalfor (int i=0;... loop.

IntStream is a stream of primitive int values. It’s part of the java.util.stream package, and you can find a lot of the same functions there as in the normal Stream<T>. There also exists streams for dealing with double and long primitives, but we’ll leave that out since it acts in pretty much the same way.

Creating the IntStream

There are several ways of creating an IntStream.

Let’s start by looking at the of function.

IntStream.of(1, 2, 3);  
// > 1, 2, 3

of just takes an arbitrary number of ints, creating an IntStream based on them.

Usually we don’t want to list up all the ints like this, so let’s instead continue by looking at two functions that probably will be used most of the time.

IntStream.range(1, 3);  
// > 1, 2
IntStream.rangeClosed(1, 3);  
// > 1, 2, 3

With rangeand rangeClosed, we define a range of ints that we want to create a stream of.

As you probably guessed from the resulting streams, the rangeClosed function includes the ending int, while range excludes it.

Now what if we don’t want all the ints within a range? What if we just want every even number?

Then we could use the iterator function.

IntStream.iterate(0, i -> i + 2).limit(3);  
// > 0, 2, 4

With iterator we can define a start value and a function that will calculate the next ints based on the previous element.

iterator creates an infinite stream, so I’ve used limit to create a stream containing just three elements.

The last function we’re going to cover for creating IntStreams, is the generate function.

IntStream.generate(() -> ThreadLocalRandom.current().nextInt(10)).limit(3);  
// > 4, 1, 7

generate looks a lot like iterator, but differ by not calculating the ints based on the previous element.

It simply takes an IntSupplier that will independently calculate the next int.

Working with the ints

Now that we have seen how we can create an IntStream, let’s start to play with it by using some of the functions it offer.

Let’s start by looking at the different map functions

First, let’s use the normal map function to find the squared value of all ints between 0 and 5.

IntStream.range(1, 5).map(i -> i * i);  
// > 1, 4, 9, 16

The map function maps to an IntStream, so what about when we want to return other types of streams?

Well, then we have dedicated map functions to handle these scenarios

Stream<Color> stream = IntStream.range(1, 5).mapToObj(i -> getColor(i));  

mapToObject will simply return a Stream of the type that the mapping returns.

Now, if you just want to convert an IntStream to a Stream<Integer>, there’s a dedicated function for this job called boxed.

Stream<Integer> stream = IntStream.range(1, 5).boxed();  

You’ll also find map functions that returns DoubleStream and LongStream.

DoubleStream stream = IntStream.range(1, 5).mapToDouble(i -> i);

LongStream stream = IntStream.range(1, 5).mapToLong(i -> i);  

Moving on, let’s try out some of the matching functions

Let’s start by using matchAny to confirm that a certain range contains at least one even number.

IntStream.range(1, 5).anyMatch(i -> i % 2 == 0);  
// > true

matchAny will check if a predicate holds for at least one of the elements in the stream.

We also have two other match functions, matchNone and matchAll, that should return false for this predicate.

IntStream.range(1, 5).allMatch(i -> i % 2 == 0);  
// > false

IntStream.range(1, 5).noneMatch(i -> i % 2 == 0);  
// > false

Great!

Let’s now use the filter function to filter all the even numbers, then confirm that the filter did it’s job by using allMatch to make sure all numbers are even. Let’s also use noneMatch to make sure we can’t find any odd numbers.

IntStream.range(1, 5)  
    .filter(i -> i % 2 == 0)
    .allMatch(i -> i % 2 == 0);
// > true

IntStream.range(1, 5)  
    .filter(i -> i % 2 == 0)
    .noneMatch(i -> i % 2 != 0);
// > true

IntStream contains functions for fetching the max and min value

IntStream.range(1, 5).max().getAsInt();  
// > 4
IntStream.range(1, 5).min().getAsInt();  
// > 1

Both these methods and a lot of the other functions that returns one element, will return anOptionalInt.

OptionalInt, like Optional, gives some great higher-order functions that are abstracting away the null checks. Since that’s not the topic of this post, we’ll just fetch the int value assuming it’s there.

IntStream also offers the excellent reduce function

IntStream.range(1, 5).reduce(1, (x, y) -> x * y)  
// > 24

Here we reduce the stream by multiplying all the elements.

Concurrency

Another great thing about the Stream API, is that you can work on elements in parallel.

Let’s say we have a heavy operation that we want to execute four times.

IntStream.range(1, 5).parallel().forEach(i -> heavyOperation());  

parallel will execute heavyOperation in parallel for all the elements in the stream. Thanks to thisparallel, we can potentially save a great amount of time, with very little effort.