yangxiang

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  8 随笔 :: 0 文章 :: 73 评论 :: 0 Trackbacks

2009年7月17日 #

[英文出处]:21 Laws of Computer Programming
[译文出处]:外刊IT评论


任何一个有经验的程序员都知道,软件开发遵循着一些不成文的法则。然而,如果你不遵循这些法则也并不意味着会受到惩罚;相反,有时你还会获得意外的好处。下面的就是软件编程中的21条法则:

  1. 任何程序一旦部署即显陈旧。
  2. 修改需求规范来适应程序比反过来做更容易。
  3. 一个程序如果很有用,那它注定要被改掉。
  4. 一个程序如果没用,那它一定会有很好的文档。
  5. 任何程序里都仅仅只有10%的代码会被执行到。
  6. 软件会一直膨胀到耗尽所有资源为止。
  7. 任何一个有点价值的程序里都会有至少一个bug。
  8. 原型完美的程度跟审视的人数成反比,反比值会随着涉及的资金数增大。
  9. 软件直到被变成产品运行至少6个月后,它最严重的问题才会被发现。
  10. 无法检测到的错误的形式无限多样,而能被检测到的正好相反,被定义了的十分有限。
  11. 修复一个错误所需要投入的努力会随着时间成指数级增加。
  12. 软件的复杂度会一直增加,直到超出维护这个程序的人的承受能力。
  13. 任何自己的程序,几个月不看,形同其他人写的。
  14. 任何一个小程序里面都有一个巨大的程序蠢蠢欲出。
  15. 编码开始的越早,花费的时间越长。
  16. 一个粗心的项目计划会让你多花3倍的时间去完成;一个细心的项目计划只会让你多花2倍的时间。
  17. 往大型项目里添加人手会使项目更延迟。
  18. 一个程序至少会完成90%,但永远完成不了超过95%。
  19. 如果你想麻烦被自动处理掉,你得到的是自动产生的麻烦。
  20. 开发一个傻瓜都会使用的软件,只有傻瓜愿意使用它。
  21. 用户不会真正的知道要在软件里做些什么,除非使用过。
posted @ 2010-09-30 09:50 『 Y X 』 阅读(242) | 评论 (0)编辑 收藏

Eclipse快捷键按了没有反应可能是和其他程序设置的快捷键冲突了,如果确认没有冲突,可以看看是不是如下问题。

在工具栏(Toolbars)上面点击右键,选择“Customize Perspective...”

看看Command Group Availability 里面有没有勾选你所设置的快捷键的分组,如果没有就勾上,再试试快捷键能否使用。


posted @ 2010-08-24 09:55 『 Y X 』 阅读(3415) | 评论 (0)编辑 收藏

    当为遗留系统加入spring时,经典问题就是遗留系统需要引用spring管理的bean。幸好spring有机制可以处理这些。

    建一个类实现ApplicationContextAware接口,有一个引用ApplicationContext的静态成员,然后,遗留系统需要引用spring管理的bean的地方,使用这个类。

1.比如:我这里建一个SpringContext类

package net.blogjava.chenlb;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 此类可以取得Spring的上下文.
 * Spring 使new方法创建的对象可以引用spring管理的 bean.
 * 2007-10-18 上午11:12:33
 * 
@author chenlb
 
*/
public class SpringContext implements ApplicationContextAware {

    
protected static ApplicationContext context;
    
    
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context 
= applicationContext;
    }

    
public static ApplicationContext getContext() {
        
return context;
    }
}


2.然后在spring配置文件里加

<bean id="springContext" class="net.blogjava.chenlb.SpringContext"></bean>


3.其它类中引用

MyBean myBean = (MyBean) SpringContext.getContext().getBean("myBean");


4.如果老是写SpringContext.getContext().getBean("...");麻烦,可以建一个工厂类来返回你要 的bean

package net.blogjava.chenlb;

public class MyServerFactory {

    
public static MyBean1 getMyBean1() {
        
return (MyBean1) SpringContext.getContext().getBean("myBean1");
    }
}



