Tags

Coffeescript Active Reading 자바스크립트 스프링 프레임워크 gvim Web Controller Testing 학습법 gvimext.dll error JUnit nowrap groovy viewport springframework MySQL 테스팅 윈도우즈 Grab JavaScript RUBY RuntimeException 독후감 자바 VIM rvm Exception Windows perl 적극적 읽기 This

첫번째, RVM(Ruby Version Manager) 설치

어떻게 설치하나 RVM 홈페이지에 방문해 보니, 아래 명령을 실행해서 설치하라고 나오더군요.

\curl -L https://get.rvm.io | bash -s stable --ruby

그래서 고민없이 실행해 보았습니다. 아래는 모두 위 명령을 실행한 후 나타난 메시지 입니다.

rosebook:~ rose$ \curl -L https://get.rvm.io | bash -s stable --ruby
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   185  100   185    0     0     92      0  0:00:02  0:00:02 --:--:--   180
100 10956  100 10956    0     0   2573      0  0:00:04  0:00:04 --:--:--  8008
Please read and follow further instructions.
Press ENTER to continue.
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   131  100   131    0     0     51      0  0:00:02  0:00:02 --:--:--    66
100 1243k  100 1243k    0     0   157k      0  0:00:07  0:00:07 --:--:--  338k

Upgrading the RVM installation in /Users/rose/.rvm/
    RVM PATH line found in /Users/rose/.bashrc /Users/rose/.zshenv.
    RVM sourcing line found in /Users/rose/.bash_profile /Users/rose/.zprofile.

rvm 은 ~/.rvm 에 설치 되고, rvm 에 대한 PATH 는 ~/.bashrc 과 ~/.zshenv 에, rvm 소스를 읽어 들이는 부분은 ~/.bash_profile 과 ~/.zprofile 에 추가되었다는 메시지가 보입니다.

Upgrade Notes:

  * If you wish to get more default(global) gems installed, install RVM with this flag: --with-gems="pry vagrant"
    this option is remembered, it's enough to use it once.


# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

위에 스크린케스트는 설치 명령어나 출력 메시지가 지금과는 다르지만 rvm 이해에 도움이 되더군요.

# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Upgrade of RVM in /Users/rose/.rvm/ is complete.

# BYUN Sangpil,
#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and
#   more enjoyable!!!
#
# ~Wayne

Thank you Wayne E. Seguin and Thank you Michal Papis.

rvm 1.17.6 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

