npm으로 모듈 설치 시, npm은 홈 디렉토리의 node_modules 디렉토리를 생성하고 node_module 디렉토리에 node 모듈을 추가한다.


$ npm install redis


$ cd node_modules/


$ ls 

redis


$ cd redis


$ ls

LICENSE      README.md    appveyor.yml benchmarks   changelog.md coverage     index.js     lib          node_modules package.json

Posted by '김용환'
,


javascript에서 문자열(numeric string)을 숫자로 변환하는 함수이다.

자바와 비슷한 역할이지만, 두 번째 인수는 radix라는 진법 체제(예, 16진수...)를 따로 명시적으로 준다.


> parseInt("0xF")

15

> parseInt("F")

NaN

> parseInt(" 0xF", 16);

15

> parseInt("0x12", 16);

18

> parseInt(1.99, 10);

1

> parseInt("5*3", 10);

5

> parseInt("15*3", 10);

15

> parseInt("100", 2);

4



Posted by '김용환'
,



mw js(https://github.com/nwjs/nw.js/)을 사용하면, 


단일 쓰레드로 nodejs + webkit을 쓸 수 있는 inapp용 브라우져 개발이 가능하다.


또한 여러 운영체제(맥, 윈도우, 리눅스)에서 동작하는 하나의 데스크탑 애플리케이션으로 배포할 수 있다.


발표 자료 

https://speakerdeck.com/zcbenz/node-webkit-app-runtime-based-on-chromium-and-node-dot-js

Posted by '김용환'
,



phantom js가 2.0을 출시했다. mac에서는 brew로 쉽게 설치할 수 있다.


$ brew install phantomjs


$ cat > hello.js

console.log("hello world");

phantom.exit();


$ phantomjs hello.js

hello world






좋다던 casperjs는 현재 2.0을 제대로 지원하지 않는다. 

포기한거냐 라는 질문이 들어왔을 정도이다. 현재 대답도 명확치 않은 상태이다. ㅜㅜ

https://github.com/n1k0/casperjs/issues/1299



ghostdriver도 쉽지 않은 상황이다. 

https://github.com/detro/ghostdriver


Posted by '김용환'
,



* 다음 지도 api

http://apis.map.daum.net/web/


* Jquery ajax

http://zetawiki.com/wiki/JQuery_AJAX_%EB%A1%9C%EA%B7%B8%EC%9D%B8_%EA%B5%AC%ED%98%84



* java script 에서 innerHtml 개발하면서 아래 블로그에 도움 받음


출처 : http://level.tistory.com/112

div 태그에서의 innerHtml 사용

var div_test = document.getElementById('Test');
var input = "";

input += "<a onMouseOver='alarm();'>";
input += "ALARM";
input += "</a>";

div_test.innerHTML = input;


Posted by '김용환'
,

inputbox에서 keyup할때마다 chkPass(pwd, targetID, saStrength)  함수를 호출하면 됨.
이것을 이용해서


/*
**    Original File: pwd_meter.js
**    Created by: Jeff Todnem (http://www.todnem.com/)
**    Created on: 2007-08-14
**    Last modified: 2007-08-30
**
**    License Information:
**    -------------------------------------------------------------------------
**    Copyright (C) 2007 Jeff Todnem
**
**    This program is free software; you can redistribute it and/or modify it
**    under the terms of the GNU General Public License as published by the
**    Free Software Foundation; either version 2 of the License, or (at your
**    option) any later version.
**   
**    This program is distributed in the hope that it will be useful, but
**    WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**    General Public License for more details.
**   
**    You should have received a copy of the GNU General Public License along
**    with this program; if not, write to the Free Software Foundation, Inc.,
**    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**   
**   
*/

String.prototype.strReverse = function() {
 var newstring = "";
 for (var s=0; s < this.length; s++) {
  newstring = this.charAt(s) + newstring;
 }
 return newstring;
};


/*
**    function: chkPass
**    purpose: Updates the password scorebar (background color and complexity text)
**              based upon how a password scores for overall security strength.
**    parameters:
**      pwd: The password string to evaluate
**      targetID: The id of the password scorebar to update
**      saStrength: A string array of different password strengths (not necessarily english)
**
*/

function chkPass(pwd, targetID, saStrength) {
    var index = { TOOSHORT:0, WEAK:1, MODERATE:2, STRONG:3 };
    var oScorebar = document.getElementById(targetID);
 var nScore = 0;
 var nLength = 0;
 var nAlphaUC = 0;
 var nAlphaLC = 0;
 var nNumber = 0;
 var nSymbol = 0;
 var nMidChar = 0;
 var nRequirements = 0;
 var nAlphasOnly = 0;
 var nNumbersOnly = 0;
 var nRepChar = 0;
 var nConsecAlphaUC = 0;
 var nConsecAlphaLC = 0;
 var nConsecNumber = 0;
 var nConsecSymbol = 0;
 var nConsecCharType = 0;
 var nSeqAlpha = 0;
 var nSeqNumber = 0;
 var nSeqChar = 0;
 var nMultLength = 4;
 var nMultAlphaUC = 2;
 var nMultAlphaLC = 2;
 var nMultNumber = 4;
 var nMultSymbol = 6;
 var nMultMidChar = 2;
 var nMultRequirements = 2;
 var nMultConsecAlphaUC = 2;
 var nMultConsecAlphaLC = 2;
 var nMultConsecNumber = 2;
 var nMultSeqAlpha = 3;
 var nMultSeqNumber = 3;
 var nTmpAlphaUC = "";
 var nTmpAlphaLC = "";
 var nTmpNumber = "";
 var nTmpSymbol = "";
 var sAlphas = "abcdefghijklmnopqrstuvwxyz";
 var sNumerics = "01234567890";
 var sComplexity = saStrength[index.TOOSHORT];
    var sColor = "#eee";
    var nMinPwdLen = 8;
 if (pwd) {
  nScore = parseInt(pwd.length * nMultLength);
  nLength = pwd.length;
  var arrPwd = pwd.replace (/\s+/g,"").split(/\s*/);
  var arrPwdLen = arrPwd.length;
  
  /* Loop through password to check for Symbol, Numeric, Lowercase and Uppercase pattern matches */
  for (var a=0; a < arrPwdLen; a++) {
   if (arrPwd[a].match(new RegExp(/[A-Z]/g))) {
    if (nTmpAlphaUC !== "") { if ((nTmpAlphaUC + 1) == a) { nConsecAlphaUC++; nConsecCharType++; } }
    nTmpAlphaUC = a;
    nAlphaUC++;
   }
   else if (arrPwd[a].match(new RegExp(/[a-z]/g))) {
    if (nTmpAlphaLC !== "") { if ((nTmpAlphaLC + 1) == a) { nConsecAlphaLC++; nConsecCharType++; } }
    nTmpAlphaLC = a;
    nAlphaLC++;
   }
   else if (arrPwd[a].match(new RegExp(/[0-9]/g))) {
    if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
    if (nTmpNumber !== "") { if ((nTmpNumber + 1) == a) { nConsecNumber++; nConsecCharType++; } }
    nTmpNumber = a;
    nNumber++;
   }
   else if (arrPwd[a].match(new RegExp(/[^a-zA-Z0-9_]/g))) {
    if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; }
    if (nTmpSymbol !== "") { if ((nTmpSymbol + 1) == a) { nConsecSymbol++; nConsecCharType++; } }
    nTmpSymbol = a;
    nSymbol++;
   }
   /* Internal loop through password to check for repeated characters */
   for (var b=0; b < arrPwdLen; b++) {
    if (arrPwd[a].toLowerCase() == arrPwd[b].toLowerCase() && a != b) { nRepChar++; }
   }
  }
  
  /* Check for sequential alpha string patterns (forward and reverse) */
  for (var s=0; s < 23; s++) {
   var sFwd = sAlphas.substring(s,parseInt(s+3));
   var sRev = sFwd.strReverse();
   if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqAlpha++; nSeqChar++;}
  }
  
  /* Check for sequential numeric string patterns (forward and reverse) */
  for (var s=0; s < 8; s++) {
   var sFwd = sNumerics.substring(s,parseInt(s+3));
   var sRev = sFwd.strReverse();
   if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqNumber++; nSeqChar++;}
  }
  
 /* Modify overall score value based on usage vs requirements */

  /* General point assignment */
  if (nAlphaUC > 0 && nAlphaUC < nLength) {
   nScore = parseInt(nScore + ((nLength - nAlphaUC) * nMultAlphaUC));
  }
  if (nAlphaLC > 0 && nAlphaLC < nLength) { 
   nScore = parseInt(nScore + ((nLength - nAlphaLC) * nMultAlphaLC));
  }
  if (nNumber > 0 && nNumber < nLength) { 
   nScore = parseInt(nScore + (nNumber * nMultNumber));
  }
  if (nSymbol > 0) { 
   nScore = parseInt(nScore + (nSymbol * nMultSymbol));
  }
  if (nMidChar > 0) { 
   nScore = parseInt(nScore + (nMidChar * nMultMidChar));
  }

  /* Point deductions for poor practices */
  if ((nAlphaLC > 0 || nAlphaUC > 0) && nSymbol === 0 && nNumber === 0) {  // Only Letters
            nAlphasOnly = nLength;
   nScore = parseInt(nScore - nAlphasOnly);
  }
  if (nAlphaLC === 0 && nAlphaUC === 0 && nSymbol === 0 && nNumber > 0) {  // Only Numbers
            nNumbersOnly = nLength;
   nScore = parseInt(nScore - nNumbersOnly);
  }
  if (nRepChar > 0) {  // Same character exists more than once
   nScore = parseInt(nScore - nRepChar);
  }
  if (nConsecAlphaUC > 0) {  // Consecutive Uppercase Letters exist
   nScore = parseInt(nScore - (nConsecAlphaUC * nMultConsecAlphaUC));
  }
  if (nConsecAlphaLC > 0) {  // Consecutive Lowercase Letters exist
   nScore = parseInt(nScore - (nConsecAlphaLC * nMultConsecAlphaLC));
  }
  if (nConsecNumber > 0) {  // Consecutive Numbers exist
   nScore = parseInt(nScore - (nConsecNumber * nMultConsecNumber)); 
  }
  if (nSeqAlpha > 0) {  // Sequential alpha strings exist (3 characters or more)
   nScore = parseInt(nScore - (nSeqAlpha * nMultSeqAlpha));
  }
  if (nSeqNumber > 0) {  // Sequential numeric strings exist (3 characters or more)
   nScore = parseInt(nScore - (nSeqNumber * nMultSeqNumber));
  }

  /* Determine if mandatory requirements have been met */
        if (nLength >= nMinPwdLen) {
            nRequirements++;
            var nMinReqChars = 3;
            if (nAlphaUC >= 1) { nRequirements++; }
            if (nAlphaLC >= 1) { nRequirements++; }
            if (nNumber >= 1) { nRequirements++; }
            if (nSymbol >= 1) { nRequirements++; }
            if (nRequirements > nMinReqChars) {
                nScore = parseInt(nScore + (nRequirements * nMultRequirements));
            }
        }

  /* Determine complexity based on overall score */
        if (nLength < 2) {
            sComplexity = saStrength[index.TOOSHORT];
            sColor = "#eee"; //light gray
        }
        else if (nScore < 40) {
            sComplexity = saStrength[index.WEAK];
            sColor = "#f00"; //red
        }
  else if (nScore < 60) {
            sComplexity = saStrength[index.MODERATE];
            sColor = "#ff0"; //yellow
        }
  else {
            sComplexity = saStrength[index.STRONG];
            sColor = "#0f0"; //green
        }
 }
    oScorebar.innerHTML = sComplexity;
    oScorebar.style.backgroundColor = sColor;
}

