2016년 2월 12일 금요일

컴포지트 패턴(Composite pattern) javascript 구현




 
/*
  * 컴포지트 패턴(Composite pattern)이란 객체들의 관계를 트리 구조로 구성하여 부분-전체 계층을 표현하는 패턴으로, 사용자가 단일 객체와 복합 객체 모두 동일하게 다루도록 한다.
  * 컴포넌트 : 컴포넌트란 더 큰 프로그램이나 구조물에서 식별 가능한 "일부분"이다, 컴포넌트는 특정 기능이나 관련된 기능들의 조합을 제공한다.
  // 보통 트리구조
  // 현재 기본 구조 { figure : [rect,line,circle], group: figurelist[] }
  // 바꿀 구조 { figure : [rect,line,circle,group]}
 */
 function Figure(){
  this.shape = "none";
 }
 Figure.prototype= {
  draw : function(){
   console.log(this.shape);
  }
 };
 var figure = new Figure();
  
 function Rectangle(){
  this.shape = "Rectangle_shape";
 };
 Rectangle.prototype = figure;

 function Circle(){
  this.shape = "Circle_shape";
 };
 Circle.prototype = figure;

 function Line(){
  this.shape = "Line_shape";
 };
 Line.prototype = figure;

 var rectangle = new Rectangle;
 var line = new Line;
 var circle = new Circle;

// rectangle.draw();

 
 //각각의 figure를 통합하여 전체 그리기 시도시 이렇게 따로 구현 해야됨
 function Group(){
  var arr = [];
  this.add = function(figure){
   arr.push(figure);
  };
  this.totalDraw = function(){
   arr.forEach(function(me, i){
    me.draw();
   })
  };


 }
// 상속받는 기능 들에 대해서도 모두 따로 구현해줘야되는 부분을 
/* var group = new Group;
  group.add(rectangle);
  group.add(line);
  group.totalDraw();
*/

//구성 공유
 function Figure(){
  this.shape = "none";
  this.arr = [];  //배열에 부분들 추가 
 }

 Figure.prototype.add = function(figure){
   this.arr.push(figure);
 };

 function Group(){
  this.draw = function(){
   this.arr.forEach(function(me, i){
    me.draw();
   })
  };
 }

//같은 figure상속
 Group.prototype = figure;


 var group = new Group;
  group.add(rectangle);
  group.add(line);
//group 이어도 똑같은 draw메소드
  group.draw();

 var rectangle = new Rectangle;
//다른 draw도 정상적인 기능
  circle.draw();

// 객체와 객체 그룹간 동일한 인터페이스로 사용 가능 

2016년 2월 11일 목요일

라라벨 tinker

- tinker라는 뜻은 어설프게 고치다 라는 뜻, 테스트 해보고 연습해보기 편함
1. php artisan tinker

>>> DB::insert('insert into posts(title, body) values(?, ?)', ['Second Title', 'Second Body']);
=> true

>>> $post = DB::selectOne('select * from posts where id = ?', [1]);

>>> DB::update('update posts set title="Modified Title" where id = ?', [1]);
=> 1


라라벨 - 데이터베이스 마이그레이션

데이터 베이스를 만들자 (migration)


1. php artisan make:migration create_posts_table





2. 테이블 스키마 작성

class CreatePostsTable extends Migration
{
    public function up()
    {
        Schema::create('posts', function($table) {
            $table->increments('id'); // id INT AUTO_INCREMENT PRIMARY KEY
            $table->string('title', 100); // title VARCHAR(100)
            $table->text('body'); // body TEXT
            $table->timestamps(); // created_at TIMESTAMP, updated_at TIMESTAMP
        });
    }

    public function down()
    {
        Schema::dropIfExists('posts'); // DROP TABLE posts
    }
}

3. php artisan migrate








2016년 2월 10일 수요일

classic asp select case 문법 활용


<%
 'classic asp select case statement 
 ' 보기싫은 or절 개선 가능
 function exp1()
  exp1 = ""
 end function

 function exp2()
  exp2 = false
 end function

 function exp3()
  exp3 = true
 end function

 select case true 
  case exp1(), exp2()
   response.write "exp1,exp2"
  case exp3()
   response.write "exp3"
  case else
   response.write "exp4"
 end select

 'result : exp3
 

%>

2015년 7월 13일 월요일

점수 구하기

<script>
var score = parseFloat(prompt("give me score ",0),10);
alert("your score "+"FFFFFEDCBAA"[score/10]+" !!");
</script>

2014년 7월 10일 목요일

inline 형태의 프로퍼티는 unbind 할수 없습니다.

<textarea cols="117" rows="5" class="texa elastic_textarea" name="letter_content" id="letter_content" onkeyup="letter_content_lengthCheck(this, <%=max%>);"><%=letter_content%></textarea>

이러한 형태로  onkeyup 이벤트를 준 후
$("#letter_content").unbind("keyup")
을 하면 안먹음
removeAttr("onkeyup")
도 안먹음
removeProp("onkeyup")만 먹힘

이로써 알수 있는 사실 onkeyup이란 프로퍼티에 등록되있음
== 이벤트가 아니다 -> 이벤트가 트리거 형태로 들어가게됨

attribute와 .prop는 엄연히 다른것이니 알아서 알겟고 ..
여튼 이런 차이가 있음

2014년 4월 2일 수요일

한글이 아닌 영문 숫자만 가능하게  유효성 검사 함수

        var re = /[^a-zA-Z0-9\-_]+/g;
        var that = this;
        that.value.replace(re, function (curVal, curNum, totalVal) { //curval, p1,p2,p3.. totalVal
            that.focus(); 
            that.value = arguments[arguments.length - 1].replace(curVal, "");
        });