<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    有多好用?
    在任何窗口,只要敲Alt+space,就會激活launchy的小窗口,比如說你想運行firefox,直接敲firefox,firefox就會被運行了,比用書標點快多了,是吧?還有自動補全和提示。想打開文件夾?沒問題,直接在launchy的窗口里輸入地址就好了。甚至于網頁也是ok的。在小窗口里輸入http://www.tkk7.com/stingh711/就會直接到我的blog上啦(誰會記得這么長的...不過常用的網站就很快了)
    launchy默認的只到Start Menu目錄下面搜索.lnk文件,如果想通過launchy運行其他程序,比如說我常用的eclipse,該怎樣做呢?首先,在launchy的窗口上右鍵,選Directories, 然后加入eclipse的目錄,并在File Types里面加入.exe,這樣launchy就會搜到eclipse了。
    是不是真的很好用呢?趕快到http://www.launchy.net/上去下載吧。

    Technorati Tags:

    Technorati :

    posted @ 2007-09-29 16:52 django 閱讀(331) | 評論 (0)編輯 收藏
     
    發覺我還真是個不能堅持的人。一直覺得應該好好寫好一個blog,在用了blogjava之后,又用了donews,百度的blog,donews的把帳號忘記了,百度的好像不支持blog editor,而且...在百度上面的人感覺都是小孩子,實在是不適合我用...今天又到blogjava上面一看,發覺原來留下來的文章訪問量還挺高,決定還是用這兒好了。

    有的時候,在過很久來再來看以前寫的東西,發覺寫的還真是不太好,又沒有心情去修改(寫blog是要心情的,對吧?)以后寫,一定要好好醞釀。希望可以堅持下去。

    Blogged with Flock

    Tags:

    posted @ 2007-09-29 16:23 django 閱讀(297) | 評論 (1)編輯 收藏
     

    Hibernate.groovy


    import ?org.hibernate.cfg.Configuration
    import ?org.hibernate.Session
    import ?org.hibernate.SessionFactory
    import ?org.hibernate.Transaction
    import ?org.hibernate.tool.hbm2ddl.SchemaUpdate

    class ?Hibernate?{
    ????def?
    static ?sessionFactory
    ???
    static ?{?
    ???????
    try ?{?
    ??????????? Configuration?cfg?
    = ? new ?Configuration()
    ??????????? cfg.configure()????????????
    ???????????
    new ?SchemaUpdate(cfg).execute( true ,? true )??????
    ??????????? sessionFactory?
    = ?cfg.buildSessionFactory()????
    ??????? }?
    catch ?(Exception?e)?{?????
    ??????????? e.printStackTrace()??????
    ??????? }????
    ??? }????

    ????Hibernate()?{}???

    ????
    private ?Session?getSession()?{????
    ????????
    return ?sessionFactory.openSession()????
    ????}????

    ????Object?execute(closure)?{???????
    ????????def?s?
    = ?getSession()????????
    ????????????def?tr?
    = ? null ????????
    ????????????def?result?
    = ? null ????????
    ????????????
    try ?{????????????
    ????????????????tr?
    = ?s.beginTransaction()??????????
    ????????????????????result?
    = ?closure.call(s)???????
    ????????????????????tr.commit()??????
    ????????????}?
    catch ?(Exception?e)?{?????
    ????????????????e.printStackTrace()??????
    ????????????????????
    if ?(tr? != ? null )?{?????
    ????????????????????????tr.rollback()????
    ????????????????????}????????
    ????????????}?
    finally ?{?????
    ????????????????s.close()???
    ????????????}????????
    ????????
    return ?result???
    ????}????

    ????
    void ?saveOrUpdate(obj)?{
    ????????def?saveClosure?
    = ?{?s? -> ?s.saveOrUpdate(obj)?}??????
    ????????execute(saveClosure)????
    ????}????

    ????List?executeQuery(hql)?{?????
    ????????execute({?s?
    -> ?s.createQuery(hql).list()?})???
    ????}????

    ????List?executeQuery(hql,?parameters)?{????
    ????????def?query?
    = ?{?s? -> ????????
    ????????????def?q?
    = ?s.createQuery(hql)????????
    ????????????????
    if ?(parameters? != ? null )?{?????????
    ????????????????????
    for ?(i?in? 0 ..parameters.size() - 1 )?{???????
    ????????????????????????q.setParameter(i,?parameters[i])???????
    ????????????????????}????????????
    ????????????????}????????????
    ????????????q.list()???????
    ????????}????????
    ????????execute(query)????
    ????}????

    ????def?get(clazz,?id)?{????
    ????????
    return ?execute({?s? -> ?s.get(clazz,?id)?})???
    ????}????

    ????
    void ?delete(obj)?{???????
    ????????execute({?s?
    -> ?s.delete(obj)?})???
    ????}
    }

    Instead of interface, I use Closure for callback

    Blogged with Flock

    Tags:

    posted @ 2006-12-20 22:54 django 閱讀(474) | 評論 (0)編輯 收藏
     

    這兩天在寫一個tr069的simulator,原理很簡單啦,用httpclient模擬tr069的client端,發送soap message到我們的acs server.

    發送soap message的代碼如下:

    public class MessageSender {
    /**
    * Logger for this class
    */
    private static final Log logger = LogFactory.getLog(MessageSender.class);

    private HttpClient httpClient;
    private PostMethod postMethod;
    private MessageFactory messageFactory;
    private String url;
    private NameValuePair sessionId;

    public MessageSender(String ip){
    this.httpClient = new HttpClient();

    try {
    this.messageFactory = MessageFactory.newInstance();
    } catch (SOAPException e) {
    logger.error(e.getMessage());
    }

    this.url = generateRequestUrl(ip);
    }

    private String generateRequestUrl(String ip) {
    return "http://" + ip + ":8080/vantage/TR069";
    }

    public SOAPMessage sendMessage(SOAPMessage input) throws IOException, SOAPException {
    this.postMethod = new PostMethod(this.url);
    byte[] dataAsBytes = null;

    if (input == null) {
    logger.debug("Send a empty post");
    dataAsBytes = new byte[0];
    } else {

    ByteArrayOutputStream data = new ByteArrayOutputStream();
    input.writeTo(data);
    dataAsBytes = data.toByteArray();
    }

    RequestEntity entity = new ByteArrayRequestEntity(dataAsBytes);
    this.postMethod.setRequestEntity(entity);

    if (this.sessionId != null) {
    this.postMethod.addParameter(this.sessionId);
    }

    this.httpClient.executeMethod(this.postMethod);

    sessionId = this.postMethod.getParameter("SessionID");

    InputStream in = this.postMethod.getResponseBodyAsStream();

    if (null == in) {
    return null;
    }

    return this.messageFactory.createMessage(null, in);
    }
    }

    最初的code里面,只有一個PostMethod,這樣每次會一直keep一個http連接.因為在server端,只直接用http session來保存server的狀態的,所以必須要是保持是一個session.用一個PostMethod可以做到這點.不過奇怪的是,在發第二次請求的時候,怎么都拿不到http connection.也不知道是不是httpclient的bug.后來才每次調用都重新create一個PostMethod,但是把第一次得到的sessionID add進去.

    posted @ 2006-12-18 23:30 django 閱讀(5687) | 評論 (0)編輯 收藏
     

    所有雙向的關聯必須有一端被設置為inverse.在一對多關聯中,它必須代表多的一端.在多對多中,可以任意選取一端.

    inverse會影響到save時候的行為。如果一端的inverse設為true,則save應該在另一端進行

    posted @ 2006-12-11 23:14 django 閱讀(288) | 評論 (0)編輯 收藏
     

    Introduction

    The Java language gives you all the room you need to write code that would be very difficult for others to understand. Java also permits you to write code that is very easy to understand. Most development teams would prefer the latter.

    A style guide provides provides a map so that the code generated by a group of programmers will be consistent and, therefore, easier to read and maintain. Many people do not care for the style guide offered by Sun. This document is one alternative.

    This document covers most areas where there could be confusion or difference of opinion. Areas that have never been a problem in our experience are undocumented.

    1 - Formatting

      1.1 - Indentation

      All indents are four spaces. All indenting is done with spaces, not tabs. (examples and reasoning)
      Matching braces always line up vertically in the same column as their construct. (examples)
      All if, while and for statements must use braces even if they control just one statement. (reasoning and examples)

      1.2 - Spacing

      All method names should be immediately followed by a left parenthesis.
      All array dereferences should be immediately followed by a left square bracket.
      Binary operators should have a space on either side.
      Unary operators should be immediately preceded or followed by their operand.
      Commas and semicolons are always followed by whitespace.
      All casts should be written with no spaces.
      The keywords if, while, for, switch, and catch must be followed by a space.
      (examples)

      1.3 - Class Member Ordering

      class Order
      {
      // fields

      // constructors

      // methods
      }

      1.4 - Maximum Line Length

      Avoid making lines longer than 120 characters. (reasoning)

      1.5 - Parentheses

      Parentheses should be used in expressions not only to specify order of precedence, but also to help simplify the expression. When in doubt, parenthesize.

    2 - Identifiers

    All identifiers use letters ('A' through 'Z' and 'a' through 'z') and numbers ('0' through '9') only. No underscores, dollar signs or non-ascii characters.

      2.1 - Classes and Interfaces

      All class and interface identifiers will use mixed case. The first letter of each word in the name will be uppercase, including the first letter of the name. All other letters will be in lowercase, except in the case of an acronym, which will be all upper case. (examples)

      2.2 - Packages

      Package names will use lower case characters only. Try to keep the length under eight (8) characters. Multi-word package names should be avoided. (examples)

      2.3 - All Other Identifiers

      All other identifiers, including (but not limited to) fields, local variables, methods and parameters, will use the following naming convention. This includes identifiers for constants.

      The first letter of each word in the name will be uppercase, except for the first letter of the name. All other letters will be in lowercase, except in the case of an embedded acronym, which will be all uppercase. Leading acronyms are all lower case. (examples and reasoning)

      Hungarian notation and scope identification are not allowed. (reasoning and examples)

      Test code is permitted to use underscores in identifiers for methods and fields. (reasoning and examples)

    3 - Coding

      3.1 - Constructs to Avoid

      Never use do..while. (examples and reasoning)
      Never use return in the middle of a method. (reasoning)
      Never use continue. (reasoning)
      Never use break other than in a switch statement. (reasoning)

      3.2 - Do Not Compound Increment Or Decrement Operators

      Use a separate line for an increment or decrement. (examples and reasoning)

      Never use pre-increment or pre-decrement (examples and reasoning)

      3.3 - Initialization

      Declare variables as close as possible to where they are used. (examples)

      3.4 - Access

      All fields must be private, except for some constants.

    4 - Self-Documenting Code

    				"Any fool can write code that a computer can understand.
    Good programmers write code that humans can understand."
          --- Martin Fowler, Refactoring: Improving the Design of Existing Code

    Rather than trying to document how you perform a complex algorithm, try to make the algorithm easier to read by introducing more identifiers. This helps in the future in case the algorithm changes but someone forgets to change the documentation. (examples and reasoning)


    原文鏈接在 http://www.javaranch.com/style.jsp

    posted @ 2006-11-27 16:18 django 閱讀(415) | 評論 (0)編輯 收藏
     
    Pro spring
    The art of project management
    Analyse patterns
    posted @ 2006-11-23 23:55 django 閱讀(315) | 評論 (0)編輯 收藏
     
    First of all, add a bean in spring's configuration files like this:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderconfigurer">
    ??? <property name="locations">
    ??????? <list>
    ??????????? <value>...property files</value>
    ??????? </list>
    ??? </property>
    </bean>
    Put the property files under classpath, then you can use ${property name} to reference properties in your property files in your spring configuration files.
    Also, system properties and properties sent it by -D are also available through ${property name}.
    posted @ 2006-11-23 23:53 django 閱讀(498) | 評論 (0)編輯 收藏
     
    1. mysql.exe -uroot -ptest -e "source create.sql"
    To be continued...
    posted @ 2006-11-22 17:42 django 閱讀(301) | 評論 (0)編輯 收藏
     

    在項目中,經常要用到讀系統文件.在項目的遺留代碼中,都是在系統啟動是傳入一個APP_HOME,然后根據相對路徑去讀文件.這樣做的缺點是比較難測試,而且自動化的測試更難.

    比如說有這樣一個類Server,要根據server.properties來初始化,一開始的代碼是這樣的:

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.Properties;

    /**
    * @author sting
    */
    public class Server {
    private static final String FILE = "conf" + File.separator + "server.properties";

    public void initial() throws IOException {
    FileInputStream in = new FileInputStream(System.getProperty("APP_HOME") + File.separator + FILE);
    Properties properties = new Properties();
    properties.load(in);
    // initial
    }
    }

    文件路徑和文件名都是hard code,很難測試. 我們首先把initial()重構一下,代碼如下:


    public void initial(InputStream in) throws IOException {
    Properties properties = new Properties();
    properties.load(in);
    // initial
    }

    至少,測試時,我們可以傳進來自己的InputStream,也可以方便的時候測試用的server.properties,或者干脆使用內聯的文件,代碼如下:

    class ServerTest extends TestCase {
    private Server server;

    public void setUp() throws Exception {
    this.server = new Server();
    }

    public void testInitial() throws Exception {
    String serverProperties = "port=8080\n" +
    "run_mode=normal";
    InputStream in = new ByteArrayInputStream(serverProperties.getBytes());

    this.server.initial(in);
    // assert
    }
    }

    但是,在實際工作的代碼中,文件名和路徑依然要hard code進代碼中.這時,我們可以使用spring中的Resource接口來進一步改進我們的代碼.

    public class Server {
    private Resource resource;

    public void setResource(Resource r) {
    this.resource = r;
    }

    public void initial() throws IOException {
    Properties properties = new Properties();
    properties.load(this.resource.getInputStream());
    // initial
    }
    }

    再加一段spring的配置文件:

    <beans>
    <bean id="server" class="Server">
    <property name="resource" value="classpath:server.properties"/>
    </bean>
    </beans>

    這樣,Server的代碼完全與文件的具體路徑和文件名無關,僅僅用配置文件就可以指定,表達更清楚,也更易于測試.

    當然,僅限于已經使用spring的項目.

    posted @ 2006-11-19 11:54 django 閱讀(3679) | 評論 (0)編輯 收藏
    僅列出標題
    共12頁: First 上一頁 4 5 6 7 8 9 10 11 12 下一頁 
     
    主站蜘蛛池模板: 国产亚洲一区二区精品| 香蕉成人免费看片视频app下载 | 亚洲欧洲日本精品| 亚洲精品国产日韩无码AV永久免费网| 最近高清中文字幕无吗免费看| 高清永久免费观看| 男女男精品网站免费观看| 国产色在线|亚洲| 久久亚洲日韩看片无码| 亚洲国产综合无码一区 | 男女猛烈无遮掩视频免费软件| 亚洲日日做天天做日日谢| 久久精品亚洲精品国产色婷 | 豆国产96在线|亚洲| 亚洲熟妇无码一区二区三区导航| 中文字幕亚洲精品| 亚洲欧洲一区二区| 亚洲国产精品久久久天堂| 国产成人亚洲精品91专区手机| 免费在线观看你懂的| 日本免费一二区在线电影| 色视频色露露永久免费观看| 毛片网站免费在线观看| 国产日本一线在线观看免费| 亚洲高清免费在线观看| 在线观看成人免费视频不卡| 1000部国产成人免费视频| 1000部禁片黄的免费看| 精品女同一区二区三区免费站| 最近中文字幕电影大全免费版| 久久99热精品免费观看动漫| 一级毛片aaaaaa免费看| 少妇太爽了在线观看免费视频| 亚洲精品免费视频| 亚洲精品视频在线观看免费| 麻豆高清免费国产一区| 99爱在线精品免费观看| 亚洲人成网站免费播放| 免费无遮挡无码视频网站| 免费看国产一级片| 亚洲中文久久精品无码|