任何一個(gè)有經(jīng)驗(yàn)的程序員都知道,軟件開發(fā)遵循著一些不成文的法則。然而,如果你不遵循這些法則也并不意味著會受到懲罰;相反,有時(shí)你還會獲得意外的好處。下面的就是軟件編程中的21條法則:
當(dāng)為遺留系統(tǒng)加入spring時(shí),經(jīng)典問題就是遺留系統(tǒng)需要引用spring管理的bean。幸好spring有機(jī)制可以處理這些。
建一個(gè)類實(shí)現(xiàn)ApplicationContextAware接口,有一個(gè)引用ApplicationContext的靜態(tài)成員,然后,遺留系統(tǒng)需要引用spring管理的bean的地方,使用這個(gè)類。
1.比如:我這里建一個(gè)SpringContext類
2.然后在spring配置文件里加
3.其它類中引用
4.如果老是寫SpringContext.getContext().getBean("...");麻煩,可以建一個(gè)工廠類來返回你要
的bean
原文:http://chenlb.javaeye.com/blog/135897
VIM中常用的替換模式總結(jié)。
0,:g/null/d
找到null的行并且刪掉
1,簡單替換表達(dá)式
替換命令可以在全文中用一個(gè)單詞替換另一個(gè)單詞:
:%s/four/4/g
“%” 范圍前綴表示在所有行中執(zhí)行替換。最后的 “g” 標(biāo)記表示替換行中的所有匹配點(diǎn)。如果僅僅對當(dāng)前行進(jìn)行操作,那么只要去掉%即可
如果你有一個(gè)象 “thirtyfour” 這樣的單詞,上面的命令會出錯(cuò)。這種情況下,這個(gè)單詞會被替換成”thirty4″。要解決這個(gè)問題,用 “\<” 來指定匹配單詞開頭:
:%s/\<four/4/g
顯然,這樣在處理 “fourty” 的時(shí)候還是會出錯(cuò)。用 “\>” 來解決這個(gè)問題:
:%s/\<four\>/4/g
如果你在編碼,你可能只想替換注釋中的 “four”,而保留代碼中的。由于這很難指定,可以在替換命令中加一個(gè) “c” 標(biāo)記,這樣,Vim 會在每次替換前提示你:
:%s/\<four\>/4/gc
2,刪除多余的空格
要?jiǎng)h除這些每行后面多余的空格,可以執(zhí)行如下命令:
:%s/\s\+$//
命令前面指明范圍是 “%”,所以這會作用于整個(gè)文件。”substitute” 命令的匹配模式是
“\s\+$”。這表示行末($)前的一個(gè)或者多個(gè)(\+)空格(\s)。替換命令的 “to” 部分是空的:”//”。這樣就會刪除那些匹配的空白字符。
3,匹配重復(fù)性模式
星號項(xiàng) “*” 規(guī)定在它前面的項(xiàng)可以重復(fù)任意次。因此:
/a*
匹配 “a”,”aa”,”aaa”,等等。但也匹配 “” (空字串),因?yàn)榱愦我舶趦?nèi)。星號 “*” 僅僅應(yīng)用于那個(gè)緊鄰在它前面的項(xiàng)。因此 “ab*” 匹配 “a”,”ab”,”abb”,”abbb”,等等。如要多次重復(fù)整個(gè)字符串,那么該字符串必須被組成一個(gè)項(xiàng)。組成一項(xiàng)的方法就是在它前面加 “\(”,后面加 “\)”。因此這個(gè)命令:
/\(ab\)*
匹配: “ab”,”abab”,”ababab”,等等。而且也匹配 “”。
要避免匹配空字串,使用 “\+”。這表示前面一項(xiàng)可以被匹配一次或多次。
/ab\+
匹配 “ab”,”abb”,”abbb”,等等。它不匹配 后面沒有跟隨 “b” 的 “a”。
要匹配一個(gè)可選項(xiàng),用 “\=”。 例如:
/folders\=
匹配 “folder” 和 “folders”。
4,指定重復(fù)次數(shù)
要匹配某一項(xiàng)的特定次數(shù)重復(fù),使用 “\{n,m}” 這樣的形式。其中 “n” 和 “m” 都是數(shù)字。在它前面的那個(gè)項(xiàng)將被重復(fù) “n” 到 “m” 次 (|inclusive| 包含 “n” 和 “m”)。例如:
/ab\{3,5}
匹配 “abbb”,”abbbb” 以及 “abbbbb”。
當(dāng) “n” 省略時(shí),被默認(rèn)為零。當(dāng) “m” 省略時(shí),被默認(rèn)為無限大。當(dāng) “,m” 省略時(shí),就表示重復(fù)正好 “n” 次。例如:
模式 匹配次數(shù)
\{,4} 0,1,2,3 或 4
\{3,} 3,4,5,等等
\{0,1} 0 或 1,同 \=
\{0,} 0 或 更多,同 *
\{1,} 1 或 更多,同 \+
\{3} 3
5,多選一匹配
在一個(gè)查找模式中,”或” 運(yùn)算符是 “\|”。例如:
/foo\|bar
這個(gè)命令匹配了 “foo” 或 “bar”。更多的抉擇可以連在后面:
/one\|two\|three
匹配 “one”,”two” 或 “three”。
如要匹配其多次重復(fù),那么整個(gè)抉擇結(jié)構(gòu)須置于 “\(” 和 “\)” 之間:
/\(foo\|bar\)\+
這個(gè)命令匹配 “foo”,”foobar”,”foofoo”,”barfoobar”,等等。
再舉個(gè)例子:
/end\(if\|while\|for\)
這個(gè)命令匹配 “endif”,”endwhile” 和 “endfor”。
滿足需求,優(yōu)點(diǎn)不少,雖然沒有時(shí)間測試所有聲稱的東西,但是大致試了一下,效果還不錯(cuò)。注意縮略圖是指定的自己在硬盤上已經(jīng)生成好的圖片文件,而不是在頁面中再來縮放的,據(jù)他的說法是這樣對減小帶寬占用有利,對用戶瀏覽器的處理能力也要求更低,事實(shí)確實(shí)如此。加載幾十張巨大的圖片和幾十張很小的縮略圖,差別就很明顯了。
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.
<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>
<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>
<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.
$(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 ›',
prevPageLinkText: '‹ 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() { ... }
});
});
I put together a jAlbum skin to make building static albums a breeze. Check it out here.
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.
If you find Galleriffic useful and would sleep better knowing you gave something back, feel free to make a donation!