星期日, 6月 10, 2012

[phpmyadmin] stored procedure and trigger

查看目前已建立的stored procedure
show procedure status

查看目前已建立的stored procedure


select * from information_schema.routines where routine_type = 'procedure'


查看指定資料庫內已有的stored procedure


select * from information_schema.routines where routine_type = 'procedure' and routine_schema = 'your_db'

新建stored procedure


  1. Open phpMyadmin.
  2. Select a database to work with.
  3. Open the SQL tab.
  4. Select all of the SQL statements between the DELIMITER statements in your stored procedure script. Do not include the DELIMITER statements! Here’s what my example script should look like:
    DROP PROCEDURE IF EXISTS spFoo $$
    CREATE PROCEDURE spFoo ()
    BEGIN
     SELECT 'Foo' FROM DUAL;
    END $$
    
  5. In the delimiter field, just below the SQL editor’s text area, enter $$ as your delimiter.

Reference:
如何使用MySQL的Stored Procedure與Trigger
Using phpMyAdmin to Create Stored Procedures

星期日, 6月 03, 2012

[Java] Jersey Session

Session控制
@Path("/helloworld")
public class HelloWorld {

    @GET
    @Produces("text/plain")
    public String hello(@Context HttpServletRequest req) {

        HttpSession session= req.getSession(true);
        Object foo = session.getAttribute("foo");
        if (foo!=null) {
                System.out.println(foo.toString());
        } else {
                foo = "bar";
                session.setAttribute("foo", "bar");
        }
        return foo.toString();


    }
}

[Java] java.lang.UnsupportedClassVersionError: example/Hello : Unsupported major.minor version 51.0 (unable to load class example.Hello)

今天在local編譯完java後,丟到機器後就爆炸了。
是JDK版本不一樣導致XD,記錄一下這個痛!!

java.lang.UnsupportedClassVersionError: example/Hello : Unsupported major.minor version 51.0 (unable to load class example.Hello)

Major Class Versions of Various JDK
Following are the major version of class file format in standard JDK environment.

JDK 1.1 = 45
JDK 1.2 = 46
JDK 1.3 = 47
JDK 1.4 = 48
JDK 1.5 = 49
JDK 1.6 = 50

[Java] org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]

案例:
本地端(mac)的JRE使用1.7的64bit版本,build出來的程式在機器上都爆炸XD
目前先把elicpse的環境設回1.6的版本就可以在server正常跑了。
有遇到一樣情形的朋友一定要先確定Java的版本到底有沒有一致

專案按右鍵選擇Properties設定
JAVA BUILD PATH 設定


JAVA COMPILER 設定

[Java] Name comp is not bound in this Context

星期五, 6月 01, 2012

[Mysql] Host ‘yourhost’ is not allowed to connect to this MySQL server錯誤

連線MySQL時,出現標題上的錯誤訊息,
這個問題是此IP位址未授權給MYSQL
解決方法:直接在下SQL語法設定即可

補充:
進入設定檔 改bind-address

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0

1.登入mysql
shell>mysql -u root -p
mysql>use mysql

2.設定資料庫的使用權限

允許所有連線

mysql>GRANT ALL PRIVILEGES ON *.* TO ‘MySQL帳號’@'%’ IDENTIFIED BY ‘MySQL密碼’ WITH GRANT OPTION;
Tip:% 代表不限client的連線ip

設定特地連結的ip

mysql>GRANT ALL PRIVILEGES ON *.* TO ‘MySQL帳號’@'你要連線IP‘ IDENTIFIED BY ‘MySQL密碼’ WITH GRANT OPTION;

3.最後一定要更新權限
mysql>FLUSH PRIVILEGES;

Reference:
[MySQL]解決ERROR 1130: Host ‘yourhost’ is not allowed to connect to this MySQL server錯誤無法遠端連接MySQL:message from server: "Host xxx is not allowed to connect to this MySQL server"
MySQL的重要語法

[Java] DBCP Sample

簡單的DBCP範例,主要記錄Reference物件的用法
Setting up initial context for DBCP connection pool.

[Java] OpenID4Java

今天在處理OpenID的議題時,發現在local測試跑很正常。
但BUILD到伺服器的時候,會產生類別找不到的問題。
發現在tomcat/lib放了二個版本的openid4java的函式庫,
把舊的砍掉就執行正常了

星期四, 5月 31, 2012

[Java] Cannot create JDBC driver of class '' for connect URL 'null'

