리버's 아름다운 소풍

1 2 3 
Korean Semantic Web Conference - 12월 4일

파이썬에서 어제 날짜는 다음의 코드로 구할 수 있다.



만약 시간까지 포함에서 구하려면 다음 코드를 사용하면 된다.


이 글의 관련글
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일
jQuery에서 특정 엘리먼트의 존재를 체크하기 위해서 먼저 다음 코드를 생각해 볼 수 있다.



하지만 위 코드는 원하는 대로 동작하지 않는다. 왜냐하면 jQuery의 셀렉터는 항상 객체를 반환하기 때문에 언제나 참으로 동작을 하게 된다. 엘리먼트가 존재하지 않은 경우에도 빈 객체를 반환하기 때문에 위 코드로는 존재 여부를 체크할 수 없고, 다음의 코드를 사용해야 한다.



length 특성을 사용하면 엘리먼트가 존재하지 않은 경우 0를 반환함므로 존재여부를 제대로 체크할 수 있다.
이 글의 관련글
    이글의 태그와 관련된 글이 없습니다.
일주일간 인기글
오늘 인기글

Hanterm on Cygwin/XFree86

Programming 2009/05/08 12:50 by 리버
Korean Semantic Web Conference - 12월 4일
Cygwin/XFree86에서 한글을 입력하기 위해서 한텀을 쓰고자 하시는 분들을 위해 Cygwin용으로 컴파일된 한텀을 올립니다.
다운로드:
hanterm.zip

한텀 실행파일





스크린캡쳐
이 글의 관련글
    이글의 태그와 관련된 글이 없습니다.
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일
IE8에는 자바스크립트 디버거가 포함되어 있지만 그전 버전에는 디버거가 없어서 자바스크립트 디버깅하기가 여간 짜증나는 일이 아니다. 'FirefoxFirebug같은 도구가 왜 없는거야 !!' MS에 불평만 하고 있었는데 정말 괜찮은 도구를 발견했다. CompanionJS. 웹개발하시는 분들은 꼭 다운받으세요.

다운로드

Companion.JS (pronounced Companion dot JS or CJS) is a Javascript debugger for IE. The current version is 0.5.
Companion.JS adds the following features to IE :

  • Detailled javascript error reporting (call stack and real file name where the error occured).
  • "Firebug"-like Console API feature.
  • Javascript console feature useful to inspect javascript objects at runtime.
  • A toolbar icon to open the Companion.JS panel.

Download the installer, guaranteed spyware/malware free and packaged with a straightforward and complete un-installer.
(Download zipped intaller for people unable to download .exe files due to proxy limitations)

To be able to use Companion.JS you'll need to have a Microsoft script debugger installed. There are many cases where you already have this component install. To check if you need it see Installing Companion.JS for details.

Here are some screenshots :


Detailled Error reporting

In the top-left corner the notifying panel which pops-up when an error occurs in the current page if the Companion.JS panel is not open. At the bottom of the page...



Console API feature
이 글의 관련글
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일
회사에서 아주 예전에 작성된 HTML을 수정하다가 하루종일 고생한 경험담을 얘기하고자 한다. 결론을 얘기하면 원인은 XHTML 표준을 지키지 않아서 였는데, 이게 원인일 줄이야!!!

다음과 같은 스타일의 HTML 태그가 있다고 하자. 과거에 CSS를 잘 사용하지 않을 때는 form 태그의 기본 패딩값에 의해 테이블 레이아웃이 깨지는 것을 방지하기 위해서 내가 자주 사용하던 스타일이다.



여기에다 자바스크립트로 폼에 input 태그를 하나 추가하고, input 박스에 값을 치고 submit 버튼을 누르면 IE에서는 input 박스에 입력된 값이 전송이 되지만, 왠일인지 Firefox에서는 새로 추가된 input 박스의 내용은 전송이 되지 않는거다.

정말 하루 종일 삽질하다가 발견한 원인, 그리고 해결방안은 다음과 같이 XHTML을 준수하는 스타일로 HTML을 코딩하는 거였다.



표준을 지키는게 중요함을 다시 한번 느낀 하루였다.

이 글의 관련글
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일
PHP에는 변수의 내용을 쉽게 볼 수 있는 print_r 이란 함수가 있다. 변수형태와 상관없이 변수명만 인자로 넘겨주면 변수에 저장된 내용을 재귀적으로 표시해 줘서 디버깅시 특히 요긴하게 쓸 수 있다. ASP에서는 안타깝게도 유사한 함수가 없어서 비슷한 기능을 하는 함수를 만들어 봤다.



위를 브라우져에서 실행해서 소스보기를 하면 다음의 결과를 얻을 수 있다.

123(vbString)
Array
    (
        [0] => 1(vbString)
        [1] => 2(vbString)
        [2] => 3(vbString)
        [3] => 4(vbString)
        [4] => 5(vbString)
    )