原文:http://chenlb.javaeye.com/blog/135897

posted @ 2010-06-15 19:22 『 Y X 』 阅读(292) | 评论 (0)编辑 收藏

<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%
    WebApplicationContext context =    WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
    SomeBean bean=(SomeBean)context.getBean(SomeBean.class);
%>

posted @ 2010-06-15 19:18 『 Y X 』 阅读(405) | 评论 (0)编辑 收藏

1、xml.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
<book>
    
<title>XML与JSP</title>
    
<chapter>
        
<title>第1章 认识XML与DTD</title>
        
<section>
            
<title>XML的产生</title>
            
<example>HelloWorld.html</example>
        
</section>
    
</chapter>
    
<chapter>
        
<title>第2章 XML名称空间</title>
        
<section>
            
<title>名称空间在元素和属性中的应用</title>
            
<section>
                
<title>名称空间在元素中的应用</title>
                
<example>people.xml</example>
            
</section>
            
<section>
                
<title>缺省名称空间</title>
                
<example>book.xml</example>
            
</section>
            
<section>
                
<title>名称空间在属性中的应用</title>
                
<example>book2.xml</example>
            
</section>
        
</section>
        
<section>
            
<title>名称空间和DTD</title>
        
</section>
    
</chapter>
</book>

2、xsl.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
<xsl:output method="html" version="1.0" encoding="utf-8" standalone="yes"/>
    
<xsl:template match="/">
        
<html>
            
<head>
                
<title>使用XML+XSLT生成的HTML文件</title>
            
</head>
            
<body>
                
<xsl:apply-templates select="book"/>
            
</body>
        
</html>
    
</xsl:template>
    
<xsl:template match="chapter">
        
<br/>
        
<br/>
        
<xsl:value-of select="./title"/>
        
<xsl:apply-templates select="./section"/>
    
</xsl:template>
    
<xsl:template match="chapter/section">
        
<br/>
        
<br/>
        
<xsl:text>    </xsl:text>
        
<!--<xsl:number format="1. " level="multiple"/>-->
        
<xsl:number format="1. " level="multiple" count="chapter | section" from="book"/>
        
<xsl:value-of select="./title"/>
        
<xsl:apply-templates select="./section"/>
    
</xsl:template>
    
<xsl:template match="chapter/section/section">
        
<br/>
        
<br/>
        
<xsl:text>        </xsl:text>
        
<!--<xsl:number format="1. " level="multiple"/>-->
        
<xsl:number format="1. " level="multiple" count="chapter | section" from="book"/>
        
<xsl:value-of select="./title"/>
        
<xsl:number value="123456789" grouping-separator="," grouping-size="3"/>
    
</xsl:template>
</xsl:stylesheet>

3、java.java
package test;

import java.io.File;
import java.io.IOException;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.junit.Test;

public class Train {
    @Test
    
public void test() throws IOException {
        String xmlFileName 
= "d:/test/xml.xml";
        String xslFileName 
= "d:/test/xsl.xsl";
        String htmlFileName 
= "d:/test/html.html";
        Train.Transform(xmlFileName, xslFileName, htmlFileName);
    }

    
public static void Transform(String xmlFileName, String xslFileName,
            String htmlFileName) {
        
try {
            TransformerFactory tFac 
= TransformerFactory.newInstance();
            Source xslSource 
= new StreamSource(xslFileName);
            Transformer t 
= tFac.newTransformer(xslSource);
            File xmlFile 
= new File(xmlFileName);
            File htmlFile 
= new File(htmlFileName);
            Source source 
= new StreamSource(xmlFile);
            Result result 
= new StreamResult(htmlFile);
            System.out.println(result.toString());
            t.transform(source, result);
        } 
catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } 
catch (TransformerException e) {
            e.printStackTrace();
        }
    }
}

4、html.html
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>使用XML+XSLT生成的HTML文件</title>
</head>
<body>
    XML与JSP
    