想要透過local的專案直接連mysql所遇到的
Cannot create JDBC driver of class '' for connect URL 'null'錯誤訊息的方法,
Google到的資訊實在太多做法了,把試成功的經驗記錄一下。

step1:在專案內的WEB-INF/加入context.xml檔

<xml version="1.0" encoding="UTF-8"?>
<Context >
<Resource
                name="jdbc/資料表連接名稱"
                auth="Container"
                type="javax.sql.DataSource"
        maxActive="100"
                maxIdle="30"
                maxWait="10000"
        username="root"
                password="密碼"
                driverClassName="com.mysql.jdbc.Driver"
        autoReconnect="true"
                removeAbandoned="true"
                removeAbandonedTimeout="300"
                logAbandoned="false"
        url="jdbc:mysql://遠端IP:3306/資料庫名稱"/>
        
Context>


Tip:DBCP已經設全域設定了,所以這個不用加
step2:在專案的web.xml加入

<resource-ref>
      <description>DB Connectiondescription>
      <res-ref-name>jdbc/資料表連接名稱res-ref-name>
      <res-type>javax.sql.DataSourceres-type>
resource-ref>

非常重要!!記得要重新開Tomcat!!

星期三, 5月 30, 2012

Mac lion Eclipse 設定 JDK7

在lion安裝完JDK7後,它的路徑已經先之前安裝的路徑不一樣了。
目前預設的安裝目錄是在
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

之後打開Eclipse後,透過偏好設定的JAVA中的Installed JREs,指定新的JDK就可以了。


找到的參考資料
If you are a Java developer who wants to do Java development on Mac OS X 10.7, here are a few not-so-tricky steps to follow to get going:
  1. Go to http://connect.apple.com and sign in with your Apple ID (developer account may be required – it’s free).
  2. From the list titled “Downloads for Apple Developers”, select the item labeled “Java for Mac OS X 10.7 Update 1 Developer Package” (release date Nov 8, 2011) then download and install the package.
  3. The JDK will be installed into a different location then previous. This will result in IDEs (such as Eclipse) being unable to locate source code and java docs.
  4. At the time of writing the JDK ended up here:
    /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
  5. Open up Eclipse preferences and go to Java > Installed JREs page
  6. Rather than use the “JVM Contents (MacOS X Default) we will need to use the JDK location
  7. At the time of writing Search is not aware of the new JDK location; we we will need to click on the Add button
  8. From the Add JRE wizard choose “MacOS X VM” for the JRE Type
  9. For the JRE Definition Page we need to fill in the following:
    JRE Home: /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
  10. The other fields will now auto fill, with the default JRE name being “Home”. You can quickly correct this to something more meaningful such as:
    JRE name: System JDK
  11. Finish the wizard and return to the Installed JREs page
  12. Choose “System JDK” from the list
  13. You can now develop normally with:

[Java] Filter 變更 jsp輸出內容

今天為了讓jsp上面的js檔案能使用SVN的版號做版本控制,
又為了讓同事能不用變更之前放在jsp裡面的script path,
所以想到了可以透過filter來將jsp輸出前把script path加上SVN的版號,
這樣就可以模擬出使用者每次都能讀到最新變更的Javascript

以下是簡單置換內容的Filter Sample

星期二, 5月 29, 2012

星期一, 5月 28, 2012

[Alfresco] Alfresco Namespace

Note: This list will expand / change between now and the next release.
NamespaceCommon PrefixDescription
http://www.alfresco.orgalfGeneral Alfresco Namespace
http://www.alfresco.org/model/dictionary/1.0dData Dictionary model
http://www.alfresco.org/model/system/1.0sysRepository system model
http://www.alfresco.org/model/content/1.0cmContent Domain model
http://www.alfresco.org/model/application/1.0appApplication model
http://www.alfresco.org/model/bpm/1.0bpmBusiness Process Model
http://www.alfresco.org/model/site/1.0stSite Model
http://www.alfresco.org/model/forum/1.0fmForum Model
http://www.alfresco.org/model/user/1.0usrUser model (in repository.jar)
http://www.alfresco.org/view/repository/1.0viewAlfresco Import / Export View
http://www.alfresco.org/model/action/1.0actAction service model
http://www.alfresco.org/model/rule/1.0ruleRule service model
http://www.alfresco.org/ws/service/authentication/1.0authAuthentication Web Service
http://www.alfresco.org/ws/service/repository/1.0repRepository Web Service
http://www.alfresco.org/ws/service/content/1.0contentContent Web Service
http://www.alfresco.org/ws/service/authoring/1.0authorAuthoring Web Service
http://www.alfresco.org/ws/service/classification/1.0clsClassification Web Service
http://www.alfresco.org/ws/cml/1.0cmlContent Manipulation Language
http://www.alfresco.org/ws/model/content/1.0cmWeb Service Content Domain Model
http://www.alfresco.org/ws/headers/1.0hdrSOAP Headers
http://www.alfresco.org/model/workflow/1.0wfWorkflow Model(link is to Alfresco simple workflow model, not generally extended)

