반응형

ubuntu 14.04 LTS 에서 apache, php5, mysql 설치하기


참고 :   http://opentutorials.org/module/255/2602

     http://www.blossom7.net/ubuntu-12-04-lts-apm-install-apache-php-mysql/



** 생활코딩 이고잉님 동영상 강좌




<< 설치 순서 >>


1. 설치할 팩키지 정보 업데이트 

sudo apt-get update

  --> (업데이트 안하면 중간에 에러 발생할수도 있다)


2. 아파치 2 설치

sudo apt-get install apache2



===> 여기까지 설치후, 웹브라우저에 localhost 입력하면, 아래 그림처럼 apache 서버 작동 모습 확인 가능하다.






3. mysql 인증 모듈 설치

sudo apt-get install libapache2-mod-auth-mysql

       --> 참고 : http://www.hamslab.com/lab/php/web_auth/web_auth_mysql.html


4. mysql 설치

sudo apt-get install mysql-server mysql-client

 --> 설치중에 mysql 비밀번호 설정한다.

 



5. PHP5 설치 ( 자세한 내용은 http://freeprog.tistory.com/148 참고)

sudo apt-get install php5-common php5 libapache2-mod-php5


6. PHP와 MySQL을 연동하기 위한 모듈을 설치

sudo apt-get install php5-mysql




7. apache를 재시작

sudo /etc/init.d/apache2 restart


8. mysql 을 재시작

sudo /etc/init.d/mysql restart




*** web server 잘 되는지 확인 작업.


1. php 테스트 파일 만들기

sudo gedit /var/www/test.php      

(주의: Ubuntu 14.04 LTS 에서는   sudo gedit /var/www/html/test.php  로 해야한다.)  


2. gedit 편집기 열리면 아래 내용 입력후 저장한다.


<?php

echo("Test my first php");

?>


3. web browser 열고, 아래 주소 입력한다.

localhost/test.php


4. 아래 처럼 나오면 성공!!!




<< 참고 >>    http://php.net/manual/en/ini.core.php#ini.short-open-tag


현재는 php 코드문을 <?php     ?> 양식으로 해야만 인식한다. 

  --> <?  ?> 양식도 인식하게 하게 위해서는  /etc/php5/apache2/php.ini 파일에서  short_open_tag = On 으로 설정 변경후 저장해야한다.

  --> 이후에 apache 재시작 해야한다. 

         sudo /etc/init.d/apache2 restart



위의 test.php를 아래와 같이 바꿔도 잘 실행 된다...

  <?

     echo("Test my first php");

  ?>




* apache, mysql 작동 테스트 





* MySQL을 잘 설치했는지 확인 명령어


mysql -uroot -p

  ---> 시작시, mysql 설치시 입력한 비밀번호 입력해야함.

  ---> mysql 종료 명령어 :  exit; 엔터





** 아파치 및 MySQL 설정 및 디폴트 디렉토리


  아파치 설정 파일 : /etc/apache2/apache2.conf

  mysql 설정 파일 :  /etc/mysql/my.cnf

  Default Web root : /var/www      ( ubuntu 14.04 LTS 에서는 /var/www/html )

  Apache root location : /etc/apache2/sites-available/default







반응형
Posted by 자유프로그램
,
반응형

visual studio 2013 에서 C/C++ 명령행 인수 넣기


환경 : windows 7 32bit, visual studio 2013


참고  :  http://stackoverflow.com/questions/3697299/passing-command-line-arguments-in-visual-studio-2010



* console 프로그램 만들어 인수 넣어줘야 하는 경우, cmd 창 사용 대신

   그냥 visual studio 2013 환경에서 설정해보자.





* 프로젝트 속성창 -> 구성속성 -> 디버깅 -> 명령 인수에  command line 에서 사용할 인수 넣으면 된다.














반응형
Posted by 자유프로그램
,

read only memory in C/C++

C & C++ 2014. 7. 14. 12:46
반응형


What is the difference between char s[] and char *s in C?


http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c





How is read-only memory implemented in C?


http://stackoverflow.com/questions/1704893/how-is-read-only-memory-implemented-in-c






http://effserv.tistory.com/131






http://www.linuxquestions.org/questions/programming-9/why-char-%2A-is-called-read-only-memory-%5Bc-c-%5D-171014/#post4136372


  // This is allocated from the heap with the C++ "new" operator
  // It's read-write
  // You must use "delete" to dispose of it
  char* str1 = new char[20];

  // This is allocated from the heap with the C "malloc()" function
  // It's also read-write
  // You must use "free()" to dispose of it
  char* str2 = malloc (20);

  // This is allocated from the stack
  // It, too, is read-write
  // It's disposed of when then block exits (usually, at the end of the function)
  char* str3[20];

  // This is a constant
  // It is READ-ONLY
  // You MUST NOT try to write to it!
  char* str4 = "Hi.123456789";








반응형
Posted by 자유프로그램
,
반응형

clipboard 로 text, image 복사하기 , 가져오기


테스트환경  : windows 7 32bit 

                   python 2.7.7

                   pywin32  218   -  win32clipboard 모듈사용위함.

                             -- http://sourceforge.net/projects/pywin32/files/?source=navbar

                   PIL 1.1.7



*** GUI 환경인 경우는 wxpython 에서 제공하는 clipboard 관련 기능 사용하는게 편함.



* clipboard 로 TEXT 복사하기

     http://stackoverflow.com/a/101167


import win32clipboard

# set clipboard data
win32clipboard.OpenClipboard()
win32clipboard.SetClipboardText('testing 123 한글 출력')
win32clipboard.CloseClipboard()



clipboard 에서 TEXT 가져오기  

     --- windows IDLE  에서는 한글 출력 정상이지만, 다른 환경에서는 테스트 못함.


import win32clipboard

# get clipboard data
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
print data



* clipboard 로 image 복사하기

http://pastebin.com/tDMiAq6F



from cStringIO import StringIO
import win32clipboard
from PIL import Image
 
def send_to_clipboard(clip_type, data):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(clip_type, data)
    win32clipboard.CloseClipboard()
 
filepath = 'cat.jpg'
image = Image.open(filepath)
 
output = StringIO()
image.save(output, "BMP")
# image.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]   # The file header off-set of BMP is 14 bytes.
output.close()
 
send_to_clipboard(win32clipboard.CF_DIB, data)



http://stackoverflow.com/a/24635307

   --- The file header off-set of BMP is 14 bytes.





* clipboard 에서 image 가져오기


http://stackoverflow.com/a/7045677

from PIL import ImageGrab   # windows only

im = ImageGrab.grabclipboard()

im.save('test.bmp','BMP')   # BMP 로 저장
# im.save('test.png','PNG')   # PNG 포맷으로 저장
# im.save('test.jpg','JPEG')







반응형
Posted by 자유프로그램
,
반응형


Pyplot tutorial


http://matplotlib.org/1.3.1/users/pyplot_tutorial.html


환경 : windows 7 32bit, matplotlib 1.3.1, numpy 1.8.1



matplotlib.pyplot  : MATLAB 처럼 matplotlib 을 사용할수있게 하는 명령 스타일 함수들(command style functions) 모음이다.


   ex)  figure 생성하고  -> figure에 plotting area 생성 -> plotting area 에 line 그리고  -> label 등을 꾸미고.. etc.