<br>
<br>第1章 认识XML与DTD<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;1.1. XML的产生
    
<br>
<br>第2章 XML名称空间<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;2.1. 名称空间在元素和属性中的应用<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1.1. 名称空间在元素中的应用123,456,789<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1.2. 缺省名称空间123,456,789<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1.3. 名称空间在属性中的应用123,456,789<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;2.2. 名称空间和DTD
</body>
</html>

5、效果
XML与JSP

第1章 认识XML与DTD

    1.1. XML的产生

第2章 XML名称空间

    2.1. 名称空间在元素和属性中的应用

        2.1.1. 名称空间在元素中的应用123,456,789

        2.1.2. 缺省名称空间123,456,789

        2.1.3. 名称空间在属性中的应用123,456,789

    2.2. 名称空间和DTD

posted @ 2009-08-11 17:05 『 Y X 』 阅读(5031) | 评论 (1)编辑 收藏

VIM中常用的替换模式总结。

0,:g/null/d

找到null的行并且删掉

1,简单替换表达式

替换命令可以在全文中用一个单词替换另一个单词:

:%s/four/4/g

“%” 范围前缀表示在所有行中执行替换。最后的 “g” 标记表示替换行中的所有匹配点。如果仅仅对当前行进行操作,那么只要去掉%即可

    如果你有一个象 “thirtyfour” 这样的单词,上面的命令会出错。这种情况下,这个单词会被替换成”thirty4″。要解决这个问题,用 “\<” 来指定匹配单词开头:

         :%s/\<four/4/g

显然,这样在处理 “fourty” 的时候还是会出错。用 “\>” 来解决这个问题:

         :%s/\<four\>/4/g

如果你在编码,你可能只想替换注释中的 “four”,而保留代码中的。由于这很难指定,可以在替换命令中加一个 “c” 标记,这样,Vim 会在每次替换前提示你:

         :%s/\<four\>/4/gc

2,删除多余的空格

要删除这些每行后面多余的空格,可以执行如下命令:

         :%s/\s\+$//

命令前面指明范围是 “%”,所以这会作用于整个文件。”substitute” 命令的匹配模式是

“\s\+$”。这表示行末($)前的一个或者多个(\+)空格(\s)。替换命令的 “to” 部分是空的:”//”。这样就会删除那些匹配的空白字符。

3,匹配重复性模式

星号项 “*” 规定在它前面的项可以重复任意次。因此:

         /a*

匹配 “a”,”aa”,”aaa”,等等。但也匹配 “” (空字串),因为零次也包含在内。星号 “*” 仅仅应用于那个紧邻在它前面的项。因此 “ab*” 匹配 “a”,”ab”,”abb”,”abbb”,等等。如要多次重复整个字符串,那么该字符串必须被组成一个项。组成一项的方法就是在它前面加 “\(”,后面加 “\)”。因此这个命令:

         /\(ab\)*

匹配: “ab”,”abab”,”ababab”,等等。而且也匹配 “”。

要避免匹配空字串,使用 “\+”。这表示前面一项可以被匹配一次或多次。

         /ab\+

匹配 “ab”,”abb”,”abbb”,等等。它不匹配 后面没有跟随 “b” 的 “a”。

要匹配一个可选项,用 “\=”。 例如:

         /folders\=

匹配 “folder” 和 “folders”。

4,指定重复次数

要匹配某一项的特定次数重复,使用 “\{n,m}” 这样的形式。其中 “n” 和 “m” 都是数字。在它前面的那个项将被重复 “n” 到 “m” 次 (|inclusive| 包含 “n” 和 “m”)。例如:

         /ab\{3,5}

匹配 “abbb”,”abbbb” 以及 “abbbbb”。

    当 “n” 省略时,被默认为零。当 “m” 省略时,被默认为无限大。当 “,m” 省略时,就表示重复正好 “n” 次。例如:

         模式            匹配次数

         \{,4}             0,1,2,3 或 4

         \{3,}             3,4,5,等等

         \{0,1}            0 或 1,同 \=

         \{0,}             0 或 更多,同 *

         \{1,}             1 或 更多,同 \+

         \{3}              3