[Eclipse] 設定JRE與Tomcat runtime

簡單記錄一下Eclipse設定JRE與Server Runtime擷圖XD

JRE Runtime
Step1: Windows-> Preference
Step2: Java-> Installed JREs


Server Runtime

Step1: Windows-> Preference
Step2: Server-> Runtime Environments
Step3: Add, 新增一個runtime server

Step4: 選擇新的runtime enviornment,範例為tomcat 7.0

Step5: 設定Tomcat安裝目錄
C:\Program Files\Apache Software Foundation\Tomcat 7.0



Step6: 完成,接下來編譯時選擇你要的執行環境即可


phpmyadmin 重新命名資料表

XD找好久
1.點選要修改的資料表
2.之後到瀏覽介面後,按上面的管理
3.資料表選項內,直接將資料表改名為的框框修改就好了

星期二, 5月 22, 2012

[Heroku] Java on Heroku

試玩了一下Heroku,發現自已從本地端的eclipse建Maven專案push上去Heroku後,
app都run不起來。
不過目前Heroku支援了四種template來幫助開發者在上面開發web app。
請參考這個網站:http://java.heroku.com/

•Web app with Spring and Tomcat
•Containerless web app with Embedded jetty
•Web app with Play! Framework
•RESTful API with JAX-RX

[Java] Maven + Eclipse 備忘錄

Maven是什麼?

Maven提供你的是建構環境,或說是建構環境的框架(Framework)。

Maven的主要精神有:


  • 慣例先於設定(Convention over configuration)


舉例來說,在Maven中認為,專案開發遵循應某些慣例,這些慣例像是固定目錄的名稱與架構、固定變數的名稱、固定的建構生命周期(Build lifecycle)等。Maven認為你不應花費時間在這些慣例的設定上,而要將精神放在更重要的工作上。


  • 集中管理相依性(Dependency management)


正如在 簡介 Apache Ivy 中提到的,程式庫的相依性管理是個頭痛的問題,Maven使用集中式管理,提供集中式的貯藏室(Central repository),你要在設定檔案宣告相依的程式庫等資訊,Maven會為你下載相關的檔案。

plugin 為基礎的架構

Maven 提供固定的建構生命周期,像是Default、Clean、Site等。在每個生命周期中,又會分作一些階段(Phase), 像是Default生命周期中,會有Validate、Compile、Test、Package、Integration test、Verify、Install、Deploy等階段,每個階段會有一些相繫結的plugin,Maven本身會有一些預設的plugin,你也 可以在設定檔中依需求宣告想使用的plugin,Maven會自動取得plugin。

專案物件模型(Project Object Model)


在Ant中使用build.xml來定義建構過程中的所有資訊,在Maven中與之對應的是pom.xml,不過pom.xml主要的目的是提供專案資訊,像是專案名稱、組織名稱、相依資訊等。


星期日, 5月 20, 2012

[RoR] 如何連接資料庫

Rails內建的資料庫是採用SQLite,資料庫的設定檔在此目錄下:config/database.yml


# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

建立一個Model
$>rails g model users account:string password:string

      invoke  active_record
      create    db/migrate/20120520124738_create_users.rb
      create    app/models/users.rb
      invoke    test_unit
      create      test/unit/users_test.rb
      create      test/fixtures/users.yml

使用migrate建立資料表

$> bundle exec rake db:migrate

==  CreateUsers: migrating ====================================================
-- create_table(:users)
   -> 0.0014s
==  CreateUsers: migrated (0.0015s) ===========================================

新增一個descript欄位到users表格

rails g migration add_descript_to_users
      invoke  active_record
      create    db/migrate/20120520125033_add_descript_to_users.rb


執行migrate將剛新增的欄位加入

$>bundle exec rake db:migrate
==  AddDescriptToUsers: migrating =============================================
==  AddDescriptToUsers: migrated (0.0000s) ====================================


TIP:Rails會知道哪些已經執行過migration,所以只會執行一次


Rake指令集
rake db:create # to create database
rake db:migrate # to create tables based on your migration







星期六, 5月 19, 2012

[RoR] 第一個RoR應用程式: HelloWorld