Session
(
    Session.StaticObjects
    (
    )
    Session.Contents
    (
    )
)
배열도 지원하고, Application, Session, Request 객체의 내용도 볼 수 있다. 자체적으로 쓰는 객체는 "Unimpleneted TypeName"이란 결과가 나올텐데, 이는 소스에다 해당 객체를 출력하는 부분을 추가해 주면 된다.
이 글의 관련글
일주일간 인기글
오늘 인기글
TAG , ,
Korean Semantic Web Conference - 12월 4일

VBScript는 객체 지향적인 측면에서는 많이 부족한 언어다. 상속이나 다형성을 전혀 제공하고 있지 않아서 클래스를 만드는게 오히려 불현할 때가 더 많은 게 사실이다. 조금이나마 이런 단점을 보안해 줄 수 있는 함수가 하나 있는데 GetRef 이다.

GetRef는 인자로 넘긴 문자열에 해당하는 함수 포인터를 반환하는 기능을 하는 함수이다.  이 함수를 이용하여 VBscript에서 간단하게 이벤트 드리븐(event driven) 프로그래밍하는 좋은 예제가 있어서 소개할려고 한다.

VBScript doesn't have an event implementation so if you fancy having features like attaching handlers which will respond to specific events on your object you can do it simply by using the GetRef function and a bit of "syntactic sugar".

I'm using ASP in these examples cos it's easy.

Example 1 - Simple Events

'Create a handler
Function MyHandler()
   Response.Write "Hello from the handler!"
End Function

'Create an event
Dim OnLoad
Set OnLoad = GetRef("MyHandler")

'Fire the event
OnLoad()

Here we've created a simple event which takes one handler function and fired the event which in turn has called the function we attached.

To turn this in to a more useful event system we can use an array for the OnLoad event variable thus...

'Create some handlers
Function MyHandler1()
   Response.Write "Hello from handler 1!"
End Function

Function MyHandler2()
   Response.Write "Hello from handler 2!"
End Function

'Create an event
Dim OnLoad
OnLoad = Array(GetRef("MyHandler1"), GetRef("MyHandler2"))

'Fire the event
For Each handler In OnLoad
   handler()
Next

Example 2 - Event Arguments

In most event implementations the event handlers take one argument, passed to them by the fired event, which contains things like the type of event and a reference to the object on which it was fired etc.

'Create a handler which takes one argument
Function MyHandler(e)
   Response.Write "Hello from the handler - i was called by " & e
End Function

'Create two events
Dim OnLoad
Set OnLoad = GetRef("MyHandler")

Dim OnUnload
Set OnUnload = GetRef("MyHandler")

'Fire the events
OnLoad("Load")
OnUnload("Unload")

Wrapping it up

We've established we can do all the basics of events, now all we need to do is wrap it up in a few classes to make it usable.

First we need an Event class that we can instantiate for each event we want. This will have to expose an event arguments property and methods for attaching handlers and firing the event. It will also have to keep track internally of the attached handlers. Lets have a go...

Class clsEvent

   'An array to keep track of our handlers
   Private aryHandlers()

   'Our event arguments object to be passed 
   'to the handlers
   Public EventArgs

   Private Sub Class_Initialize()
      ReDim aryHandlers(-1)
      Set EventArgs = New clsEventArgs
   End Sub

   Private Sub Class_Terminate()
      Set EventArgs = Nothing
      Erase aryHandlers
   End Sub

   'Method for adding a handler
   Public Function AddHandler(strFunctionName)
      ReDim Preserve aryHandlers(UBound(aryHandlers) + 1)
      Set aryHandlers(UBound(aryHandlers)) = _
         GetRef(strFunctionName)
   End Function

   'Method for firing the event
   Public Function Fire(strType, objCaller)
      EventArgs.EventType = strType
      Set EventArgs.Caller = objCaller
      For Each f In aryHandlers
         f(EventArgs)
      Next
   End Function

End Class

Next we need an EventArgs class for passing data about the event to the handlers. This just needs three properties; event type, caller and an arguments collection for event type specific things.

Class clsEventArgs

   Public EventType, Caller, Args

   Private Sub Class_Initialize()
      Set Args = CreateObject("Scripting.Dictionary")
   End Sub

   Private Sub Class_Terminate()
      Args.RemoveAll
      Set Args = Nothing
   End Sub

End Class

Next our class that has an event, in this case an OnLoad which fires after the object's Load method is called. We'll also create a few handlers and do a trial run.

Class MyClass

   Public OnLoad

   Private Sub Class_Initialize()
      'Setting up our event
      Set OnLoad = New clsEvent

      'Adding an argument
      OnLoad.EventArgs.Args.Add "arg1", "Hello"
   End Sub

   Public Function Load()
      Response.Write "loading the object here!<br />"
      
      'Firing the event
      OnLoad.Fire "load", Me
   End Function

End Class


