드림위버와 ftp

Memo 2011. 11. 28. 15:14
드림위버에서 ftp를 설정하여 윈도우에서의 작업과 리눅스 서버에서의 데이터를 연동할 수 있다.

방법 : 메뉴->site->New Site
AND

./program 이라는 프로그램이 존재한다면,

./program > result.txt 라고 쓰면 정상 출력
./program 2> result.txt 라고 쓰면 에러 출력
./program &> result.txt 라고 쓰면 모든 결과 출력

| more 을 덧붙이는 것도 유용하지만, 위 방법은 결과를 가공할 일이 있을 때 유용하다.
AND

mysql 의 mysql 데이터베이스 내의 user 테이블에서
update 쿼리를 잘못 날려서 debian-sys-maint의 비밀번호를 잊어버렸을 경우, 대처하는 방법.

배경 지식)
debian-sys-maint 계정은 기본적으로, mysql 데몬을 관리함.
/etc/init.d/mysql 스크립트를 start, stop, restart 등을 할 때
/etc/mysql/debian.cnf의 debian-sys-maint 계정과 암호를 사용.
debian.cnf 파일의 password 부분은 encryption된 것이 아니라 그냥 clear-text.

해결 방법)
즉, debian.cnf 파일의 password 부분을 임의의 문자열로 변경하고,
mysql> update user set password = password('랜덤스트링') where user = 'debian-sys-maint'
mysql> flush privileges;
를 하면 됨.

걍 .. update 쿼리를 날릴 때 where 절을 꼭 쓰도록 조심조심 하기.
AND

옵션 -C를 사용한다.
AND

아래 예제 소스에서 굵게 표시한 부분에 주의하면 해결된다.
1. 데이터베이스를 만들 때 utf8로 설정
2. 테이블을 만들 때 utf8로 설정
3. 쿼리를 날리기 전에 "set names 'utf8'" 쿼리 먼저 날리기(select할 때 등도 포함)
참고 : http://php.net/manual/en/function.mysql-client-encoding.php

$query = "create database grade CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($query) or die (mysql_error());
$db_status = mysql_select_db('grade');
mysql_query("set names 'utf8'");  // it's important thing.
$query = "CREATE TABLE student_2 (
student_number smallint unsigned not null,
student_name char(9) charset utf8 not null,
grade_pl tinyint unsigned not null,
grade_wp tinyint unsigned not null,
grade_cs tinyint unsigned not null,
grade_sp tinyint unsigned not null,
grade_sum smallint unsigned not null,
grade_avg float unsigned not null,
grade_rank tinyint unsigned,
primary key(student_number)
)";
mysql_query($query) or die (mysql_error());
AND

form태그 하위에 input 태그로 생성된 radio 버튼들이 있다고 하자.
그 radio 버튼을 선택했을 때, 다른 input 태그들이 나타나게 하고 싶다.
그럴 때는 input 태그의 버튼을 눌렀을 때, javascript 함수가 호출되게 하고,
그 javascript 함수에서 get 방식으로 인자를 넣어 다시 그 페이지를 호출하면 된다.
나타나게 하는 것은 php를 이용했다.

예제 링크 : http://eunji.byus.net/study/figure.php

 

AND

php에서, array를 foreach문으로 뽑아내면,
key와 value의 쌍이 나오는 순서는 array의 index순서(key의 순서)가 아니다.
foreach문이 뽑아내는 순서는 array에 넣은 순서이다.
 
또한, php에서 2차원 동적 배열은 별도로 만들 필요 없이
$test2[$i][$j] = $c++; 등으로 사용 가능하다.
단, $test2[$i]에 값을 할당한 후에, $test2[$i][$j]에 값을 넣는 것은 불가능하다.

테스트를 위해서 아래와 같은 코드를 작성하였다. -_-;;

그리고, 결과는 아래와 같다.
 
헷갈릴 때는 실행시켜보면 명료해질 것이다.
 
php의 array는 c와 같이 '[]'를 사용하면 되고,
그 안의 구현은 추측컨대, 행 단위로 array를 구현하고,
그 행안에 array를 자동으로 구현하는 방식인 것 같다. (c와 비슷한)

 하지만, foreach문의 출력 형태로 보아 연결리스트와 비슷하지 않을까 싶기도 하다.
 index와 값이 아닌, key와 value로 이루어져 있는 걸 보면 그럴 것도 같다.

걍 직접 경험해보느라 ㅋㅋ 조금 밖에 안 읽었지만, 참고 자료는 아래 링크.
http://www.php.net/manual/en/control-structures.foreach.php 
AND

반환형이 void가 아닌 함수에서 함수의 끝이 되어 종료 될 때까지 반환하지 않을 경우,
마지막에 호출한 함수의 반환값을 따로 저장하지 않더라도 그 값을 반환하게 된다.

주석으로 여기 !!!!!!! 라고 표시한, return prime(n, ++divisior)부분을
prime(n, ++divisior)로 바꾸면 n이 소수일 때, 반환값 1이 별도로 반환하지 않더라도 반환된다.
또한, pritf("123\n");의 주석을 풀면 그 반환값인 4가 별도로 반환하지 않더라도 반환된다.

return을 지워도 .. 정상적으로 동작하긴 하지만,
반환형이 void가 아닌 재귀함수에서는 return을 명시적으로 하는 것이 옳다.

환경) Ubuntu Linux, vi editor, gcc complier
예제)
#include <stdio.h>

int prime(int n, int divisor)
{
        if(divisor<=(n/2))
        {
                if(n%divisor != 0)
                {
                        printf("call n:%d, divisor : %d\n", n, divisor);
                        return prime(n, ++divisor);  // 여기 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//                      printf("123\n");
                }
                else
                {
                        printf("0.n : %d, divisor : %d\n", n, divisor);
                        return 0;  // 소수가 아니다.
                }
        }
        else
        {
                printf("1.n : %d, divisor : %d\n", n, divisor);
                return 1;  // 소수이다.
        }
}

void main()
{
        int n;

        printf("input n : ");
        scanf("%d", &n);

        printf("반환값 : %d\n", prime(n,2));
//      prime(n, 2)?(printf("소수이다.\n")):(printf("소수가 아니다.\n"));
}

AND

C++에서 private 한정자

Memo 2011. 1. 7. 13:10

C++에서 private 한정자는 class 단위이다. 객체 단위가 아니다.

예를 들면,
#include <iostream>

using namespace std;

class A {
private:
 int a;
public:
 void b()
 {
  A test;
  test.a = 1;
  cout << test.a << endl;
 }
};

void main()
{
 A a;
 a.b();
}
a라는 객체에서 test라는 객체의 private 변수에 접근이 가능하다.
따라서, private 한정자는 class 단위이다.

이와 관련하여, 상속받은 상위 클래스의 private 한정자들은
하위 클래스가 상속을 받았더라도 다른 클래스이므로 private 변수에 접근할 수 없다.
상위 클래스에서 private가 아닌 protected 한정자를 사용하거나
하위 클래스에서 상위 클래스의 생성자를 이용하여 private 변수에 접근하는 수 밖에 없다.

AND


new 연산자를 사용하는 코드를 작성한 후
F11을 눌러서 디버그 모드로 들어가면 뜯어볼 수 있다.
AND