* plotting 함수들은 current axes 에 작용한다.



import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

**  plot() 에  값 한개만 입력시에는 y 값으로 생각한다.

   -- x 값은  자동생성한다.(0 부터 시작함)



import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])   # [xmin, xmax, ymin, ymax]
plt.show()


matplotlib.pyplot.plot(*args**kwargs)

Plot lines and/or markers to the Axes

plot(x, y)        # plot x and y using default line style and color
plot(x, y, 'bo')  # plot x and y using blue circle markers
plot(y)           # plot y using x as index array 0..N-1
plot(y, 'r+')     # ditto, but with red plusses
a.plot(x1, y1, 'g^', x2, y2, 'g-')


format string characters are accepted to control the line style or marker:

characterdescription
'-'solid line style
'--'dashed line style
'-.'dash-dot line style
':'dotted line style
'.'point marker
','pixel marker
'o'circle marker
'v'triangle_down marker
'^'triangle_up marker
'<'triangle_left marker
'>'triangle_right marker
'1'tri_down marker
'2'tri_up marker
'3'tri_left marker
'4'tri_right marker
's'square marker
'p'pentagon marker
'*'star marker
'h'hexagon1 marker
'H'hexagon2 marker
'+'plus marker
'x'x marker
'D'diamond marker
'd'thin_diamond marker
'|'vline marker
'_'hline marker