5,多选一匹配

在一个查找模式中,”或” 运算符是 “\|”。例如:

         /foo\|bar

这个命令匹配了 “foo” 或 “bar”。更多的抉择可以连在后面:

         /one\|two\|three

匹配 “one”,”two” 或 “three”。

    如要匹配其多次重复,那么整个抉择结构须置于 “\(” 和 “\)” 之间:

         /\(foo\|bar\)\+

这个命令匹配 “foo”,”foobar”,”foofoo”,”barfoobar”,等等。

    再举个例子:

         /end\(if\|while\|for\)

这个命令匹配 “endif”,”endwhile” 和 “endfor”。

posted @ 2009-07-29 23:12 『 Y X 』 阅读(733) | 评论 (0)编辑 收藏

     摘要: Uploadify is a jQuery plugin that allows the easy integration of a multiple (or single) file uploads on your website. It requires Flash and any backend development language. An array of options allow for full customization for advanced users, but basic implementation is so easy that even coding novices can do it.
Uploadify是jQuery的插件,用于web的多文件(或单文件)上传。需要flash和后台程序支持。多种自定义选项适合于高级使用者,也可以做简单的最基本的实现,即使一个初学者也能完成。  阅读全文
posted @ 2009-07-29 15:01 『 Y X 』 阅读(48616) | 评论 (72)编辑 收藏

由于要做一个网络相册程序,想在浏览相册图片的时候能显示缩略图,点击缩略图可以显示大图,缩略图可翻页,并且相片路径是程序动态生成而不是在配置文件中写死的。

这种东西网上一大把,但是完全符合要求的确并不多,找了半天发现了Galleriffic,首先看界面就知道符合功能需求。



然后看看例子的代码,也很清晰,几个DIV,一个图片列表,适合代码的动态生成。当然他给的说明里面没有让加上CSS,其实还是需要添加的,自己也可以根据情况进行修改。

