星期四, 11月 29, 2012

[Javascript] 檢查IE Document Mode

客戶遇到ie無法正確指定文件模式的問題。 只要在ui加上<meta http-equiv="X-UA-Compatible" content="IE=edge">,即可。 不過要避免在它之前有其他script執行(網民建議)。 不過今天在客戶那邊處理的時候,之前把content內多加了一個IE=edge,chrome=1,會導致無法正確告訴ie使用最新的文件模式檢視(content)。 以下的語法可以偵測目前用戶的文件模式。
function checkIEDocumentMode(){
 
 if (window.navigator.appName == "Microsoft Internet Explorer")
 {
    if (document.documentMode){
     USERAGENT = document.documentMode;
    } // IE8
    else // IE 5-7
    {
     USERAGENT = 5; // Assume quirks mode unless proven otherwise
       if (document.compatMode)
       {
          if (document.compatMode == "CSS1Compat")
           USERAGENT = 7; // standards mode
       }
    }
    // the USERAGENT variable now contains the document compatibility mode.
    $.console("checkIEDocumentMode:" + USERAGENT);
    //var $metaTag = $("");
    //$metaTag.appendTo("head");
    //content="IE=Value" value types:5、6、7、8、9、10、EmulateIE7、EmulateIE8、Edge
 }
}

星期五, 11月 23, 2012

[jQuery] 價錢格式化

想要讓你網站顯示的數字讓使用者更容易閱讀嗎?
可以使用jquery price format 來快速完成唷
http://jquerypriceformat.com/


星期日, 11月 18, 2012

[Java] Hashmap Race condition

最近發生了一個hashmap的嚴重bug,跟同事查了才知道這是Java hashmap常見的問題之一。
由此可見大家都是java的菜鳥XD,
發生原因在於hashmap當滿了之後,如果有多個threads同時對他put或get就會產生Race Condition。
所以可以採用Java Synchronized來處理。參考這位大大的心得:[Java] Synchronized 心得
總共有三種方法可以使用

[jQuery plugin] ajaxForm 與 validator 整合範例

時常會需要利用到jquery form與 validator 二個元件整合的應用。 把範例記錄一下 :D 範例網址:
注意在submithandler事件裡面要改用ajaxSubmit的方法而不是ajaxForm。

http://jquery.bassistance.de/validate/demo/ajaxSubmit-intergration-demo.html

