2015年1月26日 星期一
[Software Development] Terminology: Boilerplate
http://en.wikipedia.org/wiki/Boilerplate_%28text%29
http://en.wikipedia.org/wiki/Boilerplate_code
Differences between boilerplate and template?
From : http://www.webopedia.com/TERM/B/boilerplate.html
Template: describes the layout & style information
Boilerplate: actual text & graphics
http://whatis.techtarget.com/definition/boilerplate
boilerplate : actual text / code
template: fill-in-the-blanks boilerplate
http://en.wikipedia.org/wiki/Boilerplate_code
Differences between boilerplate and template?
From : http://www.webopedia.com/TERM/B/boilerplate.html
Template: describes the layout & style information
Boilerplate: actual text & graphics
http://whatis.techtarget.com/definition/boilerplate
boilerplate : actual text / code
template: fill-in-the-blanks boilerplate
[MongoDB] When name goes wrong
db.collectionName.find()
> work
db.collectionName.renameCollection("1")
> operation ok
db.1.find()
> error, illegal collection name
How to rollback?
db.getCollection("1").find()
> work
db.getCollection("1").renameCollection("properCollectionName")
> done
http://blog.onetechnical.com/2013/05/22/how-to-drop-a-mongodb-collection-with-an-illegal-name/
> work
db.collectionName.renameCollection("1")
> operation ok
db.1.find()
> error, illegal collection name
How to rollback?
db.getCollection("1").find()
> work
db.getCollection("1").renameCollection("properCollectionName")
> done
http://blog.onetechnical.com/2013/05/22/how-to-drop-a-mongodb-collection-with-an-illegal-name/
2015年1月22日 星期四
[Java Groovy] Convert Array or Object to String
def numbers = [0, 1, 2, 3, 4, 5] as Integer[]
assert '0 x 1 x 2 x 3 x 4 x 5' == numbers.join(' x ')
def objects = [new URL('http://www.mrhaki.com'), 'mrhaki', new Expando(name: 'mrhaki'), new Date(109, 10, 10)]
assert 'http://www.mrhaki.com,mrhaki,{name=mrhaki},Tue Nov 10 00:00:00 UTC 2009' == objects.join(',')
http://mrhaki.blogspot.hk/2009/10/groovy-goodness-join-elements-to-string.html
2015年1月15日 星期四
2015年1月14日 星期三
[Spring] [MongoDB] MongoDB Collection Event Listener
Event Listeners:
How to Use:
http://www.27programs.com/2013/10/27/mongodb-collection-event-listeners-spring-data/
http://maciejwalkowiak.pl/blog/2012/05/09/sorting-spring-data-mongodb-collections-using-orderby/
http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.html
- onBeforeConvert(E document)
- onAfterConvert(DbObject dbo, E document)
- onBeforeSave(E document)
- onAfterSave( E collection, DbObject dbo)
- ...
How to Use:
Step 1: Write Java class
package com.tsp.event;
import javax.annotation.Resource;
import org.springframework.data.mongodb.core.mapping.event.
AbstractMongoEventListener; // line broken for rendering
import com.mongodb.DBObject;
/**
* @author siva mondi
*
*/
public class UserEventListener extends AbstractMongoEventListener<User> {
@Override
public void onBeforeConvert(User user) {
}
@Override
public void onBeforeSave(User user, DBObject dbo) {
}
@Override
public void onAfterSave(User user, DBObject dbo) {
}
@Override
public void onAfterLoad(DBObject dbo) {
}
@Override
public void onAfterConvert(DBObject dbo, User user) {
}
}
|
Step 2: Register Event Listener in Spring XML
<!-- All The Event Listeners -->
<bean class="com.tsp.event.UserEventListener" />
|
http://www.27programs.com/2013/10/27/mongodb-collection-event-listeners-spring-data/
http://maciejwalkowiak.pl/blog/2012/05/09/sorting-spring-data-mongodb-collections-using-orderby/
http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.html
[MongoDB] ObjectId to Timestamp Converter
Test data (ObjectId): 54b37110f441a40ce4239497
Return (ISO Timestamp): 2015-01-12T07:00:32.000Z
* Note that _id stores the timestamp to second only, no millisecond value stored :(
http://steveridout.github.io/mongo-object-time/
Return (ISO Timestamp): 2015-01-12T07:00:32.000Z
* Note that _id stores the timestamp to second only, no millisecond value stored :(
http://steveridout.github.io/mongo-object-time/
[JPA] @transient
transient : passing with time; remaining in a place only a brief of time
http://www.thefreedictionary.com/transient
@transient : a field not to be persisted in database
http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation
http://www.thefreedictionary.com/transient
@transient : a field not to be persisted in database
http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation
2015年1月13日 星期二
[Java] HashMap, TreeMap and LinkedHashMap
HashMap - random ordering, after each new insertion
TreeMap - natural ordering by key
LinkedHashMap - ordering by insertion order
http://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap
TreeMap - natural ordering by key
LinkedHashMap - ordering by insertion order
http://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap
2015年1月8日 星期四
[Spring Security] Get Current User
To get the current authentication:
Method 1
http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/
Method 1
Authentication auth = SecurityContextHolder.getContext().getAuthentication();Method 2
String name = auth.getName(); //get logged in username
User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();String name = user.getUsername(); //get logged in username
http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/
2015年1月6日 星期二
[Spring Security] About CSRF
What is CSRF?
Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf[1]) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.
http://en.wikipedia.org/wiki/Cross-site_request_forgery
Some descriptions are at the bottom of the page:
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/helloworld.html
You can also read (before conclusion):
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
Some descriptions are at the bottom of the page:
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/helloworld.html
You can also read (before conclusion):
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
For Spring Security, notice that one description says:
" If you were not using Spring MVC taglibs or Thymeleaf, you can access the CsrfToken on the ServletRequest using the attribute _csrf. "
2015年1月2日 星期五
[Spring MVC] Some references for using Spring Security / MVC for web app
Spring Security
http://pro.ctlok.com/2010/02/spring-security-3.html
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
Spring Web MVC
http://krams915.blogspot.hk/2010/12/spring-3-mvc-using-modelattribute-in.html
http://www.javacodegeeks.com/2013/04/spring-mvc-hibernate-maven-crud-operations-example.html
http://examples.javacodegeeks.com/enterprise-java/spring/mvc/spring-mvc-form-handling-example/#code
Hindrance of using jsp:
Some of the related .jar files (more precisely .tld files with those jars) have to put into "/WEB-INF/lib", though they are included in the main application's "dist"(or "target") folder.
http://pro.ctlok.com/2010/02/spring-security-3.html
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
Spring Web MVC
http://krams915.blogspot.hk/2010/12/spring-3-mvc-using-modelattribute-in.html
http://www.javacodegeeks.com/2013/04/spring-mvc-hibernate-maven-crud-operations-example.html
http://examples.javacodegeeks.com/enterprise-java/spring/mvc/spring-mvc-form-handling-example/#code
Hindrance of using jsp:
Some of the related .jar files (more precisely .tld files with those jars) have to put into "/WEB-INF/lib", though they are included in the main application's "dist"(or "target") folder.
訂閱:
文章 (Atom)
[康復路] 試完又試
見了醫生,因為血色素又變低了,醫生想檢查是否「缺鐵」為成因,檢查又檢查…… 感覺有些麻煩……又抽血,又要留樣本…… 令我回想起當日入院的時光,因為一些原因,留樣本只需留一次,免卻留三次的麻煩;現在每天都要留一次,連續三天。每天早上就要跑醫院一趟再上班。 幸好也完成了。 第二次抽血...
-
裝水喉要用銅喉, 不要鐵喉, 熱水冷水都是。 裝煤氣喉因化學原理要用特製鐵喉, 不能用銅喉。如果是用煤氣熱水爐, 就要搵煤氣公司整。 用煤氣熱水爐拆要找煤氣公司, 清拆費$165公價, 安裝費一般無特別改位公價$475, 如煤氣公司check到有漏氣, 要換喉, 可在牆外...
-
Wow, 又一突破,自己換水龍頭 話說尋晚搭完飛機返到香港,第一時間拎曬行李喼d衫出黎洗,執好d野後,想沖埋涼一機過洗曬d衫,但唔知係咪去完旅行太興奮,開完個水龍頭之後點關都關唔到,感覺到裏面有d野斷左/鬆左/甩左咁,唯有沖完涼即刻放個花灑落水桶度,即刻拿拿淋去關水制。。。我...
-
8 January 2012 at 15:16 前言 話說12月左右, 考試前幾日開始左下面隻智慧齒異常的痛, D牙肉好腫, 所以去左POLY睇牙。之前E生都話過我隻智慧齒斜生, 頂住前面隻牙, 一來容易SIP食物, 2來可能影響前面隻牙會蛀, 所以叫我最好...
-
What is Interceptor? http://viralpatel.net/blogs/spring-mvc-interceptor-example/ Add autowired interceptors from Java Config http://stac...
-
Source: http://www.hket.com/eti/article/913472db-26f6-465a-b643-c5daaba82f4b-406134?category=green_news&source=print&printable=tru...