JavaScript Remove Element From Array
- Array.prototype.removeByElement = function(element) {
- for(var i=0; i<this.length; i++) {
- if (this[i] == element) {
- this.splice(i, 1); // (start position, select length)
- }
- }
- return this;
- }
JavaScript 的簡短寫法
在網上遊網時發現原來 JavaScript 是屬於函式語言?所以在 if, else 中失去了效率,變相就有了以下的取代方法,
整理了一下代碼如下:
- // 先定義要用到的變量
- var a = 1, b = 0 , c = "";
- /* 寫法一 */
- // 簡寫:
- a && (c += "OK");
- // 正寫:
- if (a) {
- c += "OK";
- }
- /* 寫法二 */
- // 簡寫:
- b || (b = 2);
- // 正寫:
- if (!b) {
- b = 2;
- }
- /* 寫法三 */
- // 簡寫:
- a ? ( (c = "yes"), (b = 1) ) : ( (c = "no"), (b = 2) );
- // 正寫
- if (a) {
- c = "yes";
- b = 1;
- }else{
- c = "no";
- b = 2;
- }
- /* 寫法四 */
- // 簡寫 (1):
- (a == window.getElementById("c")) && (a.style.display = "none");
- // 簡寫 (2):
- (a == window.getElementById("c")) ? a.style.display = "none" : "";
- // 正寫:
- if (a == window.getElementById("c")) {
- a.style.display = "none";
- }
- /* 寫法五 */
- // 簡寫
- return a.nodeType != 3
- ? a.tagName
- : a.setIntval
- ? "window"
- : "other"
- // 正寫
- if (a.nodeType != 3) {
- return a.tageName;
- }else if (a.setIntval) {
- return "window";
- }else{
- return "other";
- }
table auto height 100%
因為在某些情況下要使用到 table,所以花了點昤間來研究.
結果在 IE8, Chrome, FireFox 3.6 都測試成功了,記錄一下
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>x</title>
- <style type="text/css">
- * { border: none; padding: 0; margin: 0; z-index:0; }
- body, html { height: 100%; }
- #wapper { height:100%; min-height:100%; width: 100%; background-color:#000; color: #FFF; }
- </style>
- </head>
- <body>
- <div id="wapper">
- <table width="100%" height="100%">
- <tr>
- <td>1</td>
- <td>2</td>
- </tr>
- <tr>
- <td>1</td>
- <td>2</td>
- </tr>
- </table>
- </div>
- </body>
- </html>
Python 中計算字串中的字符出現次數
- #縮成一行:
- s = 'abCdEab@a!{(]zyu&8jb'; print "\n".join(map(lambda x: "%s -> %d" % (x, s.count(x)), s))
- #分成多行
- s = 'abCdEab@a!{(]zyu&8jb'
- f = lambda x: "%s -> %d" % (x, s.count(x));
- e = map(f, s)
- print "\n".join(e)
- #備用
- print [i for i in s]
2009-03-02 網摘
Node.js
SQLite bindings for Node.js
pure Javascript MySQL network driver for node.js
BSlayer (MySQL) support for Node.JS
WebSocket-compatible realtime HTTP server implemented with Node.JS
simple chat demo for node
PHP
PHP jQuery AJAX Javascript Long Polling
php framework / php微型智能框架 / jquery Similar Operation
jQuery
Javascript jQuery plugin for hooking keyboard events
IIS
Internet Information Services 6.0 may not function correctly after installing KB973917
PHP 通過 .htaccess 修改上傳檔案大小
- php_value upload_max_filesize 32M
- php_value post_max_size 32M
- php_value max_execution_time 360
- php_value max_input_time 360
Python 找出陣列中的相同值
- # -*- coding: utf-8 -*-
- a = ["11","22","33"]
- b = ["11","33"]
- c = set(a) & set(b)
- print c #输出 set(['11', '33'])
判斷是否為 Window
- function isWindowObject(obj){
- return obj.window === obj.window.window
- }
參考: http://blog.csdn.net/cheng5128/archive/2010/02/20/5313654.aspx
Python 中取得昨天的日期
- import datetime
- last_date = datetime.date.today() - datetime.timedelta(days=1)
- print last_date
PHP5 的測試筆記 (closure, lambda)
- class XRuby {
- private $from, $to, $table;
- public function __construct($from = "", $to = "", $table = array()) {
- $this->from = $from;
- $this->to = $to;
- $this->table = $table;
- }
- public function eachRange($func) {
- if (is_callable($func)) {
- $yield = function() use ($func) {
- $args = func_get_args();
- call_user_func_array($func, $args);
- };
- for($i=$this->from; $i<$this->to; $i++) {
- $yield($i);
- }
- }
- }
- public function eachArray($func) {
- if (is_callable($func)) {
- foreach($this->table as $k => $v) {
- call_user_func_array($func, array($k, $v));
- }
- }
- }
- }
- $s = function($num) {
- echo "<strong>Test Case: ".($num)."</strong><br />";
- };
- $x = new XRuby(1, 10, array(1 => 'one', 2 => 'two'));
- $s(1);
- $x->eachRange(function($i) {
- echo ($i*$i)."<br />";
- });
- $s(2);
- $x->eachArray(function($k, $v) {
- printf("%s => %s<br />", $k, $v);
- });
- $s(3);
- array_walk(
- $t = array('1' => 'one', '2' => 'two', '3' => 'three'),
- function(&$v, $k) {
- printf("%s => %s<br />", $k, $v);
- }
- );
分類
- Apache
- Bat Script
- C Language
- C# .NET
- CSS
- FreeBSD
- Google App Engine (GAE)
- html
- IronPython
- Java
- JavaScript
- JSP
- Lighttpd
- MFC
- MySQL
- Oracle
- PHP
- Python
- Resin
- Ruby
- Ruby On Rails
- SQLite
- Ubuntu
- VB.NET
- Visual Studio 2005
- Webmin
- Window Mobile
- Windows
- WordPress
- wxPython
- wxWidgets
- 伺服器
- 忽然一感
- 未分類
- 案子
- 程式作品
- 程式修改
- 程式片段
- 程式筆記
- 網摘
- 網絡見聞
- 網路代碼
- 網路文章
- 編輯器
- 資料收集
- 軟體應用
彙整
- 2010 年 三月
- 2010 年 二月
- 2010 年 一月
- 2009 年 十二月
- 2009 年 十一月
- 2009 年 十月
- 2009 年 八月
- 2009 年 七月
- 2009 年 六月
- 2009 年 五月
- 2009 年 四月
- 2009 年 三月
- 2009 年 二月
- 2009 年 一月
- 2008 年 十二月
- 2008 年 十一月
- 2008 年 十月
- 2008 年 九月
- 2008 年 八月
- 2008 年 七月
- 2008 年 六月
- 2008 年 五月
- 2008 年 四月
- 2008 年 三月
- 2008 年 二月
- 2008 年 一月
- 2007 年 十二月
- 2007 年 十一月
- 2007 年 十月
- 2007 年 九月
- 2007 年 八月
- 2007 年 七月
- 2007 年 六月
- 2007 年 五月