Posted by '김용환'
,
Posted by '김용환'
,

 

 

ie버젼에 맞는 먼가 작업이 할 일이 생겼다.

ie7에서는 되는데, ie6에서는 에러가 난다. 그럴 경우에 사용하는 자바 스크립트..

 

자바 스크립트 코드는 안할줄 알았는데.. 흐흐흐 하지만 잼있다.

 

 

 

    function checkBrowser()
    {
        var agt=navigator.userAgent.toLowerCase();

        var is_major = parseInt(navigator.appVersion);
        var is_minor = parseFloat(navigator.appVersion);

        // *** BROWSER VERSION ***
        // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
        var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        var is_ie3    = (is_ie && (is_major < 4));
        var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
        var is_ie4up  = (is_ie && (is_major >= 4));
        var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
        var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
        var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
        var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
        var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
        var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
        var is_ie6down  = (is_ie || is_ie3  || is_ie4 || is_ie5  || is_ie5_5 || is_ie6);
        var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );

        if( is_ie7 == false) {
            ie7="false";
        } else {
            ie7="true";
        }
    }

    checkBrowser();
    if (ie7 == "true") {
        document.write("<input type='text' name='logdate' dojoType='dropdowndatepicker'  displayFormat='yyyyMMdd'  value='" + "<c:out value='${param.logdate}'/>" + "'" + "    > ");
    } else {
        document.write("<input type='text' name='logdate'   value='<c:out value="${param.logdate}"/>'   size=8 maxlength=8>");
    }

 

 

Posted by '김용환'
,