Skip to content

Instantly share code, notes, and snippets.

View yanhua365's full-sized avatar

yanhua365 yanhua365

View GitHub Profile
@yanhua365
yanhua365 / sublimetext-coffeescript-highlight.md
Created September 3, 2014 05:37
sublimetext 对coffeesciprt高亮
@yanhua365
yanhua365 / HTTP-Content-Type.md
Last active August 29, 2015 14:05
各种Content-Type的写法

application/x-www-form-urlencoded

application/x-www-form-urlencoded

application/json; charset=UTF-8

@yanhua365
yanhua365 / http-status-401-vs-403.md
Created August 27, 2014 09:10
HTTP的状态码 —— 401和403的区别

A clear explanation from Daniel Irvine:

401 Unauthorized, the HTTP status code for authentication errors. And that’s just it: it’s for authentication, not authorization. Receiving a 401 response is the server telling you, “you aren’t authenticated–either not authenticated at all or authenticated incorrectly–but please reauthenticate and try again.” To help you out, it will always include a WWW-Authenticate header that describes how to authenticate.

This is a response generally returned by your web server, not your web application.

It’s also something very temporary; the server is asking you to try again.

So, for authorization I use the 403 Forbidden response. It’s permanent, it’s tied to my application logic, and it’s a more concrete response than a 401.

@yanhua365
yanhua365 / inline-user-service.xml
Last active August 29, 2015 14:05
Spring Security的各种User Service
<authentication-manager>
<authentication-provider>
<user-service>
<user name="sa" password="sa" authorities="ROLE_USER,ROLE_ADMIN,ROLE_UC_ADMIN" />
</user-service>
</authentication-provider>
</authentication-manager>
@yanhua365
yanhua365 / tomcat-get-utf8-server.xml
Created July 28, 2014 02:27
Tocmat里解决中文乱码的问题
<!-- 加上URIEncoding解决GET请求的中文问题 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"
/>
@yanhua365
yanhua365 / TableExistsInDb.java
Created July 24, 2014 01:08
判断数据库里有没有某个表,没有就创建
private boolean tableExistsInDb(String tableName){
Connection conn = null;
ResultSet tabs = null;
try {
conn = jdbcTemplate.getDataSource().getConnection();
DatabaseMetaData dbMetaData = conn.getMetaData();
String[] types = { "TABLE" };
tabs = dbMetaData.getTables(null, null, tableName, types);
if (tabs.next()) {
return true;
@yanhua365
yanhua365 / FileFilterSample.groovy
Created July 23, 2014 08:49
Java和Groovy里使用FilenameFilter来查找文件 (from: http://groovycode.com/file/filename_filter)
println new File("/tmp").list({d, f-> f ==~ /.*.txt/ } as FilenameFilter)
@yanhua365
yanhua365 / groovy-ant-svn.md
Last active August 29, 2015 14:04
用Groovy和Ant操作Subversion
@yanhua365
yanhua365 / servlet3_async_process
Created July 14, 2014 08:39
解释Servlet3.0中的异步功能的处理过程
Once your doGet method ends, the response is complete and sent back to the client. Your thread may or may not still be running, but it can't change the response any longer.
What the new async feature in Servlet 3.0 does, is that it allows you to free the request thread for processing another request. What happens is the following:
RequestThread: |-- doGet() { startAsync() } // Thread free to do something else
WorkerThread: |-- do heavy processing --|
OtherThread: |-- send response --|
The important thing is that once RequestThread has started asynchronous processing via a call to startAsync(...), it is free to do something else. It can accept new requests, for example. This improves throughput.
@yanhua365
yanhua365 / LoggerDebugOrError.java
Created June 23, 2014 08:37
当出现异常的时候,根据是否是debug来决定是否打印异常
StringBuilder msg = new StringBuilder();
msg.append("Could not refresh JMS Connection for destination '");
msg.append(getDestinationDescription()).append("' - retrying in ");
msg.append(this.recoveryInterval).append(" ms. Cause: ");
msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
if (logger.isDebugEnabled()) {
logger.error(msg, ex);
}
else {
logger.error(msg);