Thursday, August 28, 2014

event emiter in nodejs

var custom = new process.EventEmitter();

custom.on('hello', function(){ console.log('event generated')});

custom.emit('hello');



======================
"event generated" log will be written in console

file write sync and async in nodejs



var fs = require('fs');
var data= 'heloo world';

fs.writeFile('filename.txt', data, 'utf-8', function(error){
console.log('write file async');
});

fs.writeFile('filenameSync.txt', data, 'utf-8');
console.log('write file sync');

read file in folder and write in browser in nodejs

this is a sample http server and read file and print in brwoser
when you call
http://localhost:8888/

var http = require("http");
var fs = require('fs');
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
var text= fs.readFileSync('textfile.txt', 'utf-8');

response.write(text);  response.end();
}).listen(8888);

Wednesday, August 27, 2014

Search Content Architecture

In this generation lots of book publicshed day by day
and If I go to library to find some book which containing some contents (I want)

there is no way to find 
may you have to use you whole life to find books which you are looking for

so library must provide tools or program for looking books
.

this is architecture that searching title, content, date and so on

there is good opensource Lucene.

Simple http server architecture


This is what i usually setting in my Simple http server
some people say that this is very old~
because recently people tend to use new technology like node.js or nosql

What I learned serverside is used like this architecture and no problem generated~

This architecture pages will be written and paged from my experience.

I'm not sure It is best way or not
but i'm sure that this will help improving my skill and knowloged about IT

Have a good job~

exports in nodejs

Require and Exports ~!

require will get file

exports will help file to be used in require file


example


main.js
var mymodule = require('./mymodule.js');

console.log('asdfasdf ' + mymodule.hello());

mymodule.js
exports.hello = function(){
return 'hello 2';
}

Tuesday, August 19, 2014

이름 자동완성 리스트

내 안드로이드폰 주소록 검색을 보게 되면
ㄱ만 쳐도 ㄱ을 포함하고 있는 사용자 이름을 다 검색하게 되어있다.
그것도 빠른 시간내에..

문뜩 이것을 따라 만들고 싶은 욕망이 치 솟아서 저번에 배운 한글 초성 + 중성 + 종성으로
나눠 따라 해보기로 했다.

1. 테이블을 
   name 
   name_index 필드를 만들었다.

  name 에는 홍길동이 들어가고
  name_index  에는 ㅎㅗㅇㄱㅣㄹㄷㅗㅇ 
이런식으로 초성중성조성으로 구분되어서 각각이 하나의 문자로 들어간다.

그러면 TextEdit box에서 정을 쳤을때
 " ㅈㅓㅇ "
을 like 검색을 하면 정에 관한 데이터들이 쭈루룩 올라온다.

약 500건의 데이터로 테스트를 했는데
실제 DB 에서 가져오는 시간은 0.01초 걸렸다.
 즉 10ms

많지 않는 내용의 값을 검색할때는 초성중성종성 을 넣은 란은 Like검색해서 가져오면
충분히 효율성이 있을 것이라고 생각한다.

물론 Server side의 입장을 다르게 될것이다
좀더 나은 효율성과 Perfomance 를 위해 

Lucene같은 라이브러리를 이용해도 되고
아니면 데이터베이스를 이용해도 되겠다.