charactercolor
‘b’blue
‘g’green
‘r’red
‘c’cyan
‘m’magenta
‘y’yellow
‘k’black
‘w’

white



http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.axis
matplotlib.pyplot.axis(*v**kwargs)

Convenience method to get or set axis properties.

>>> axis(v)

sets the min and max of the x and y axes, with v = [xmin, xmax, ymin, ymax].:



*** matplotlib 은 numpy array 를 사용한다. 

    : seqence 자료 (list etc)는 내부적으로 numpy array로 변환하여 사용한다.







import numpy as np
import matplotlib.pyplot as plt

# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)

# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()




line 속성 제어하기 (Controlling line properties)


참고 :  matplotlib.lines.Line2D  

         http://matplotlib.org/1.3.1/api/artist_api.html#matplotlib.lines.Line2D



plt.plot(x, y, linewidth=2.0)


line, = plt.plot(x, y, '-')
line.set_antialiased(False) # turn off antialising


 setp()  명령어 사용

lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color='r', linewidth=2.0)
# or MATLAB style string value pairs
plt.setp(lines, 'color', 'r', 'linewidth', 2.0)


* line 속성 얻을때도, setp()  명령어 사용

In [69]: lines = plt.plot([1,2,3])

In [70]: plt.setp(lines)
  alpha: float
  animated: [True | False]
  antialiased or aa: [True | False]
  ...snip



여러개의 figure & axes 로 작업하기 (Working with multiple figures and axes)


pyplot  --- current figure, current axes 의 개념이 있다. 


* 모든 plotting 명령어는 current axes 에 적용된다. 


* gca() --- current axes 반환 (matplotlib.axes.Axes instance)

* gcf() --- current figure 반환 (matplotlib.figure.Figure instance)



import numpy as np
import matplotlib.pyplot as plt

def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)   #  생략 가능
plt.subplot(211)   # row number, column number, figure number
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()


 ---  plt.figure(1) 생략 가능  : defalut 로 figure(1) 생성 된다.

 ---   axes 지정 하지않으면, defalut 로 subplot(111)  생성됨.



*** figure() 를 여러번 호출하여, 여러개의 figure 생성 가능하다. 

     (각 figure 는 자신만의 axes , subplot 를 갖는다)

import matplotlib.pyplot as plt
plt.figure(1)                # the first figure
plt.subplot(211)             # the first subplot in the first figure
plt.plot([1,2,3])
plt.subplot(212)             # the second subplot in the first figure
plt.plot([4,5,6])


plt.figure(2)                # a second figure
plt.plot([4,5,6])            # creates a subplot(111) by default

plt.figure(1)                # figure 1 current; subplot(212) still current
plt.subplot(211)             # make subplot(211) in figure1 current
plt.title('Easy as 1,2,3')   # subplot 211 title


clf() --- clear current figure.

cla() --- clear current axes.



***  메모리 해제 :  close()

     -  close() 호출되기 전까지는, pyplot 이 참조를 계속 가지고 있다.



텍스트 작업하기 (Working with text)


http://matplotlib.org/1.3.1/api/pyplot_api.html#matplotlib.pyplot.text


matplotlib.pyplot.text(xysfontdict=Nonewithdash=False**kwargs)

 -- 좌표 x,y 에 텍스트 s 출력하기


import numpy as np
import matplotlib.pyplot as plt

mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)

# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)


plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()




t = plt.xlabel('my data', fontsize=14, color='red')



텍스트로 수학식 표현하기 (Using mathematical expressions in text)


built-in TeX expression parser and layout engine


plt.title(r'$\sigma_i=15$')


참고 : http://matplotlib.org/1.3.1/users/mathtext.html#mathtext-tutorial 



텍스트 주석달기 (Annotating text)


참고 : http://matplotlib.org/1.3.1/api/pyplot_api.html#matplotlib.pyplot.annotate


matplotlib.pyplot.annotate(*args**kwargs)

annotate(s, xy, xytext=None, xycoords='data',
         textcoords='data', arrowprops=None, **kwargs)

---  주석 = s, 화살표 시작 = x,y ,  주석 텍스트 시작 = xytext


import numpy as np
import matplotlib.pyplot as plt

ax = plt.subplot(111)

t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = plt.plot(t, s, lw=2)

plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
            arrowprops=dict(facecolor='black', shrink=0.05),
            )

plt.ylim(-2,2)
plt.show()









반응형
Posted by 자유프로그램
,