태그

2013년 12월 5일 목요일

Express.js sample

var express = require('express'), http = require('http');
var app = express();

app.all("*", function(request, response, next) {
response.writeHead(200, {
"Content-Type" : "text/plain"
});
next();
});

app.get("/", function(request, response) {
response.end("Welcome to the homepage!");
});

app.get("/about", function(request, response) {
response.end("Welcome to the about page!");
});

app.get("/hi/:user", function(req, res) {
 res.end("Hi, " + req.params.user + ".");
});

app.get("*", function(request, response) {
response.end("404!");
});

http.createServer(app).listen(1337);

console.log('Server running at http://127.0.0.1:1337/');

2013년 11월 17일 일요일

Google Big Data Reference

Hadoop DFS :
http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en//archive/gfs-sosp2003.pdf

Hadoop MapReduce :
http://static.usenix.org/event/osdi04/tech/full_papers/dean/dean.pdf

HBase, Cassandra .. :
http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en//archive/bigtable-osdi06.pdf

Hive, Pig :
http://research.google.com/archive/sawzall.html

Apache ZooKeeper :
http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en//archive/chubby-osdi06.pdf

2013년 11월 3일 일요일

Eclipse configuration tuning

1. JVM Heap memory(eclipse.ini 설정변경)
-vm
C:/G-MES2.0/jdk1.6.0_26/bin/javaw.exe
-startup
plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.2.R36x_v20101222
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
512M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms256m
-Xmx768m
2. Automatic folding 설정 해제
Window > Preferences > Java > Editor > Folding 옵션을 모두 해제(disable)한다.
3. Automatic Code Insight 설정 해제 (개발자 선택)
Window > Preferences > Java > Editor > Code Assit 에서 Enable auto activation 항목을 해제(disable)
4. spelling check 설정 해제
Window > Preferences > General > Editors > Text Editors > Spelling 에서 Enable spelling checking 항목을 해제
5. validation check 설정 해제
Window > Preferences > Validation 모든 항목 체크 해제
6. eclipse compare 에서 공백 배제하는 법
Window > Preferences > General > Compae/Patch 에서 Ignore white space 항목을 체크
7. 사용자 정보 수집 해제
Window > Preferences > Usage Data Collector 에서 Enable capture 항목 해제
8. Maven index 해제
Window > Preferences > Maven에서 모든 항목 해제
9. KeepResident 플러그인
메모리에 여유가 있다면 KeepResident Eclpse plugin for Windows - KeepResident Eclipse plugin 을 설치한다. (화면 창을 내렸다 올릴경우 버벅이는 현상 제거 - 대기중이던 모든 GC가 작동하여 느리게 됨)
link - http://suif.stanford.edu/pub/keepresident/
10. 이클립스 자동 업데이트
Window > Preferences > Automatic Updates 에서 Automatically find new updates and notify me 항목 해제
11. 시작을 빠르게
Window > Preferences > General > Editors > close all editors on exist 항목을 설정(enable) 한다.
Window > Preferences > General > Startup and Shutdown 에서 KeepResident 플러그인을 제외한 모든 플러그인을 startup list 에서 제외한다.

12. 개발 Perspective를 Java로 설정해서 사용한다.
Window > Open Perspective > Other 에서 Java 선택

How to deploy node.js to Heroku in Windows


It is not working only for Getting Start Guide in official link.
https://devcenter.heroku.com/articles/getting-started-with-nodejs


Just follow above link, and when you push source to Heroku, you will see this massage.

C:\heroku\KanbanBoardProject>git push heroku master
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 This problem was not on my SSH key.. Even I put right SSH key in Heroku's account, my command prompt cannot get SSH key by itself. I just got reason from below link.
http://stackoverflow.com/questions/17626944/heroku-permission-denied-publickey-fatal-could-not-read-from-remote-reposito

And window solution is here.
http://wordgraphs.com/post/5000/Heroku--Permission-denied--publickey---fatal--Could-not-read-from-remote-repository-

C:\heroku\KanbanBoardProject>ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-TFTddq3932/agent.3932; export SSH_AUTH_SOCK;
SSH_AGENT_PID=6616; export SSH_AGENT_PID;
echo Agent pid 6616;

C:\heroku\KanbanBoardProject>set SSH_AUTH_SOCK=/tmp/ssh-TFTddq3932/agent.3932

C:\heroku\KanbanBoardProject>set SSH_AGENT_PID=6616

C:\heroku\KanbanBoardProject>ssh-add C:\Users\chris\.ssh\id_rsa
Identity added: C:\Users\chris\.ssh\id_rsa (C:\Users\chris\.ssh\id_rsa)

C:\heroku\KanbanBoardProject>heroku keys:add
Found existing public key: C:/Users/chris/.ssh/id_rsa.pub
Uploading SSH public key C:/Users/chris/.ssh/id_rsa.pub... done

C:\heroku\KanbanBoardProject>git push heroku master
Counting objects: 1138, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1041/1041), done.
Writing objects: 100% (1138/1138), 1.39 MiB | 159 KiB/s, done.
Total 1138 (delta 117), reused 0 (delta 0)

It is working as a charm, I spent lots of time to solve it..T.T

I hope windows user can solve this issue with below solultion!!

2013년 9월 20일 금요일

MongoDB 설치하기


공식 홈페이지 : http://www.mongodb.org/

다운로드 : http://www.mongodb.org/downloads

공식 문서 : http://docs.mongodb.org/manual/

윈도우 설치 가이드 : http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/


몽구스(mongoose) 사용하기 - getting started