來個所有程式的第一步吧,HelloWorld

測試環境:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
Rails 3.2.3
作業1:HelloWorld 起步

星期三, 5月 09, 2012

[Javascript] Prototype 繼承

記錄一些關於Prototype的讀後感:)


Prototype的好處?
Javascript可使用Prototype來擴充類別的方法,
可以增加其效能,可將全部已instances的物件,
全部加上新的方法。

為什麼要用jQuery.fn?
jQuery中的jQuery.fn ($.fn) 其實就是等於 jQuery.prototype,
意即:

$.fn = $.prototype

所以寫外掛的時候就能輕鬆擴充jQuery的函式庫了。

為什麼不直接用$.prototype?


主要在於早期的jQuery.fn裡的每個內容並不使用prototype來實作,
而是採繞行整個物件的方式,
因為物件內的屬性跟方法可能很多,導致速度很慢,
後續版本改用prototype來提升效能,
為避免已存在的外掛程式被破壞。
所以才有會$.fn = $.prototype的別名存在。

Reference:
用javascript的prototype來玩繼承

[jQuery API] Deferred Object

Deferred Object 最大的特色在於處理非同步的狀況時,所執行的 Callback function 可以指定多個,讓程式增加可讀性,舉一個簡單的例子來說明:


Deferred Object 的狀態可分成三種
1. Pending: Operation 處理中
2. Resolve: Operation 處理成功
3. Reject: Operation 處理失敗


Reference:
http://ithelp.ithome.com.tw/question/10090605

星期二, 5月 08, 2012

[jQuery plugin] 使用tinyscrollbar外掛做出iphone/ipad捲軸視窗效果

如果使用iPhone/iPad常常會看到視窗過長的捲軸效果,
現在Facebook也都有一樣的捲軸視窗,
使用tinyscrollbar可以簡單的完成這個效果。




[jQuery Plugin] imagesLoaded偵測圖檔已被讀取

需要偵測圖檔已被讀取完畢的話,可以使用imagesLoaded這個外掛:)

[jQuery API] 偵測元素大小被改變 Detect element resize

先前寫了一個FlickrLinkr小服務,在div添加tinyscrollbar的外掛, 但因為div裡面需要讀取圖檔,當未讀取完的時候,會導致tinyscrollbar的高度不正常(後面被讀取出來的圖檔被div擋住) 可以透過這個可以偵測元素resize的外掛來解決目前的問題:)

[RoR] Ruby on Rails 完整架構圖

RoR完整架構圖,讓你簡單了解RoR MVC架構




Reference:

星期四, 5月 03, 2012

[IIS7] URL rewrite for php

前幾天試著透過Fast CGI想在上面跑phpMyAdmin的專案結果不是很順利(可參考 這篇)
今天換個變通的想法,
利用IIS 7的rewrite的模組來進行轉址~
開始動手設定吧XD

星期三, 5月 02, 2012

UML 又來了 lol

免費的UML圖表工具
http://astah.net/

活動圖:

  • 活動圖是表示流程的大方向面
  • 不要落入描述活動的細節裡面,有細節可再細分第二張活動圖
  • 活動圖應保持易讀性與單純化

http://microbuddy.blogspot.com/2009/03/uml_25.html

循序圖:
http://codingjames.blogspot.com/2009/08/uml-sequence-diagram.html

星期一, 4月 30, 2012

[Ruby] Ruby autocomplete in VIM

http://www.cuberick.com/2008/10/ruby-autocomplete-in-vim.html

[IIS7] IIS7 執行 php專案以及phpMyAdmin

本篇記綠在IIS7上面執行php與phpMyAdmin的安裝心得。
最後可以正確在IIS7上架php的專案(可正常連接mysql),
但目前IIS7執行phpMyAdmin專案在載入mysql.dll模組會錯誤,尚無解Orz~

安裝環境: 
Win7


前置工作:
Appserv安裝apache, php, phpmyadmin


如何在IIS7上執行php設定步驟

接著打開IIS管理工具

Step1:選擇 處理常式對應

Step2:接著點擊 新增模組對應

Step3:
在 要求路徑中 輸入 *.php

類型下拉 選擇 FastCgiModule

執行檔選擇 php5安裝目錄下的 php-cgi.exe

接著名稱取個 PHP for FCGI 即可

點確定,接著將剩餘的步驟都點確定即可完成設定。

Step4:
接著,請到php5安裝目錄下,把php.ini-recommended 改為 php.ini

Step5:
重新啟動www服務,即可運作PHP

星期日, 4月 29, 2012