'A couple of handling function for the events
Function EventHandler(e)
   Response.Write "<h2>EventHandler</h2>"
   Response.Write "<p>Event """ & e.EventType & """ fired by object
of type " & TypeName(e.Caller) & ".</p>"
End Function

Function EventHandler2(e)
   Response.Write "<h2>EventHandler2</h2>"
   For Each x In e.Args
      Response.Write x & ": " & e.Args(x) & "<br />"
   Next
End Function

'instantiate the object, attach the handlers and call the load
Set myObj = New MyClass
myObj.OnLoad.AddHandler("EventHandler")
myObj.OnLoad.AddHandler("EventHandler2")
myObj.Load()

Event based programming reverses the responsibility for code execution within your program. In conventional procedural programming it would be the responsibility of the myObj class to make sure the two event handlers were fired when it's Load method was called. By using an OnLoad event instead myObj doesn't have to know anything about the environment in which its executing, it just blindly fires the event and any attached handlers will be called. In this way you can add additional functions which run when myObj's Load method is called without modifying MyClass.

In more complex systems being able to add functionality with a minimum of intrusion into other parts of the system is a big bonus and event based programming is an easy way of achieving it.



출처: http://derek-says.blogspot.com/2006/10/simple-event-driven-programming-using.html

이 글의 관련글
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일

ASP에 URL을 인코딩하려면 Server 객체의 URLEncode 메쏘드를 사용하면 된다. 그럼 디코딩은 어떻게 하지? ASP환경이 아닌 환경- 예를 들면 도스창에서 VBScript로 스크립트를 짤 때 - 에서는 Server 객체가 제공이 안되는데 이곳에서는 인코딩이나 디코딩을 어떻게 해야 하는가?

여기에 대한 대안으로 사용할 수 있는 함수인 URLEncode, URLDecode를 소개한다.

이 글의 관련글
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일
한국정보진흥원(KISA)의 SEED 암호알고리즘을 ASP에서 사용하기 위해서 만든 ECPlaza.Seed 컴포넌트의 소스를 공개합니다. 이 컴포넌트는 ANSI X.923 패딩을 사용했고, BASE64 인코딩 절차를 한번 더 거쳤습니다.

사용법은 간단합니다.

ECPlazaSeed.dll을 다운로드 받은 다음 적당한 폴더에 복사한뒤
regsvr32 ECPlazaSeed.dll

을 하면 컴포넌트 등록이 끝납니다.

등록 확인은 테스트 스크립트를 다운 받아서
cscript test.vbs

를 도스창에서 실행해서 오류가 발생하지 않으면 제대로 둥록이 된 겁니다.


이 컴포넌트는 두가기 메쏘드를 제공합니다.

Encrypt(sPlainText, sKey)
sPlainText 평서문을 sKey를 가지고 SEED 암호화 및 Base64
인코딩한 결과를 반환합니다. sKey는 반드시 16자리여야만 합니다.


Decrypt(sCipherText, sKey)
sCipherText 암호문을 Base64 디코딩을 하고, SEED 복호화를
거쳐서 원 평서문을 반환합니다.

사용 예제


소스를 컴파일 하기 위해서는 Visual C++ 6가 필요합니다. 전 아직도 이걸 쓴답니다.ㅜ.ㅜ
Visual Stuio .Net에서는 컴파일 해보지 않앗습니다. 아마 컴파일이 안 될것 같습니다.


다운로드:
소스:



DLL :


테스트 스크립트 :




참고:
한국정보진흥원 SEED 알고리즘
SEED 알고리즘 - Java API
Seed알고리즘을 이용한 암호화 복호화 기능 수행하는 DLL 만들기

Daum 블로거뉴스
블로거뉴스에서 이 포스트를 추천해주세요.
추천하기
이 글의 관련글
일주일간 인기글
오늘 인기글
Korean Semantic Web Conference - 12월 4일

이씨플라자는 중문으로 서비스되는 이씨플라자 중문 사이트가 따로 있고, 대부분의 사용자는 중국업체들이다. 서버는 현재 국내 KTNET IDC에 있다. 요즘 알 수 없는 이유(?)로 중국에서 이씨플라자 중문 사이트에 접속하는데 장애가 많이 발생해서, 이를 탐지하는 프로그램을 만들어야만 했다. 중국사용자 환경에서 접속을 테스트해야 하니깐 중국내 공개된 proxy 서버를 이용하기로 했다.

전에 올린 "MSXML2.ServerXMLHTTP 사용하여 원격 웹서버 내용 갖고 오기" 포스트에서 사용한 MSXML2.ServerXMLHTTP 컴포넌트를 사용하려고 했는데 허걱.. 이 컴포넌트는 Proxy 서버를 지정할 수 있는 방법을 제공하지 않는 것이다. 별 수 없이 막강한 함수를 갖고 있는 php를 좀 뒤져봤다. 역시 여기에는 해결책이 있었다.

Proxy 서버를 이용해서 http 통신을 하는 get_contents 라는 함수를 하나 만들어서 사용했다. 혹시나 Proxy 서버를 사용할 필요가 있으신 분들은 참고하시기를.

이 글의 관련글
일주일간 인기글
오늘 인기글
1 2 3 
BLOG main image
리버's 아름다운 소풍
이씨플라자 개발자가 살아가는 이야기
by 리버

공지사항

카테고리

전체 (327)
살.아.가.며. (184)
웹.이.야.기. (74)
OS (13)
Software (17)
Security (4)
SQL Server (8)
Programming (24)

달력

«   2009/11   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
textcubeDesignMyselfget rss

495

400

-30 days

today : 97