jQuery(function() {
  // show a simple loading indicator
  var loader = jQuery('
loading...
') .css({position: "relative", top: "1em", left: "25em", display: "inline"}) .appendTo("body") .hide(); jQuery().ajaxStart(function() { loader.show(); }).ajaxStop(function() { loader.hide(); }).ajaxError(function(a, b, e) { throw e; }); var v = jQuery("#form").validate({ submitHandler: function(form) { jQuery(form).ajaxSubmit({ target: "#result" }); } }); jQuery("#reset").click(function() { v.resetForm(); }); });

星期二, 11月 13, 2012

[Alfresco] User Quota Issue

如何讓alfresco的quota即時更新, alfresco的工程師說可透過Java backend的ContentUsageService.getUserUsage(userName) 或 覆寫userUsageCollapseJob
https://forums.alfresco.com/en/viewtopic.php?f=27&t=43431
You should be able to get the up-to-date user usage via ContentUsageService.getUserUsage(userName) or else you could consider overriding the userUsageCollapseJob to run more often (eg. every minute instead of every 5 minutes).

If you're running Enterprise 3.4.6 and need more help with this issue then please contact Alfresco Support (if you haven't already).

Regards,
Jan

Ref:
Interface ContentUsageService

星期一, 11月 12, 2012

[Java] GZIP Filter 與 404 錯誤頁面的臭蟲

起因:
GZIPFilter壓縮遇到不存在的網頁會爆炸,如下所示:


這個網頁無法使用

http://serverip/test.jspddd 的網頁可能暫時無法使用或被永久移至新網址。
錯誤 330 (net::ERR_CONTENT_DECODING_FAILED): 未知的錯誤。


2012/11/13
目前尚未找到解法,不過透過HttpServletResponseWrapper目前竟然無法成功拿到各網頁的content,唯有在最後一層的Filter呼叫啊HttpServletResponseWrapper才有辦法拿到



Reference:
What is the simplest way to display httpServletResponse.sendError(403, “My Message”) status from JSTL
How to make a filter to detect if the user requested a not found page?

[Hadoop] WordCount Sample


記錄一下第一次跑Hadoop WordCount Job的過程 :)

1. 建立HDFS資料夾
#全部的資料夾會自動建立
hduser@hadoop-master:/usr/local/hadoop$hadoop dfs -mkdir /home/hduser/wordcount

2. 匯入要分析的文件資料(local-dir)到HDFS資料夾

$hadoop dfs -copyFromLocal
#匯入
hduser@hadoop-master:/usr/local/hadoop$hadoop dfs -copyFromLocal /home/hduser/wordcount /home/hduser/wordcount

#查看匯入的資料
hduser@hadoop-master:/usr/local/hadoop$ hadoop dfs -ls /home/hduser/wordcount
Warning: $HADOOP_HOME is deprecated.

[Hadoop] WordCount

在寫Hadoop job的時候,如果你有分package的話,
匯出.jar的時候請記得選取Main Class進入點,如下所示

然後再執行job的時候就不會說找不到了
hadoop@client:~/wordcount$ hadoop jar exercise.wordco.jar WordCo /user/hadoop/wordcount/pg5000.txt /user/hadoop/wordcount/output



星期五, 11月 09, 2012

Chrome: Uncaught SyntaxError: Unexpected end of input


Chrome: Uncaught SyntaxError: Unexpected end of input

今天遇到一個找很久的BUG,
本來以為是JS裡面的{}沒對好,結果是網頁上的超連結的javascript:void(0)設錯了==
少打了void後面的(0)
這個手殘的錯誤似乎出現好幾次了XD


[jQuery plugin] 如何reset from

jquery validator常常submit完要重新清除,常用到的語法。
在此記錄一下。

$(form)[0].reset();

[jQuery plugin] validator fileupload


記錄如何驗證上傳元素,只要加上accept,filesize即可。

 fileToUpload:{ 
accept: "png|jpe?g|gif",
filesize: 1048576
 }

[jQuery plugin] Validator 如何在選擇元素select驗證

常常會用到的validator於選擇元素上的驗證,原來也是加個required就好,記一下 XD

$("#bankForm").validate({
   rules:{
    
     citys:{
     required:true
     }
                     
});
最後發現請選擇的option的value要記得設"",不然會無法動作。

                               
                           

星期六, 11月 03, 2012

[Javascript] 檢查json的key是否存在



太常用到了,記錄一下。使用hasOwnProperty就可以輕鬆解決嚕 wow

You don't need jQuery for this, just JavaScript. You can do it a few ways:
  • typeof d.failed- returns the type ('undefined', 'Number', etc)
  • d.hasOwnProperty('failed')- just in case it's inherited
  • 'failed' in d- check if it was ever set (even to undefined)

星期四, 11月 01, 2012

[Alfresco] Upload Avatar Javascript API


//js

/**
 * User Profile Avatar Upload method
 *
 * @method POST
 * @param username {string}
 *        filedata {file}
 */

function main()
{
   try
   {
      var filename = null;
      var content = null;
      var username = null;

      // locate file attributes
      for each (field in formdata.fields)
      {
         if (field.name == "filedata" && field.isFile)
         {
            filename = field.filename;
            content = field.content;
         }
         else if (field.name == "username")
         {
            username = field.value;
         }
      }

      // ensure all mandatory attributes have been located
      if (filename == undefined || content == undefined)
      {
         status.code = 400;
         status.message = "Uploaded file cannot be located in request";
         status.redirect = true;
         return;
      }
      if (username == null || username.length == 0)
      {
         status.code = 500;
         status.message = "Username parameter not supplied.";
         status.redirect = true;
         return;
      }

      var user = people.getPerson(username);
      // ensure we found a valid user and that it is the current user or we are an admin
      if (user == null ||
          (people.isAdmin(person) == false && user.properties.userName != person.properties.userName))
      {
         status.code = 500;
         status.message = "Failed to locate user to modify or permission denied.";
         status.redirect = true;
         return;
      }

      // ensure cm:person has 'cm:preferences' aspect applied - as we want to add the avatar as
      // the child node of the 'cm:preferenceImage' association
      if (!user.hasAspect("cm:preferences"))
      {
         user.addAspect("cm:preferences");
      }

      // remove old image child node if we already have one
      var assocs = user.childAssocs["cm:preferenceImage"];
      if (assocs != null && assocs.length == 1)
      {
         assocs[0].remove();
      }

      // create the new image node
      var image = user.createNode(filename, "cm:content", "cm:preferenceImage");
      image.properties.content.write(content);
      image.properties.content.guessMimetype(filename);
      image.properties.content.encoding = "UTF-8";
      image.save();

      // wire up 'cm:avatar' target association - backward compatible with JSF web-client avatar
      assocs = user.associations["cm:avatar"];
      if (assocs != null && assocs.length == 1)
      {
         user.removeAssociation(assocs[0], "cm:avatar");
      }
      user.createAssociation(image, "cm:avatar");

      // save ref to be returned
      model.image = image;
   }
   catch (e)
   {
      var x = e;
      status.code = 500;
      status.message = "Unexpected error occured during upload of new content.";
      if(x.message && x.message.indexOf("org.alfresco.service.cmr.usage.ContentQuotaException") == 0)
      {
         status.code = 413;
         status.message = x.message;
      }
      status.redirect = true;
      return;
   }
}

main();



//description

  Avatar Upload
  Upload avatar file content and apply to person preferences
 
  user
  required
  /slingshot/profile/uploadavatar



//template
{
<#if person.childAssocs["cm:preferenceImage"]??>
"avatar": "${person.childAssocs["cm:preferenceImage"][0].downloadUrl}"
</#if>
<#if person.associations["cm:avatar"]??>
<#if person.associations["cm:avatar"][0].childAssocs["rn:rendition"]??>
,"avatarthumb": "${person.associations["cm:avatar"][0].childAssocs["rn:rendition"][0].downloadUrl}"
</#if>
</#if>
}

其他你感興趣的文章

Related Posts with Thumbnails