[jQuery API] Html encode decode

利用jQuery簡單的完成html的編碼跟解碼
function htmlEncode(value){
  return $('<div/>').text(value).html();
}

function htmlDecode(value){
  return $('<div/>').html(value).text();
}

Reference:
JavaScript/jQuery HTML Encoding

星期三, 4月 25, 2012

[Javascript] 偵測上傳檔案的MIME Type

在前端偵測上傳檔案的MIME Type,不過不實用,因為使用者可以改副檔名來欺騙你。

var mimeType = document.getElementById("filedata").files[0].type; // e.g. image/png

星期二, 4月 24, 2012

[jQuery Plugin] 處理過長文字外掛(Truncate long string in web)

常常遇到在web上要處理文字過長的問題!!
參考了jquery text truncate寫的範例程式:

/**
 * Visual string trimming Trimming with pixel of container
 * 
 * change log:
 * 2012/12/06 use text function to avoid special characters let system crash
 * @author ken tsai 2012/04/06
 */
;
(function($) {

 function htmlEncode(value) {
  
  try{
   return $('<div/>').text(value).html();
  }catch(err){
   $.console("htmlEncode:" + err);
   return valeu;
  }
 }

 function htmlDecode(value) {
  try{
   return $('<div/>').html(value).text();
  }catch(err){
   $.console("htmlDecode:" + err);
   return valeu;
  }
 
 }
 
 $.tirmWithPixel = {};
 
 $.tirmWithPixelHTML = function(options){
  
  var opts = $.extend($.fn.trimWithPixel.defaults, options);
  
  var text = opts.text;
  var pixelLimitWidth = opts.limitPixelLength;
  var tailPattern = opts.tail;
  
  var $container = $("<div/>");
  
  var content = $container.append(
    $.tirmWithPixel({
       text:text,
       limitPixelLength:pixelLimitWidth,
       tail:tailPattern}
    ).clone()).html();
  
  return content;
 };
 
 $.tirmWithPixel = function(options) {

  var opts = $.extend($.fn.trimWithPixel.defaults, options);
  
  var text = opts.text;
  var pixelLimitWidth = opts.limitPixelLength;
  var tailPattern = opts.tail;
  
  var $container = $("<span></span>");
  
  //if element don't add to body
  //you can't get width from current element
  $container.text(text).appendTo("body");
  
//  $.console("original:" + $container.text());
  
  $container.trimWithPixel({
          limitPixelLength:pixelLimitWidth,
          tail:tailPattern});
  
  var $copyContainer = $container.clone();
  
  //remove from body
  $container.remove();
  
//  $.console("trim:" + $container.text());
  
  return $container;
 };

 $.fn.trimWithPixel = function(options) {

  // combine options
  var opts = $.extend($.fn.trimWithPixel.defaults, options);
  var pixelLimitWidth = opts.limitPixelLength;
  var tailPattern = opts.tail;
  var callback = opts.callback;
  
  this.each(function(i, obj) {

   var $strContainer = $(this);// current element
   
   var cText = $strContainer.text();// original text of container(without html encode)
   var oText = cText;// record original text(with html encode)
   
   //$.console("oText:" + oText);
   
   var $vistualSpan = $("<span style='white-space:nowrap;'></span>");
   $vistualSpan.text(cText);
   
   //$.console("span context:" + $vistualSpan.html());
   $strContainer.html($vistualSpan);
   
   //$.console("$strContainer html:" + $strContainer.html());
   
   var spanWidth = $vistualSpan.width();
   
   //$.console("spanWidth:" + spanWidth);
   
   // elem width is more than limit pixel length
   if (spanWidth > pixelLimitWidth) {
    var max = 0;
    while ((spanWidth = $vistualSpan.width()) > pixelLimitWidth) {
    
     cText = cText.substring(0, cText.length - 1);
     
     $vistualSpan.text(cText);
     cText = $vistualSpan.text();
     
     //debug
     /*
     max++;
     if(max > 100){
      $.console("[trimWithPixel] Exceed max limitation..");
      return;
     }*/
      
    }

    cText = cText + tailPattern;
    
    if (callback && typeof(callback) === "function") {
     callback({oText:oText,cText:cText});
    }else{
     $strContainer.attr("title", oText);
     $strContainer.text(cText);// using text fun to unescape html
    }
   } else {
    
    // not trimming
    //$.console("not trimming");
    
    if (callback && typeof(callback) === "function") {  
     callback({oText:oText,cText:cText});
    }else{
     $strContainer.attr("title",oText);
     $strContainer.text(oText);// using text fun to unescape html tag
    }
   }
  });
 };

 // default options
 $.fn.trimWithPixel.defaults = {
  limitPixelLength : 125,
  tail : "..."
 };

})(jQuery);

