역삼각함수란 삼각함수의 역함수를 의미하고,

역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.

수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데, ErLang 언어에서는 asin 함수로 구현되어 있다.

OCaml 언어는 F#, Scala 언어 처럼 비순수 함수형 언어이다. (여기서 바순수라 함은 절차적 언어 처럼 for, while, break 등의 제어문 기능을 갖고 있어서 C 언어나 Java 언어 처럼 작성할 수 있다는 뜻이다.)

OCaml 언어로 작성된 소스에서는 각 명령 줄이 두 개의 세미콜론(;;)으로 끝나야 한다.

영문 위키피디아의 OCaml  프로그래밍 언어 설명: http://en.wikipedia.org/wiki/OCaml

OCaml 언어로 부동소수점수(float 타입, 이느 C 언어와 Java 언어의 double 타입에 해당)의 사칙 연산 기로가 +, -, *, / 가 아니라 각 연산지 뒤에 점(.)을 하나씩 추가한 +., -., *., /. 임에 주위 한다. 정수(int) 타입의 사칙 연산 기호는 +, -, *, / 를 그대로 사용한다. 그리고 float 타입과 int 타입을 섞어서 연산할 때는 반드시 타입을 통일시키는 작업을 해야 한다.

아래에서 샤프 기호(#)는 OCaml 의 프롬프트이다. 테스트는 진한 글자로 된 부분만 입력하면 된다.

명령프롬프트> ocaml
        Objective Caml version 3.12.1

# 3 + 1.2;;
Characters 4-7:
  3 + 1.2;;
      ^^^
Error: This expression has type float but an expression was expected of type
         int
# (float_of_int 3) + 1.2;;
Characters 0-16:
  (float_of_int 3) + 1.2;;
  ^^^^^^^^^^^^^^^^
Error: This expression has type float but an expression was expected of type
         int
# (float_of_int 3) +. 1.2;;
- : float = 4.2
# 3 + (int_of_float 1.2);;
- : int = 4

 

아래의 소스는 컴파일 없이 "ocaml 소스파일명" 으로 실행해도 되고, "ocamlc -o 실행파일명 소스파일명" 컴파일한 뒤 생성된 실행파일을 실행해도 된다.

컴파일하여 실행하는 경우 현재 최신 버전인 OCaml 4.00.1 은 "NTVDM CPU CS ......" 에러가 발생힌디.


OCaml 3.12.* 에서는 컴파일 하여 실행하더러도 아무 문제가 없다.

(윈도우 Vista, XP, 7 등에서 OCaml 3.12.1 은 설치되는 중에 시스템 환경변수 PATH 의 값을 삭제해 버리므로 주의를 요한다. PATH 의 값을 다른 곳에 저장해 두었다가 복원해야 함.)

 

(*
   Filename: testArcSine.ml
 
   Execute: ocaml testArcSine.ml

     Or
 
   Compile: ocamlc -o testArcSine testArcSine.ml
   Execute: ./testArcSine
 
     Or
 
   Compile: ocamlc -o testArcSine.exe testArcSine.ml
   Execute: testArcSine.exe
 
   Date: 2013. 1. 3.
   Copyright (c) pkim _AT_ scripts.pe.kr
*)


let asinh x = log(x +. sqrt(x *. x +. 1.0));;

let acosh x = log(x +. sqrt(x *. x -. 1.0));;

let x = -0.9;;
let y = asin(x);;

let _ = Printf.printf "y = asin(%g) = %.9f\n" x y;;
let _ = Printf.printf "sin(y) = sin(%.9f) = %g\n" y (sin y) ;;
let _ = Printf.printf "\n";;

let x = 1.1;;
let u = acosh(x);;
let _ = Printf.printf "u = acosh(%g) = %.10f\n" x u;;
let v = asinh(x);;
let _ = Printf.printf "v = asinh(%g) = %.10f\n" x v;;

let _ = Printf.printf "cosh(u) = cosh(%.10f) = %g\n" u (cosh u);;
let _ = Printf.printf "sinh(v) = sinh(%.10f) = %g\n" v (sinh v);;

(*
Output:
y = asin(-0.9) = -1.119769515
sin(y) = sin(-1.119769515) = -0.9

u = acosh(1.1) = 0.4435682544
v = asinh(1.1) = 0.9503469298
cosh(u) = cosh(0.4435682544) = 1.1
sinh(v) = sinh(0.9503469298) = 1.1
*)

 

 

Posted by Scripter
,

Jython은 JVM(자바 가상 기계, Java Virtual Machine) 상에서 동작하는 파이썬 인터프리터이다. 한 때는 JPython이라는 이름으로 불리우기도 했는데, 지금은 더 짧은 이름 Jython으로 통한다.

리녹스 시스템에 슈퍼유저(su) 권한으로 Jython을 러치하면 캐쉬 디렉토리의 설정 문제로 약간은 다소 귀찮은 일이 발샐한다. 여기서는 이런 문제도 해결하고 Tomcat과 연동하여 PyServlet을 동자기켜 보기로 한다.


* Jython 2.5.3 다운로드

Jython의 현재 최신 릴리즈는 2.5.3이다 Jython 홈페이지 http://jythom.org 에서 jython-installer-2.5.3 을 다운받는다. 다운받은 파일을 적당한 곳으로 옮기고, 터미널에서 그 폴더로 체인지 디렉토리(cd)하여 다음 java 명령으로 jython을 설치한다.

$ sudo java -jar jython-installer-2.5.3.jar






이 글에서는 Jython을 /usr/local/jython-2.5.3에 서리한 것으로 간주하고 계속 진행한다.

/etc/profile에 환경변수 JYTHON_HOME과 PATH를 잡아준다. (다음 두 줄 추가)

$ sudo vi /etc/profile

JYTHON_HOME=/usr/local/jthon-2.5.3; export JYTHON_HOME

PATH=$JYTHON_HOME/bin"$PATH; export PATH


변경된 환경변수 JYTHON_HOME과 PATH를 현재의 셀에 적용시킨다.

$ source /etc/profile



* jython 인터프리터 실행

jython 명령을 사용하면 캐쉬 디렉토리 관련 에러가 뜨면서 실행은 된다.


$ jython hello.py
*sys-package-mgr*: can't create package cache dir, '/usr/local/jython-2.5.3/cachedir/packages'
Hello, world!

이제 이 문제를 해결해 보자. 해결하는데 두 가지 방법이 있다. 하나는 jython 명령을 내릴 때 -D 옵션을 쓰는 것이도, 다른 하나는 ~/.jython 파일에서 캐쉬 디렉토리를 잡아주는 방법이다.

(참고. 전체 경로에 ~ 나 $HOME 은 적어봐야 jython이 인식하지 못한다.)

$ jython -Dpython.cachedir=전체경로 hello.py
Hello, world!


다음 한 줄로 된 파일 ~/.jython 을 작성한다.

$ vi ~/.jython

python.cachedir=전체경로


$ jython hello.py
Hello, world!



PyServlet 설정 및 실행

* web.xml 파일에 추가될 내용

    <servlet>
        <servlet-name>PyServlet</servlet-name>
        <servlet-class>org.python.util.PyServlet</servlet-class>
        <init-param>
         <param-name>python/home</param-name>
         <param-value>/opt/usr/local/jython-2.5.3</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>PyServlet</servlet-name>
        <url-pattern>*.py</url-pattern>
    </servlet-mapping>



* 수정 전 PyServlet: enter.py

import javax.servlet.http as http

class enter(http.HttpServlet):
  def doPost(self, request, response):
    session = request.getSession(1)
    counter = session.getAttribute("counter")
    try:
        counter = int(counter)
    except: # counter is None
        counter = 0
    counter += 1
    session.setAttribute("counter", counter)
    response.contentType = "text/html; charset=utf-8"
    out = response.outputStream print >> out, """The string you entered is: %s. <br />
You have played this game %s times.\n<hr>""" % (
request.getParameter("thing"), counter)
    self.doGet(request, response)

  def doGet(self, request, response):
    response.contentType = "text/html; charset=utf-8"
    out = response.outputStream print >> out, """Enter a string: <form method="post">
<input type="text" name="thing">
<input type="submit">
</form>"""



* Ubuntu에서 Tomcat 6 & Jython 2.5.3을 사용하여 수정전 enter.py를 실행한 장면




* 수정 후 PyServlet: enter.py (utf-8 한글 파라미터 처리를 위해 파란색 부분만 수정됨)

# -*- encoding: utf-8 -*-

import javax.servlet.http as http

class enter(http.HttpServlet):

  def doPost(self, request, response):
    session = request.getSession(1)
    counter = session.getAttribute("counter")
    try:
        counter = int(counter)
    except: # counter is None
        counter = 0
    counter += 1
    session.setAttribute("counter", counter)
    request.setCharacterEncoding("utf-8")
    response.contentType = "text/html; charset=utf-8"
    out = response.outputStream
    print >> out, """The string you entered is: %s. <br />
You have played this game %s times.\n<hr>""" % (
request.getParameter("thing").encode("utf-8"), counter)
    self.doGet(request, response)

  def doGet(self, request, response):
    response.contentType = "text/html; charset=utf-8"
    out = response.outputStream
    print >> out, """Enter a string: <form method="post">
<input type="text" name="thing">
<input type="submit">
</form>"""


* Ubuntu에서 Tomcat 6 & Jython 2.5.3을 사용하여 수정된 enter.py를 실행한 장면







Posted by Scripter
,

 Mac OS X 또는Ubuntu 등의 리뉵스에 Grails 2.1.1 을 설치하는 방법을 알아본다

Grais 를 설치하기 위해서는 JDK(Java Development Kit) 6.0 이상이 ㅁㄴ저 설치되어 있으면 충분하다. (Groovy는 설치되어 있지 않아도 된다.)

Grails 홈페이지는 http://grails.org 이다. 현재 최신 릴리즈는 Grails 2.1.1 이다. gails-2.1.1.zip 파일을 다운받아서 압축 해제한 다음 적당한 곳으로 옮긴다.

$ unzip grails-2.1.1.zip

$ sudo mv grails=2.1.1 /usr/local/grails-2.1.1

한경변수 GRAILS_HOME, JAVA_HOME, PATH 를 잡아 준다.

$ sudo vi /etc/profile

하여 다음 세 줄을 추가한다.

JAVA_HOME=................' export JAVA_HOME

GAILS_HOME=/usr/local/grails-2.1.1; export GRAILS_HOME

PATH=$GRAILS_HOME/bin:$JAVA_HOME/bin:$PATH; export PATH


변경된 환경변수의 값을 현재의 ㅌ미널 셀에 적요이킨다.

$ source /etc/profile


홈 폴더(~) 밑에 test 폴더를 만들고 또 그 밑에 테스트르 위한 grails 폴더를 만든 후 ~/test/grails 폴더로 간다.


$ mkdir ~/test
$ mkdir ~/test/grals
$ cd ~/test/grails


~/test/grails 폴더에서 helloworld 애플리케이션 생성한다.

$ grails create-app helloworld
 

* grails 애플리케이션 실행하기

~/test/grails 폴더의 서브폴더 helloworld 러 가서 Grails 애플리케이션을 실행시킨다.

$ cd helloworld

$ grails run-app


 웹브라우저로 http://localhost:8080/helloworld 를 방문한다.



 

* 첫번 째 컨트롤러 만들기

$ grails create-controller hello

[grails-app/contollers/helloworld/HelloController.groovy 파일의 내용]

package helloworld

class HelloController {

    def index() { }

    def world() {
        render "Hello, world! <br />\n${new Date()}<br />\n"
        render "안녕하세요? GRails 2.1.1<br />\n"
    }
}

 

$ grails run-app

웹브라우저로 http://localhost:8080/helloworld/hello/world 를 방문한다.


 

 

 

Posted by Scripter
,

리눅스(Ubuntu/Fedora/CentOS 등)에 Tomcat 7.0.33 설치하기

http://tomcat.apache.org/download-70.cgi#7.0.33 에서 apache-tomcat-7.0.33.tar.gz 의 압축을 풀어서 원하는 폴더(예를 들어, /usr/local/tomcat7)로 옮긴다.

$ sudo mv apache-tomcat-7.0.33 /usr/local/tomcat7


* /etc/profile 파일에 다음 두 줄을 추가

$ sudo vi /etc/profile

TOMCAT_HOME=/usr/local/tomcat7; export TOMCAT_HOME
PATH=$TOMCAT_HOME/bin; export PATH


* 변경된 한경변수 적용하기

$ source /etc/profile


* Tomcat 시작하기

$ startup.sh

* Tomcat 종료하기

$ shutdown.sh


* 설치 후 초기 화면 학인하기



* $TOMCAT_HOME/webapps/examples/WEB-INF/web.xml 파일에 추가할 내용

    <servlet>
        <servlet-name>Groovy</servlet-name>
        <servlet-class>groovy.servlet.GroovyServlet</servlet-class>
    </servlet>

    <servlet>
        <servlet-name>GTemplate</servlet-name>
        <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
        <init-param>
         <param-name>groovy.source.encoding</param-name>
         <param-value>UTF-8</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>GTemplate</servlet-name>
        <url-pattern>*.ghtml</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>GTemplate</servlet-name>
        <url-pattern>*.gsp</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Groovy</servlet-name>
        <url-pattern>*.groovy</url-pattern>
    </servlet-mapping>



* ($TOMCAT_HOME/webapps/example 폴더에 저정된) hello.groovy 파일의 내용

response.setContentType("text/html; charset=utf-8")

println "Hi! Hello, how are you? I am Groovlet!<br />"
println "안녕하세요? 나는 그루블릿입니다.<br />"
println "${new Date()}<br />"



* hello.groovy의 실행 확인



* ($TOMCAT_HOME/webapps/example 폴더에 저정된) gugudan.gsp 파일의 내용

<h2>구구단 표 출력 </h2>
<hr />

<% for (dan in 2..9) { %>
<fieldset id="dan" style="width:150; display: inline-block;">
<legend>[ <%= dan %>단 ]</legend>
<p style="width: 80; margin: 5 10; padding: 5 20; border: dotted; display:inline-block;">
<% 9.times { x -> %>
  <%= dan %> &times; <%=  x + 1 %> = <%=  dan*(x + 1) %> <br />
<% } %>
</p>
</fieldset>
<% if (dan == 5) { %> <br /> <% } %>
<% } %>

<hr />
현재 시각은 <%= new Date() %>  입니다.


* gugudan.gsp 의 실행 확인





Posted by Scripter
,

 

윈도우에서 Grails 2.1.1 을 설치한 후, 한경변수 GRAILS_HOME, JAVA_HOME, PATH 가 모두 잡혔는데도 불구하고 "rails create-app" 명령시 에러

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre7

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

가 나는 경우가 있다. (리눅스/유닉스에서는 이런 경우가 없음 )

이럴 때는 startGrails.bat 파일을 텍스트 편집기로 열어서 42번째 줄

%COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul

@rem %COMMAND_COM% /C DIR "%JAVA_HOME%" 2>&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul

로 고쳐서 주석처리 한다. 그러면 "grails create-app" 명령이 잘 된다.

다음은 C:\test\grails 폴더에서 helloworld 애플리케이션을 성공적으로 생성한 경우의 출력이다.

C:\test\grails> grails create-app helloworld

| Downloading: c:\GRails211\lib\org.springframework.uaa\org.springframework.uaa.
| Downloading: c:\GRails211\lib\com.googlecode.json-simple\json-simple\ivy-1.1.x
| Downloading: c:\GRails211\lib\com.googlecode.concurrentlinkedhashmap\concurren
| Downloading: c:\GRails211\lib\org.springframework.uaa\org.springframework.uaa.
| Downloading: c:\GRails211\lib\com.google.protobuf\protobuf-java\jars\protobuf-
| Downloading: c:\GRails211\lib\com.googlecode.json-simple\json-simple\jars\json
| Downloading: c:\GRails211\lib\org.bouncycastle\bcpg-jdk15\jars\bcpg-jdk15-1.45
| Downloading: c:\GRails211\lib\org.bouncycastle\bcprov-jdk15\jars\bcprov-jdk15-
| Downloading: c:\GRails211\lib\org.springframework\spring-test\jars\spring-test
| Downloading: c:\GRails211\lib\com.googlecode.concurrentlinkedhashmap\concurren
| Downloading: c:\GRails211\lib\org.apache.ant\ant-launcher\jars\ant-launcher-1.
| Downloading: c:\GRails211\lib\org.apache.ant\ant-junit\jars\ant-junit-1.8.2.ja
| Downloading: c:\GRails211\lib\org.apache.tomcat.embed\tomcat-embed-core\jars\t
| Downloading: c:\GRails211\lib\org.apache.tomcat.embed\tomcat-embed-jasper\jars
| Downloading: c:\GRails211\lib\org.apache.tomcat.embed\tomcat-embed-logging-log
| Downloading: c:\GRails211\lib\commons-beanutils\commons-beanutils\ivy-1.8.3.xm
| Downloading: c:\GRails211\lib\commons-validator\commons-validator\ivy-1.3.1.xm
| Downloading: c:\GRails211\lib\commons-collections\commons-collections\ivy-3.2.
| Downloading: c:\GRails211\lib\org.hibernate.javax.persistence\hibernate-jpa-2.
| Downloading: c:\GRails211\lib\commons-fileupload\commons-fileupload\ivy-1.2.2.
| Downloading: c:\GRails211\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-1
| Downloading: c:\GRails211\lib\commons-beanutils\commons-beanutils\jars\commons
| Downloading: c:\GRails211\lib\commons-validator\commons-validator\jars\commons
| Downloading: c:\GRails211\lib\aopalliance\aopalliance\jars\aopalliance-1.0.jar
| Downloading: c:\GRails211\lib\commons-codec\commons-codec\jars\commons-codec-1
| Downloading: c:\GRails211\lib\commons-collections\commons-collections\jars\com
| Downloading: c:\GRails211\lib\commons-lang\commons-lang\jars\commons-lang-2.6.
| Downloading: c:\GRails211\lib\org.hibernate.javax.persistence\hibernate-jpa-2.
| Downloading: c:\GRails211\lib\org.springframework\spring-core\jars\spring-core
| Downloading: c:\GRails211\lib\org.springframework\spring-aop\jars\spring-aop-3
| Downloading: c:\GRails211\lib\org.springframework\spring-aspects\jars\spring-a
| Downloading: c:\GRails211\lib\org.springframework\spring-asm\jars\spring-asm-3
| Downloading: c:\GRails211\lib\org.springframework\spring-beans\jars\spring-bea
| Downloading: c:\GRails211\lib\org.springframework\spring-context\jars\spring-c
| Downloading: c:\GRails211\lib\org.springframework\spring-context-support\jars\
| Downloading: c:\GRails211\lib\org.springframework\spring-expression\jars\sprin
| Downloading: c:\GRails211\lib\org.springframework\spring-jdbc\jars\spring-jdbc
| Downloading: c:\GRails211\lib\org.springframework\spring-jms\jars\spring-jms-3
| Downloading: c:\GRails211\lib\org.springframework\spring-orm\jars\spring-orm-3
| Downloading: c:\GRails211\lib\org.springframework\spring-tx\jars\spring-tx-3.1
| Downloading: c:\GRails211\lib\org.springframework\spring-web\jars\spring-web-3
| Downloading: c:\GRails211\lib\org.springframework\spring-webmvc\jars\spring-we
| Downloading: c:\GRails211\lib\org.grails\grails-datastore-gorm\jars\grails-dat
| Downloading: c:\GRails211\lib\org.grails\grails-datastore-core\jars\grails-dat
| Downloading: c:\GRails211\lib\org.grails\grails-datastore-simple\jars\grails-d
| Downloading: c:\GRails211\lib\org.aspectj\aspectjweaver\jars\aspectjweaver-1.6
| Downloading: c:\GRails211\lib\commons-fileupload\commons-fileupload\jars\commo
| Downloading: c:\GRails211\lib\commons-dbcp\commons-dbcp\jars\commons-dbcp-1.4.
| Downloading: c:\GRails211\lib\commons-pool\commons-pool\jars\commons-pool-1.5.
| Downloading: c:\GRails211\lib\net.sf.ehcache\ehcache-core\jars\ehcache-core-2.
| Downloading: c:\GRails211\lib\org.slf4j\jcl-over-slf4j\jars\jcl-over-slf4j-1.6
| Downloading: c:\GRails211\lib\org.slf4j\jul-to-slf4j\jars\jul-to-slf4j-1.6.2.j
| Created Grails Application at C:\test\grails/helloworld

 

grails 애플리케이션 실행하기

C:\test\grails> cd helloworld

C:\test\grails\helloworld> grails run-app

 웹브라우저로 http://localhost:8080/helloworld 를 방문한다.

 

 

첫번째 컨트롤러 만들기

C:\test\grails\helloworld> grails create-controller hello

[grails-app/contollers/helloworld/HelloController.groovy 파일의 내용]

package helloworld

class HelloController {

    def index() { }

    def world() {
        render "Hello, world! <br />\n${new Date()}<br />\n"
        render "안녕하세요? GRails 2.1.1<br />\n"
    }
}

 

C:\test\grails\helloworld> grails run-app

웹브라우저로 http://localhost:8080/helloworld/hello/world 를 방문한다.

 

 

 

Posted by Scripter
,

 

단계 1. Ruby 1.9.3 p-327 설치하기

http://www.ruby-lang.org/en/downloads/ 의 좌측 메뉴에서  Ruby 1.9.3-p327 를 클릭하여 다운로드하여 Ruby 1.9.3 설치한다.

 

단계 2. RubyGems 1.8.24  설치하기

http://rubygems.org/pages/download 에서 ZIP 을 클릭하여 rubygens-1,8.24.zip 을 다운로드하여 압축을 풀고, 명령 프롬프트에서 명령

프롬프트> set PATH=C:\ruby193\bin;%PATH%

으로 환경변수 PATH 를 설정하고, 명령

프롬프트> cd  {RubyGems가 설치된 폴더}\rubygems-1.8.24

으로 압축 해제된 폴더 안으로 들어가서 명령

프롬프트> ruby setup.rb

으로 RubyGems 1.8.24를 설치한다.

 

단계 3. Rails 3.2.9 설치하기

명령

프롬프트> gem install rails

으로 Rails 3,2,9를 설치한다.

 

단계 4. Rails 애플리케이션 생성하기

프롬프트> rails new myapp

하면 gem istall json -v '1.7.5' 를 확인하라는 에러 메세지가 뜬다. 명렬

프롬프트> gem install json -v=1.7.5

으로 json을 설치하려고 시도하지만 json 은 잘 설치되지 않는다. 이를 해결하자면  Devlopment-Kit 를 설치해야 한다.  http://rubyinstaller.org/downloads 의 좌측메뉴에서 DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe 를 클릭하여 다운로드하여 이를 실행한다.

* Devlopment-Kit의 사용 설명: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit 을 참고한다.

Devlopment-Kit 가 설치된 폴더로 가서 명령 'ruby dk.rb install --force' 를 실행한다.

프롬프트> cd c:\DevKit

프롬프트> ruby dk.rb install --force 

Error loading 'config.yml'.  Have you run 'ruby dk.rb init' yet?

이런 에러를 내면서 위의 명령이  먹히지 않는 경우가 있다.

config.yml 파일이 없다고 불평을 하는 것 같은데, config,yml 파일을 만들기 위해 명령

프롬프트> ruby dk.rb init

을 실행해 보지만 더 길다란 에러메세지가 출력된다.

 c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:173:in `tr': invalid byte sequence i
n UTF-8 (ArgumentError)
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:173:in `initialize'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:231:in `exception'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:231:in `raise'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:231:in `check'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:254:in `OpenKey'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:385:in `open'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:496:in `open'
        from dk.rb:118:in `block in scan_for'
        from dk.rb:116:in `each'
        from dk.rb:116:in `scan_for'
        from dk.rb:138:in `block in installed_rubies'
        from dk.rb:138:in `collect'
        from dk.rb:138:in `installed_rubies'
        from dk.rb:146:in `init'
        from dk.rb:313:in `run'
        from dk.rb:332:in `<main>'

좀 황당하하기는 하지만, 잠시 https://groups.google.com/forum/#!msg/rubyinstaller/zCj6ttx_GdI/LPFdToNc4O0J 를 참고하면서 마음을 가다듬는다. 저 참고대로 따라서 할 것은 아니다. 이는 Ruby 1.9.3 버전에서 가끔 있을 수 있는 에러이다. 원인은 현재 명령 프롬프트의 코드페이지가 맞지 않아서 그런 것이다. 코드페이지가 utf-8로 되어 있었기 때문이다. DevKit 를 서치하는 동안만 잠시 MS939 로 돌아갔다 오면 된다. 

프롬프트> cp 949

프롬프트> ruby rk.db init

[INFO] found RubyInstaller v1.8.7 at C:/Ruby187
[INFO] found RubyInstaller v1.9.1 at C:/Ruby191
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

프롬프트> ruby rk.rb install --force

[INFO] Installing 'C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/defaults/operating
_system.rb'
[INFO] Installing 'C:/Ruby187/lib/ruby/site_ruby/devkit.rb'
[INFO] Installing 'C:/Ruby191/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operati
ng_system.rb'
[INFO] Installing 'C:/Ruby191/lib/ruby/site_ruby/devkit.rb'
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

프롬프트> cp 65001

그 다음 명령

프롬프트> gem install json -v=1.7.5

을 실행한다. 그러면 json 이 잘 설치된다.

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed json-1.7.5
1 gem installed
Installing ri documentation for json-1.7.5...
Installing RDoc documentation for json-1.7.5...

(아직 sqlite3가 설치되어 있지 않다면, 명령

프롬프트> gem install sqlite3

으로 sqlite3 를 설치한다.) 이제 명령

프롬프트> rails new myapp

으로  Rails 애플리케이션 myapp가 생성된다.

      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.gitkeep
      create  app/models/.gitkeep
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  lib/assets
      create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  test/fixtures
      create  test/fixtures/.gitkeep
      create  test/functional
      create  test/functional/.gitkeep
      create  test/integration
      create  test/integration/.gitkeep
      create  test/unit
      create  test/unit/.gitkeep
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.gitkeep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.gitkeep
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
         run  bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.2)
Using i18n (0.6.1)
Using multi_json (1.3.7)
Using activesupport (3.2.9)
Using builder (3.0.4)
Using activemodel (3.2.9)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.2.1)
Using actionpack (3.2.9)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.4.4)
Using actionmailer (3.2.9)
Using arel (3.0.2)
Using tzinfo (0.3.35)
Using activerecord (3.2.9)
Using activeresource (3.2.9)
Using bundler (1.2.2)
Using coffee-script-source (1.4.0)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Installing rdoc (3.12)
Using thor (0.16.0)
Using railties (3.2.9)
Installing coffee-rails (3.2.2)
Installing jquery-rails (2.1.3)
Using rails (3.2.9)
Installing sass (3.2.3)
Installing sass-rails (3.2.5)
Using sqlite3 (1.3.6)
Installing uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem
is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

 

단계 5. Rails 애플리케이션 실행하기

명령프롬프트> cd myapp

명령프롬프트> rails server

=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-11-23 15:11:46] INFO  WEBrick 1.3.1
[2012-11-23 15:11:46] INFO  ruby 1.9.3 (2012-11-10) [i386-mingw32]
[2012-11-23 15:11:47] INFO  WEBrick::HTTPServer#start: pid=7468 port=3000

 

이제 웹브라우저로 http://localhost:3000 를 방문하면, 아래와 같은 Rails 애플리케이션의 초기화면이 뜬다.

 

 

 

단계 6: Home 컨트롤러 생성하기

프롬프트> rails generate controller home index

위 명령으로 notepad app/views/home/index.html.erb 이라는 파일이 자동으로 생성되어 있을 것이다. 이 파일의 내용은 딱 두 줄

         <h1>Home#index</h1>
         <p>Find me in app/views/home/index.html.erb</p>

이다. 이것이 웹브라우저에서 실행되게 하려면 public/index.html 파일을 삭제하거나 다른 이름으로 변경하고, config/routes.rb 파일의 내용을 다음과 같이 수정한다. (진하게 된 부분을 추가한다.)

Myapp::Application.routes.draw do
  get "home/index"

.............................................

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  root :to => "home#index" 
  .............................................

 

 

이제 다시 서버를 다시 시작하고 웹브라우저로 http://localhost:3000 을 방문한다

프롬프트> rails server

 

 

Posted by Scripter
,

1) Boost 라이브러리 홈페이지: www.boost.org (2012년 2월 24일 최신 버전은 1.48.0)

2) Boost 라이브러리 소스 내려받기: http://sourceforge.net/projects/boost/files/boost/1.49.0/

3) 이 문서 작성에 참고한 자료: Boost getting on Windows

4) 이래는 Boost 라이브러리 홈페에지;에 게시된 글...

Boost provides free peer-reviewed portable C++ source libraries.

We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.

We aim to establish "existing practice" and provide reference implementations so that Boost libraries are suitable for eventual standardization. Ten Boost libraries are included in the C++ Standards Committee's Library Technical Report (TR1) and in the new C++11 Standard. C++11 also includes several more Boost libraries in addition to those from TR1. More Boost libraries are proposed for TR2.

 

Boost 1.49.0 설치하고 테스트하기

[단계 1] 압축 파일을 적당한 곳에 풀어 놓는다.  (여기서는 D:\boost_1_49_0 에 풀에 놓은 것으로 간주한다.)

 

[단계 2] Visual Studio 2010 의 명령 프롬프트를 열고, Boost 의 주 디렉토리로 간다.

프롬프트> D:

프롬프트> cd \boost_1_49_0

 

[단계 3] 예제 파일 example.cpp 파일을 컴파일한다.

// Filename: example.cpp
//
// Compile: cl /EHsc example.cpp -I d:\boost_1_49_0
// Execute: echo 1 2 3 | example

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

 

프롬프트> cl /EHsc example.cpp -I d:\boost_1_49_0

 

[단계 4] 생성된 실행 파일 example.exe 파일을 실행한다.

프롬프트> echo 10 20 30 | example

 

[단계 5] 예제 파일 example2.cpp 파일을 컴파일한다.

// Filename: example2.cpp
//
// Compile: cl /EHsc example2.cpp -I d:\boost_1_49_0 /MD /link /LIBPATH:d:\boost_1_49_0\stage\lib
// Execute: example2 < jayne.txt

#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}
/*
Execution Result:
Will Success Spoil Rock Hunter?
*/

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link /LIBPATH:d:\boost_1_49_0\lib

   라이브러리가 아직 빌드되지 않았으므로 당연히 (라이브러리 없음) 에러가 발생한다.

 

[단계 6] 일괄파일 bootstrap.bat 파일을 실행한다.

프롬프트> bootstrap

 

[단계 7] b2.exe 파일을 실행한다.

프롬프트> b2

 

[단계 8]  시간이 꽤 걸리므로 (볼일을 본 후) 한 두시간 후에 다시 컴에 돌아온다.

 

[단계 9]  생성된 lib 파일들을 확인한다.

프롬프트> dir stage\lib

 

[단계 10] 다시 example2.cpp 를 컴파일한다,

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link /LIBPATH:d:\boost_1_49_0\lib

LINK : fatal error LNK1104: 'libboost_regex-vc100-mt-s-1_49.lib' 파일을 열 수 없습니다.

아직도 필요한 라이브러리 libboost_regex-vc100-mt-s-1_49.lib 가 없다는 에러 메시지이다.

 

[단계 11] 라이브러리 경로를 잘 지정하고 다시 example2.cpp  를 컴파일한다,

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link LIBPATH:d:\boost_1_49_0\stage\lib

LINK : fatal error LNK1104: 'libboost_regex-vc100-mt-s-1_49.lib' 파일을 열 수 없습니다.

그래도 라이브러리 libboost_regex-vc100-mt-s-1_49.lib 가 없다고 한다.

실제로 폴더 d:\boost_1_49_0\stage\lib 를 탐색기로 확인해 보아도 그런 파일은 없다.

 

[단계 12] 이번에는 옵션 /MD 를 주고 다시 example2.cpp  를 컴파일해 본다,

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /MD /link LIBPATH:d:\boost_1_49_0\stage\lib

아주 깨끗하게 컴파일된다. (아래는 컴파일되면서 컨솔에 출력되는 메시지)

/out:example2.exe
/LIBPATH:d:\boost_1_49_0\stage\lib
example2.obj

 

[단계 13] 실행 파일 example2.exe  을 실행하기 전에 다음 내용의 텍스트 파일을 jayne.txt 라는 이름으로 저장한다.

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.

 

[단계 14] 실행 파일 example2.exe 를 실행한다.

프롬프트> example2 < jayne.txt
Will Success Spoil Rock Hunter?

 

Posted by Scripter
,

Xcas 란?

소개와 설치/Xcas 2011. 9. 23. 07:17
Xcas 는 CAS(Computer Algebra System) 중 하나이며 GNU GPL 로 배포되는 자유 소프트웨어로서, X 터미널에서 동작하는 CAS 구현 애플리케이션이다. Mathematica, Maple, Maxima 부류의 소프트웨어라고 보면 되고, Lixux, Mac OS X, Windows 등 많은 OS 환경에서 사용가능한 무료(free) 소프트웨어이다.

현재 Xcas 의 안정적 버전은 0.9.3 이다.
설치할 때는 불어로 되어 있어서 혼돈이 되지만 적당히 "동의", "다음", "마침"의 뜻이라고 판단되는 버튼을 클릭하면 설치된다.

* Xcas 의 홈페이지는 http://www-fourier.ujf-grenoble.fr/~parisse/giac.html  이다.
* Xcas 의 다운로드는 http://www-fourier.ujf-grenoble.fr/~parisse/install_en 와 http://www-fourier.ujf-grenoble.fr/~parisse/install_en#packages 를 참조한다.


다음은 윈도우 XP에서 Xcas 룰 처음으로 실행시켜 간단한 계산 연습을 한 화면의 스샸이다.





* Ubuntu 에 Xcas 설차하고 실행하기
   "시넵틱 패키지 관리자" 로도 설치가 안되고, "sudo apt-get install xcas" 명령으로도 설치가 안된다.  오직 http://www-fourier.ujf-grenoble.fr/~parisse/install_en#packages 에서 Ubuntu 32bit 용과  64bit 용을 다운반는 하이퍼링크(click here)가 따로 되어 있으니, 각자의 환경에 맞는 것으로 다운방아 전형적인 설치 과정(./configure, make, make install)을 거치면 된다. 설치 중에 giac 를 설치하겠느냐는 질문이 뜨는데 이 때는 설치한다고 답(버튼 클릭)하면 된다. 다 설치되고 나면. Ubutu 의 주메뉴에서

          "프로그램" -> "교육" ->  "Xcas Computer Algebra Sytem"

을 선택해 나가면 Xcas 가 실행된다.  Xcas 를 처음 실행하면 인터페이스를 Other, Xcas, Maple 중 어느 것으로 할 것이냐는 질문 창이 뜨는데, 아래의 경우는Maple  인터페이스 선택한 경우이다.

* 다음은 Xcas 를 처음 실행하여 간단한 테스트를 한 화면의 스샷이다.





Posted by Scripter
,

GSL 이란?

소개와 설치/GSL 2011. 9. 21. 19:59

GSL 소개

GSL(GNU Scientific Library) 은 C 언어와 C++ 언어 프로그래머들을 위한 수치해석학 라이브러리이다.  GSL은 GNU GPL(GNU General Public License) 하에 배포되는 자유 소프트웨어이다.

이 라이브러리는 난수 발생, 특수 함수, 촤소제곱적합 등을 포함한 광범위한 수학 문제 처리 과정을 제공한다. 여기에는 테스트 모음(test suit)을 포합하여 무려 1000 여개의 함수들이 있다.

이 라이브러리는 다음의 여러 가지 분야들을 취급한다.


복소수(Complex Numbers) 다항식의 근(Roots of Polynomials)
특수함수(Special Functions) 벡터와 행렬(Vectors and Matrices)
순열(Permutations) 분류(Sorting)
BLAS 지원(BLAS Support) 선형대수(Linear Algebra)
고유계(Eigensystems) 고속 푸리에 변환(Fast Fourier Transforms)
구적법(Quadrature) 난수(Random Numbers)
준 난수열(Quasi-Random Sequences) 확률분포(Random Distributions)
통계학(Statistics) 막대그래프(히스토그램, Histograms)
N-순서조(N-Tuples) 몬테카를로 적분(Monte Carlo Integration)
야금 시뮬레이션(Simulated Annealing) 미분방정식(Differential Equations)
보간법(Interpolation) 수치적 미분(Numerical Differentiation)
체비세프 근사(Chebyshev Approximation) 급수 가속법(Series Acceleration)
이산 한켈 변환(Discrete Hankel Transforms 근 찾기(근 구하기, Root-Finding)
극소화(Minimization) 최소자승근사법(Least-Squares Fitting)
물리 상수(Physical Constants) IEEE 부동소수점(IEEE Floating-Point)
이산 웨이브를릿 변환(Discrete Wavelet Transforms) 기선 스플라인(Basis splines)


[원문 원본] GSL(GNU Scientific Library) 홈페이지

Posted by Scripter
,
* http://code.google.com/p/luaforwindows/downloads/list

* Lua 홈페이지 : http://www.lua.org

* 설치 후 간단한 lua 샘플 빨리 테스트하기

프롬프트> cd "LUA 설치 디렉토리의 절대경로"
프롬프트> cd examples
프롬프트> lua quickluatour.lua



Posted by Scripter
,