공식 홈페이지 : http://mongoosejs.com/

Getting Started : http://mongoosejs.com/docs/index.html

아래 예제는 몽구스 공식 홈페이지에 나와있는 예제입니다. 아래 내용 참고해서, 몽구스로 개발을 어떻게 하는지 알아봅시다.

몽고DB와 Node.js는 이미 설치 되었다고 가정합니다.

몽구스를 npm명령어를 통해 설치 해봅시다.:
$ npm install mongoose

자, 유스케이스를 하나 만들어볼까요? 우리는 털이 복슬복슬하게 나 있는 아기 고양이를 무척 좋아하고, 몽고DB 안에서 만난 모든 새끼 고양이에 대해서 기록하고 싶다고 합시다. 첫 번째로 할 일은 '몽구스'를 우리 프로젝트에 추가하고, 로컬 환경에 설치되어 있는 몽고DB의  'test'  데이터베이스와 커넥션을 획득하는 것이겠죠?
// getting-started.js
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');

이제 우리는 커넥션이 맺어지기를 기다리고 있습니다. 그리고 커넥션 획득 성공 여부를 확인하고, 알수 있어야 합니다. db.on('error', .. 을 통해 에러가 발생하면 콘솔에 에러 로그를 출력합니다. db.once('open', 을 사용하면, 커넥션을 획득했을 때, 어떤 동작을 해야 할지, 콜백 함수에 몀시할 수 있습니다.
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));db.once('open', function callback () {  // 성공!!
});

커넥션을 획득하면, 콜백함수가 호출되겠죠? 간단하게, 이 콜백함수에 앞으로 소개하는 모든 소스를 담도록 하겠습니다.
몽구스에서는 모든 데이터가 스키마로 부터 조회 할 수 있습니다. 우리의 아기고양이 스키마를 한번 만들어 볼까요?
var kittySchema = mongoose.Schema({
    name: String
})

좋습니다. name 이라는 한 개의 속성을 가진 스키마를 생성하였습니다. 이제 이 스키마를 모델안으로 넣어볼까요?
var Kitten = mongoose.model('Kitten', kittySchema)

모델은 우리가 만든 문서를 의미하는 클래스 입니다. 이 경우에는, 각 문서는 우리가 선언한 스키마에 명시한 속성값과 행위들을 지니고 있는 아기고양이가 되겠군요.
저 밖에 길가에서 만난 작은 사나이를 뜻하는 아기고양이 문서를 하나 만들어 봅시다. 변수명은 'silence'로 하죠..
var silence = new Kitten({ name: 'Silence' })
console.log(silence.name) // 'Silence'

아기 고양이는 '야옹'하고 울기 마련이죠. 우리의 문서에 어떻게 우는 기능을 추가 할 수 있는 지 확인 해 봅시다. 스키마를 모델안에 집어 넣기 전에 이 작업을 해야 겠죠? 주의 하시기 바랍니다.
// NOTE: methods must be added to the schema before compiling it with mongoose.model()
kittySchema.methods.speak = function () {
  var greeting = this.name
    ? "Meow name is " + this.name
    : "I don't have a name"
  console.log(greeting);
}

var Kitten = mongoose.model('Kitten', kittySchema)
함수는 스키마의 'methods' 속성값에 추가한 다음, 모델 프로토타입에 추가되었습니다. 그리고 각 문서에 노출되었습니다.

이제 아기 고양이들하고 대화를 해봐야 겠죠? 'fluffy'라는 이름의 아기 고양이를 변수에 할당하고 위에서 추가한 함수를 호출해봅시다.
var fluffy = new Kitten({ name: 'fluffy' });
fluffy.speak() // "Meow name is fluffy"

이제 아기 고양이와 대화를 할 수 있게 되었군요!! 하지만, 아직 우린 아무것도 몽고DB에 저장하지 않았습니다. 각 문서는 'save' 함수를 통해 데이터베이스에 저장할 수 있습니다. 첫 번째 인자값은 에러발생시에 수행되는 콜백 함수 입니다.
fluffy.save(function (err, fluffy) {
  if (err) // TODO handle the error
  fluffy.speak();
});

위에서 언급했던 유스케이스를 다시 떠올려 볼까요? 우리는 우리가 만난 모든 아기 고양이를 기록하고 싶습니다. 우리는 'find'함수를 사용하여,  'Kitten' 모델을 통해 모든 아기고양이 문서에 접근할 수 있습니다.
Kitten.find(function (err, kittens) {
  if (err) // TODO handle err
  console.log(kittens)
})

또한, 데이터베이스에 있는 모든 아기고양이를 콘솔에 로깅 할 수 도 있습니다. 물론, 아래와 같이 이름에 필터링을 걸 수도 있겠죠. 더 다양한 몽구스의 검색 용법에 대해 궁금하신 분들은 다음 링크를 확인 해 보기 바랍니다. http://mongoosejs.com/docs/queries.html
Kitten.find({ name: /^Fluff/ }, callback)

이 줄은 'Fluff'로 시작되는 모든 아기 고양이를 찾아내서, 두 번째 인자값에 포함된 콜백 함수를 수행하게게 됩니다.

Congratulations축하드립니다!

퀵스타트 예제가 끝이났군요. 스키마를 생성하고, 자신이 원하는 함수를 추가하였으며, 몽고DB 에 저장하고 다시 불러오는 과정까지 해 보았습니다. 더 알고 싶으신 분들은 다음 링크의 가이드 및 Api 문서를 확인 하기 바랍니다. Head over to the guide, or API docs for more.