[TOMCAT] TOMCAT在WIN7自動啟動


最近在WIN7安裝了TOMCAT7,每次WIN7開機的時候都會跳這個視窗。


原來是WIN7安全性的問題,將CONFIGURE TOMCAT的特殊權限等級內的系統管理員的身分執行此程式打勾即可

[Ruby] MacOSX 安裝Ruby

這篇文章記錄自已安裝Ruby環境的心得,
自已裝過一遍才會遇到不一樣的問題lol

系統環境:
Mac OSX 10.7.3

[SEO] Google Sitemap

Sitemap 範例
<urlset xmlns:image="http://www.sitemaps.org/schemas/sitemap-image/1.1" xmlns:video="http://www.sitemaps.org/schemas/sitemap-video/1.1" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url> 
    <loc>http://www.example.com/foo.html</loc> 
    <image:image>
       <image:loc>http://example.com/image.jpg</image:loc> 
    </image:image>
    <video:video>     
      <video:content_loc>http://www.example.com/video123.flv</video:content_loc>
      <video:player_loc allow_embed="yes" autoplay="ap=1">http://www.example.com/videoplayer.swf?video=123</video:player_loc>
      <video:thumbnail_loc>http://www.example.com/thumbs/123.jpg</video:thumbnail_loc>
      <video:title>適合夏季的燒烤排餐</video:title>  
      <video:description>完美排餐烹調秘訣</video:description>
    </video:video>
  </url>
</urlset>

Sitemap 標記定義

標記是否必要說明
必要包含與 Sitemap 所含網址相關的所有資訊。
必要包含與特定網址相關的所有資料。
必要指定網址。如果是圖片與影片,請指定到達網頁 (亦稱為播放網頁或參照網頁)。此網址必須是獨一無二的。
選擇性網址的最後更新日期,格式為 YYYY-MM-DDThh:mmTZD (時間值為選擇性)。
選擇性用於提示網頁大概多久更新一次。有效值如下:
  • always:表示網頁每次遭到存取時皆會變更。
  • hourly
  • daily
  • weekly
  • monthly
  • yearly
  • never:此值適用於封存的網址。
選擇性描述網站上某個網址相對於其他網址的優先順序。優先順序範圍介於 1.0 (非常重要) 到 0.1 (完全不重要) 之間。這項設定不會影響您的網站在 Google 搜尋結果的排名,因為這個值是相對性的,只能和您網站中的其他網頁比較,因此即使將某個網頁指定為高優先順序 (或將所有網址指定為相同的優先順序),也不會提升您的網站在搜尋結果中的排名。此外,如果您將所有網頁的優先順序設定為相同的值,則設定不會產生任何作用。

星期一, 4月 23, 2012

[jQuery API] $.data()

很多時候我們會將物件的屬性值繫結在元素的屬性上面(我從以前就習慣這樣lol)。
然後再透過$('selector').attr('key') 拿取,
不過這個方法會造成dom過長( 也會降低seo的內容代碼比。 ),
不過常常遇到需求變更時又要多一個屬性,感覺很不方便。

建議使用jQuery提供的$.data()方法來儲存你的資料
jQuery.data( element, key, value )
  • element - 必要的參數,這個屬性就是我們要塞入資料的節點。
  • key - 欲塞入資料的鍵值,往後取得資料使用。
  • value - 欲塞入的資料,可為任何的資料型態。

jQuery.data(div, "test", { first: 16, last: "pizza!" });
$("span:first").text(jQuery.data(div, "test").first);
$("span:last").text(jQuery.data(div, "test").last);


如果你已經確定要綁定在某個元素上的話請用$.data()效能會比較好。
另外這方$.data(),也可以用在非元素上的資料存儲
var usersList = {};//store user list with key/value
$.data(usersList,user.userName,user);//user is json object

要取得資料的話也蠻方便的
var userData = $.data(usersList,userName);//userName is key
var userRowindex = userData.rowIndex;//某一個屬性值


Reference:
$.fn.data 與 $.data效率比較 
jQuery.data()
利用 jQuery 的 data 方法取數值時的陷阱

星期日, 4月 22, 2012

[Window7] Create symboic link in Window7


如何在Window7建立Symbolic link,參考至How to create symbolic link in windows 7

C:\Windows\system32>mklink
Creates a symbolic link.
 