再看看亮点:
  • Smart image preloading after the page is loaded    //智能图片加载
  • Thumbnail navigation (with pagination)     //缩略图导航,带翻页
  • Support for bookmark-friendly URLs per-image     //为图片产生的URL适合收藏到收藏夹
  • Slideshow (with optional auto-updating url bookmarks)     //自动播放,并且播放时会自动更新地址栏地址
  • Events that allow for adding your own custom transition effects     //可以自己添加变换效果
  • Support for image captions     // 支持图片标题
  • Flexible configuration     //灵活的配置
  • Graceful degradation when javascript is not available     //无JavaScript时也比较友好
  • Support for multiple galleries per page     //支持单页面的多个相册集

    满足需求,优点不少,虽然没有时间测试所有声称的东西,但是大致试了一下,效果还不错。注意缩略图是指定的自己在硬盘上已经生成好的图片文件,而不是在页面中再来缩放的,据他的说法是这样对减小带宽占用有利,对用户浏览器的处理能力也要求更低,事实确实如此。加载几十张巨大的图片和几十张很小的缩略图,差别就很明显了。


    作品主页很简单,就放在下面把。

     


    Galleriffic

    A jQuery plugin for rendering fast-performing photo galleries

    Galleriffic was inspired by Mike Alsup's Cycle plugin, but with performance in mind for delivering a high volume of photos. This is my first experiment with jQuery, so I would love feedback on how to improve this plugin. I am not so great at spelling, and it was much later that I realized that the more appropriate spellings would be Gallerific or Gallerrific, but is too late now for a name change, so Galleriffic remains.

    Examples

    Features

    • Smart image preloading after the page is loaded
    • Thumbnail navigation (with pagination)
    • Support for bookmark-friendly URLs per-image
    • Slideshow (with optional auto-updating url bookmarks)
    • Events that allow for adding your own custom transition effects
    • Support for image captions
    • Flexible configuration
    • Graceful degradation when javascript is not available
    • Support for multiple galleries per page

    Usage

    1. Download the latest version of Galleriffic below and jQuery 1.2.6 or later (use other versions of jQuery at your own risk)
    2. Setup the script references in the header:
      <head>
          ...
          <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
          <script type="text/javascript" src="js/jquery.galleriffic.js"></script>
          ...
          </head>
                                  
    3. Add container elements to your page. All container elements are optional, so you may choose to not include an area (such as the loading or caption container elements). Here is an example of all the elements needed for a full-featured setup:
      <div id="controls"></div>
          <div id="loading"></div>
          <div id="slideshow"></div>
          <div id="caption"></div>
          <div id="thumbs">
          ... graceful degrading list of thumbnails (specific format specified below) ...
          </div>
                                  
    4. Within the thumbnails container element, build your graceful degrading unordered list of thumbnails linking to the image slides as such:
      <ul class="thumbs noscript">
          <li>
               <a class="thumb" href="path/to/slide" title="your image title">
                  <img src="path/to/thumbnail" alt="your image title again for graceful degradation" />
               </a>
                  <div class="caption">
                      (Any html can go here)
                  </div>
          </li>
          ... (repeat for every image in the gallery)
          </ul>
                                  
      It is important to specify the 'thumb' class for the link that should serve as the thumbnail and the 'caption' class for the element that should serve as the caption. When an image is selected for display in the slideshow, any elements with the 'caption' class will be rendered within the specified caption container element above.
    5. Initialize the gallery by calling the galleriffic initialization function with two arguments, the thumbnails container selector and an options hash. The following example shows the default options:
      $(document).ready(function() {
              var gallery = $('#gallery').galleriffic('#thumbs', {
                  delay:                  3000 // in milliseconds
                  numThumbs:              20 // The number of thumbnails to show page
                  preloadAhead:           40 // Set to -1 to preload all images
                  enableTopPager:         false,
                  enableBottomPager:      true,
                  imageContainerSel:      '', // The CSS selector for the element within which the main slideshow image should be rendered
                  controlsContainerSel:   '', // The CSS selector for the element within which the slideshow controls should be rendered
                  captionContainerSel:    '', // The CSS selector for the element within which the captions should be rendered
                  loadingContainerSel:    '', // The CSS selector for the element within which should be shown when an image is loading
                  renderSSControls:       true, // Specifies whether the slideshow's Play and Pause links should be rendered
                  renderNavControls:      true, // Specifies whether the slideshow's Next and Previous links should be rendered
                  playLinkText:           'Play',
                  pauseLinkText:          'Pause',
                  prevLinkText:           'Previous',
                  nextLinkText:           'Next',
                  nextPageLinkText:       'Next &rsaquo;',
                  prevPageLinkText:       '&lsaquo; Prev',
                  enableHistory:          false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes 
                  autoStart:              false, // Specifies whether the slideshow should be playing or paused when the page first loads 
                  onChange:               undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
                  onTransitionOut:        undefined, // accepts a delegate like such: function(callback) { ... }
                  onTransitionIn:         undefined, // accepts a delegate like such: function() { ... }
                  onPageTransitionOut:    undefined, // accepts a delegate like such: function(callback) { ... }
                  onPageTransitionIn:     undefined  // accepts a delegate like such: function() { ... }
              });
          });
                                  

    Download

    Extras

    I put together a jAlbum skin to make building static albums a breeze. Check it out here.

    Feedback

    I made alot of assumptions based on my own personal needs, so please make your needs known here and I will take them into consideration for future releases. I'd also like to keep a list of sites making use of Galleriffic, so if this is you, please email me (trent [at] twospy.com) your Web site's URL and indicate whether or not I may list it publicly.

    Donate

    If you find Galleriffic useful and would sleep better knowing you gave something back, feel free to make a donation!

  • posted @ 2009-07-17 23:09 『 Y X 』 阅读(1186) | 评论 (0)编辑 收藏