No binary rubies available for: downloads/ruby-1.9.3-p362.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: /Users/rose/.rvm/rubies/ruby-1.9.3-p362, this may take a while depending on your cpu(s)...
ruby-1.9.3-p362 - #downloading ruby-1.9.3-p362, this may take a while depending on your connection...
ruby-1.9.3-p362 - #extracting ruby-1.9.3-p362 to /Users/rose/.rvm/src/ruby-1.9.3-p362
ruby-1.9.3-p362 - #extracted to /Users/rose/.rvm/src/ruby-1.9.3-p362
ruby-1.9.3-p362 - #configuring
ruby-1.9.3-p362 - #compiling
ruby-1.9.3-p362 - #installing
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.9.3-p362 ...
Installation of rubygems completed successfully.
Saving wrappers to '/Users/rose/.rvm/bin'.
ruby-1.9.3-p362 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p362 - #importing default gemsets (/Users/rose/.rvm/gemsets/), this may take time ...
Install of ruby-1.9.3-p362 - #complete
Creating alias default for ruby-1.9.3-p362.
Recording alias default for ruby-1.9.3-p362.
Creating default links/files
Saving wrappers to '/Users/rose/.rvm/bin'.

  * To start using RVM you need to run `source /Users/rose/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
rosebook:~ rose$

기본적으로 ruby 1.9.3 버전과, rubygems-1.8.24 를 설치해 줬습니다.

루비 개발환경 셋팅 끝!

저작자 표시 변경 금지
Trackback 0: Comment 0

머릿속에서 타당한 구조가 떠오르기 전에, 코드부터 작성하는 버릇은 고쳐야겠다.

저작자 표시 변경 금지
Trackback 0: Comment 0

오늘 일을 하다, 몇몇 테이블에서 url 컬럼에 시작값이 http://www.daum.net 또는 http://www.naver.com 또는 http://www.nate.com 인 녀석들의 통계를 구하는 작업을 했습니다.(여기서 컬럼명 url, 값 네이버, 다음, 네이트 등등은 실제 데이터는 아닙니다.)

이 작업은 꽤 많은 테이블에 반복적인 쿼리를 날려야 하는 일로, 쉽지않은 방법으로 아래와 같은 그루비(=Groovy) 코드를 만들었습니다.

@GrabConfig(systemClassLoader=true)
@Grab(group='mysql', module='mysql-connector-java', version='5.1.21')

import groovy.sql.Sql

def db1 = Sql.newInstance('jdbc:mysql://DB_SERVER1:3306/db1','ID', 'Password', 'com.mysql.jdbc.Driver')
def db2 = Sql.newInstance('jdbc:mysql://DB_SERVER2:3306/db2','ID', 'Password', 'com.mysql.jdbc.Driver')
def db1_tables = [ 'T001', 'T002']
def db2_tables = [ 'T003', 'T004']

countEmbedTypes = { bbs, tables ->
    tables.each{ table ->
        bbs.eachRow(
            """
            SELECT 
                SUM(1) AS 'Total',
                SUM(IF (url LIKE "http://www.daum.net%", 1, 0)) AS 'daum',
                SUM(IF (url LIKE "http://www.naver.com%", 1, 0)) AS 'naver',
                SUM(IF (url LIKE "http://www.nate.com/%", 1, 0)) AS 'nate'
                FROM """ + table
        ){
            def total = toInt(it.Total)
            def daum = toInt(it.daum)
            def naver = toInt(it.naver)
            def nate = toInt(it.nate)
            printf ( "| %6s | %6s | %6s | %6s | %6s | \n", [table, total, daum, naver, nate])
        }
    }
}

def toInt(i) {
    return (i == null) ? 0 : i.toInteger()
}

countUrlTypes(db1, db1_tables)
countUrlTypes(db2, db2_tables)

첫 번째 난관은 SQL 쿼리를 만드는 일, 이건 StackOverflow 에서 해답을 구했습니다. 아래와 같은 형태로. 몇번 실행해보니 원하던 값이 나오더군요.

SELECT
    SUM(1) AS 'Total',
    SUM(IF (url LIKE "http://www.daum.net%", 1, 0)) AS 'daum',
    SUM(IF (url LIKE "http://www.naver.com%", 1, 0)) AS 'naver',
    SUM(IF (url LIKE "http://www.nate.com/%", 1, 0)) AS 'nate'
FROM YOUR_TABLE

두번째 난관은 그루비에서 MySQL 서버에 연결하는 방법.

import groovy.sql.Sql
def db1 = Sql.newInstance('jdbc:mysql://DB_SERVER1:3306/db1','ID', 'Password', 'com.mysql.jdbc.Driver')

그루비 홈페이지에서 위와 같은 코드는 쉽게 발견할 수 있었는데, 문제는 예제 코드를 실행하면, com.mysql.jdbc.Driver 관련 클래스를 찾을 수 없다는 오류 메시지.

혹시나해서 Maven Classpath를 Groovy에서 쓸수 있는 방법을 찾다가. @Grab 이란 표현으로 메이븐 저장소의 라이브러리를 읽어 올 수 있다는 방법을 알게 되었습니다.

@Grab(group='mysql', module='mysql-connector-java', version='5.1.21')

그리고, 데이터베이스 드라이버의 경우, @GrabConfig 에서 systemClassLoadertrue로 설정해야 한다고 합니다.

@GrabConfig(systemClassLoader=true)

systemClassLoader 설정은 그루비 API 페이지에, 아래와 같은 설명으로 되어 있는데, 내용은 잘 이해가 안되네여.. '포도'를 로딩하다니,...

Set to true if you want to use the system classloader when loading the grape. This is normally only required when a core Java class needs to reference the grabbed classes, e.g. for a database driver accessed using DriverManager.

그 외에도 그루비 클로져도 찾아 쓰고, 함수도 찾아 써봐서, 생각보다 어렵게 하지만 재미있는 스크립트를 만들 수 있었습니다.

저작자 표시 변경 금지
Trackback 0: Comments 3

긴 로그 파일의 경우 자동 줄바꿈은 로그를 한눈에 살펴보기에 방해가 되더군요.

물론, 넓은 모니터를 사면 되겠지만...

vim 에서는 이럴때, 자동 줄바꿈(wrap) 옵션을 끄면 됩니다, 이렇게,

set nowrap


저작자 표시 변경 금지
Trackback 0: Comment 0
  1. 인덱스는 도큐먼트를 가져오기 위해 필요한 작업량을 많이 줄인다. 적당한 인텍스가 없으면 질의 조건을 만족할 때까지 모든 도큐먼트를 차례로 스캔해야만 하고, 이것은 종종 컬렉션 전체를 스캔하는 것을 의미한다.
  2. 한 쿼리를 실행하기 위해서 하나의 단일 키 인덱스만 사용할 수 있다. 복합 키를 사용하는 쿼리에 대해서는 복합 인덱스가 적합하다.
    예를 들어, 삼성 제품중 안드로이드 폰인 경우 -> 밴더 - OS 와 같은 복합 키로,
  3. a - b 에 대한 복합 인덱스를 가지고 있다면 a 에 대한 인덱스는 필요없다. 중복이다.
  4. 복합 인텍스에서 키의 순서는 매우 중요하다.
몽고디비 인 액션 7.1 인덱싱의 이론적 고찰 중
저작자 표시 변경 금지
Trackback 1: Comment 0

viewport 메타 태그

<meta name="viewport" content="width=device-width; user-scalable=0;" />

viewport 메타 태그에서 사용할 수 있는 매개변수 목록

매개변수 개요 대입 가능한 값
width 너비를 지정할 때 사용. device-width: 기기의 화면 너비, 절대값으로 지정.
height 높이를 지정할 때 사용. device-height: 기기의 화면 높이, 절대값으로 지정.
user-scalable 사용자가 화면 크기 조절 가능 여부 1, yes, true: 허용
0, no, false: 금지
initial-scale 초기 화면의 배율 값 배율 값, 1.0은 viewport 1 픽셀은 1화면 픽셀과 같다는 의미
minimum-scale 최소 배율 0 ~ 10.0
maximum-scale 최대 배율 0 ~ 10.0
안드로이드 전용
target-densitydpi 웹 페이지에 적합한 홤녀 해상도를 알려줌 device-dpi: viewport가 지정하는 dpi
high-dpi, medium-dpi, low-dpi
70~400 범위 안에서 기기의 픽셀 밀도 지정.

아이폰 모바일 사파리의 경우, [설정] 메뉴 > ‘일반’ > ‘손쉬운 사용’ 에서 확대/축소 기능을 활성화 하면 user-scalable=0 설정을 무시할 수 있음.

target-densitydpi 는 아직 잘 모르겠음. 안드로이드 WebView 문서 에 설명이 잘 되어 있는듯, 그래도 잘 모르겠음.

URL 입력 바 자동 숨김

브라우저가 페이지를 다 불러온 시점에서 window.scrollTo(0,1) 을 실행

<body onload="window.scrollTo(0,1);" >
저작자 표시 변경 금지
Trackback 0: Comment 0