MKLINK [[/D] | [/H] | [/J]] Link Target
 
/D      Creates a directory symbolic link.  Default is a file
symbolic link.
/H      Creates a hard link instead of a symbolic link.
/J      Creates a Directory Junction.
Link    specifies the new symbolic link name.
Target  specifies the path (relative or absolute) that the new link
refers to.


Example:
To create a symbolic link named MyDocs from the root directory to the \Users\User1\Documents directory, type:
mklink /D \MyDocs \Users\User1\Documents

[RoR] RoR 初探


最近開發接觸的語言,擷錄Ruby on Rails 實戰聖經心得 XD


Ruby on rails(ROR)
Rails的哲學包括以下指導原則:
  • 不要重複自己(DRY: Don’t Repeat Yourself) – 撰寫出重複的程式碼是件壞事
  • 慣例勝於設計(Convention Over Configuration) – Rails會預設各種好的設定跟慣例,而不是要求你設定每一個細節到設定檔中。
  • REST是網站應用程式的最佳模式 – 使用Resources和標準的HTTP verbs(動詞)來組織你的應用程式是最快的方式(我們會在路徑一章詳細介紹這個強大的設計)

Rails是採用Ruby開發的網頁框架,David Heinemeier Hanson(DHH)在2004年發明,具有以下功能:
  • MVC(Model-View-Control)模式
  • 支援單元測試和整合測試
  • 支援Ajax和RESTful介面
  • ORM機制
  • 支援各種最新的業界標準像是HTML5、JQuery

星期六, 4月 21, 2012

[Java] TOMCAT 啟動執行 Serverlet


  1. Initialize your class in servlet's init() method. You may add  attribute to make sure your servlet is created at application startup and not on first access.
  2. Add ServletContextListener and use contextInitialized() callback method. UseServletContext#setAttribute to store created object for future use.

星期四, 4月 19, 2012

[jQuery API] ScrollTop 回傳值為0



遇到一個需求需要將body一開始先設style為display:none;

之後再適當時機的時候再將此屬性移除~

結果會導致IE8再擷取ScorllTop時回傳的值都為0,

原以為是ScorllTop api不支援IE8的問題,但結果是因為加了display:none;
在這篇討論中有人提到:http://api.jquery.com/scrollTop/
Warning: .scrollTop() will return 0 (and setting it to anything won't work) if the element, or a parent element, is set to "display:none;". I had to apply my .scrollTop() logic after the element was shown.

[jQuery plugin] element center

控制元素置中的center plugin,常用在跳出式的視窗,
如果遇到parent元素,設定style="display:none;"。
可能會造成置中不正常,可參考這篇:[jQuery API] ScrollTop 回傳值為0

星期二, 4月 17, 2012

IIS 主機標頭

要在IIS上分別不同的網站其實很簡單
有分3種
1. 用IP區分
2. 用PORT區分
3. 用主機標頭區分

這次介紹的是第三種, 用主機標頭區分
用主機標頭區分的方式需要跟DNS做配合
方法如下:
1. 進IIS主機, 在IIS上的"網站"按右鍵-->新增網站(EX.Web01)
2. 在此網站按右鍵-->內容-->網站-->進階-->編輯, 在主機標頭值那邊, 填上客戶要的網站名稱(EX.testa.com)
3. 重複1, 2步驟, 建另一個新的網站(Web02), 主機標頭值填上testb.com

4. 進DNS, 增加 testa.com, testb.com 兩個正項對應區域
5. 在testa.com上按右鍵-->新增主機-->增加一筆IP為IIS主機IP的資料, 名稱不用打(不用打代表使用父系網域名稱, 也就是testa.com)
6. 在testb.com上按右鍵-->新增主機-->增加一筆IP為IIS主機IP的資料, 名稱不用打(不用打代表使用父系網域名稱, 也就是testb.com)

設好之後, 進IIS按下"瀏覽", 就可以正常瀏覽之
(在本機也可以直接打網站名(ex.www.testa.com)去找到站台資料)



補充:

1. 用此法設定的網站, 要將client的dns指向同一台的dns, 閘道也要相同才能連到.
2. 網站使用SSL安全連線時, 就不能使用主機標頭值

星期三, 4月 11, 2012

[IIS 7] 500.21-無法辨識的模組

今天發生如主題所示的 500.21-無法辨識的模組的錯誤,
第一時間一定就請教G大神了,原來只是單純SERVER上未安裝.NETFramework 4.0。
另外這篇: 500.21-無法辨識的模組 的作者也發生同樣的問題。
主要是用命令提示字元來重新註冊就可以解決了。

路徑如下:
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i

如果你想要自已寫批次檔來修正錯誤的話可以參考這篇
[Asp.Net] 重新註冊IIS .NET Framework
提供給同樣問題的朋友參考!!

[IIS 7] 解決 HTTP 404.2-Not found ISAPI和CGI限制方法

在將網站從IIS6移到IIS7後,
雖然已經重新安裝新的IIRF的模組
[IIS 7] IIS7 安裝 IIRF(Ionic's ISAPI Rewrite Filter),
不過還是造成了HTTP 404.2-Not found的錯誤訊息(本機看的時候)。
主要是ISAPI和CGI的限制內的.net 4.0模組未設置允許!!


重新設定為允許就可以正常Rewrite了。


Reference:
http://www.qiandabao.com/wdgz/938.html

[jQuery plugin] spinner button

好用的Spinner Button的元件 https://github.com/btburnett3/jquery.ui.spinner

[Javascript] 偵測是否為iphone/ipod/ipad瀏覽器

簡單的用Regex來判斷是否為iphone/ipad/ipod的瀏覽器!!
//偵測是否為ipad   
if(/iPad/i.test(navigator.userAgent) {   
    // dosomething
}   
//如果所有的裝置要一起改變可以這樣用   
if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {   
    // dosomething  
}; 

[jQuery plugin] Masked Input Plugin

強大的textbox欄位驗證元件:Masked Input Plugin

星期二, 4月 10, 2012

[jQuery] 改善你的jQuery效能

愈大型的網站該考慮網站的效能:
本篇記綠一些找到提升jQuery效能的文章:)
Improve your jquery 25 excellent

加速前端網頁效能的14條規則

[IIS 7] IIS7 安裝 IIRF(Ionic's ISAPI Rewrite Filter)

如果你的asp.net的舊網站從IIS6升級至IIS7時,
如果你有用到IIRF模組,可參考這篇文章。
Installing IIRF on IIS7

不過現在已經提供方便的.msi檔了,可以無痛設定XD
下載IIRF 這裡

[IIS 7] 總該面對IIS 7了吧!!

一直都懶得來摸IIS 7,都出來這麼久了,也是該面對的時候了lol
今天在試的過程中找到的一些學習資源。記綠在此方便以後參考。


IIS 7 基礎觀念:網站、應用程式、與虛擬目錄
【潛盾機】列出IIS上所有ASP.NET網站應用程式
M$ IIS7 邊做邊學系列
如何部署 Asp.Net 4.0 應用程式於 IIS 7 x64 WSS 3.0 下

星期一, 4月 02, 2012

[Javascript] 取得完整路徑的檔名

今天在測試input box的檔案路徑時,
發現不同瀏覽器的取出的值不太一致,Chrome的是完整路徑,FF跟IE都是檔名。
要取得檔案的話可以使用以下的javascript範例,
取自 "Javascript - How to extract filename from a file input control"


To split the string ({filepath}/{filename}) and get the file name you could use something like this:
str.split(/(\\|\/)/g).pop()
"The pop method removes the last element from an array and returns that value to the caller." MOZILLA DEVELOPER NETWORK
Example:
from: "/home/user/file.txt".split(/(\\|\/)/g).pop()
you get: "file.txt"


[AJAX] 解決AJAX呼叫後的上下頁按鈕問題


使用AJAX來存取資料後,常常會遇到上下頁沒有辦法記錄歷程。
以下是建議解決這個議題的各種套件。
最後選擇Asual address套件:
範例如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery Address - Deep linking for the masses</title>
<script src="js/jquery-1.7.js"></script>
<script src="js/jquery.address-1.4.js"></script>
<script>

$(function(){
    
 $.address.change(function(event) {
     // do something depending on the event.value property, e.g.
     // $('#content').load(event.value + '.xml');
     console.log("address.change" + event.value);
 });
 
    $('a').click(function() {
     
     //record address
     var link = $(this).attr('href').replace(/^#/,'');;
     $.address.autoUpdate(false).value(link);
      
    });
});
</script>
</head>
<body>
<a href="#a" >a</a>
<a href="#b">b</a>
<a href="#c" >c</a>
</body>
</html>

此元件提供三種Callback Event,分別為change,externalChange,internalChange。
觀看你的使用情況,主要是externalChange可能你區別出是改變瀏覽器網址觸發的事件,非常好用,不過目前測試情況要多偵測出externalChange事件需要綁定每個link元素的click事件後加入

其他你感興趣的文章

Related Posts with Thumbnails