'프로그래밍'에 해당하는 글 31건

1. 설치할 것 : 

1) VirtualBox 6.x, or VMWare

2) Vagrant

 

Downloads | Vagrant by HashiCorp

Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.

www.vagrantup.com

3) git bash

 

2. 홈스테드 Vagrant Box 설치하기

1) 커맨드 창에 아래의 명령어 입력

vagrant box add laravel/homestead

2) provider 선택지 : virtualbox 선택

vagrant box 설치

3) success 시 완료

 

3. 홈스테드 설치하기

1) Git bash로 home 디렉토리안에 Homestead 폴더로 저장소를 복제하기

git clone https://github.com/laravel/homestead.git ~/Homestead

 

2) master 브랜치는 개발중이라 안정적이지 않을 수도 있기 때문에, 태그를 지정한 버전을 체크아웃 

cd ~/Homestead

git checkout release

 

4. Homestead 설정하기 (Homestead.yalm)

 

1) C:\Users\사용자\Homestead\resources 에서 Homestead.yalm 수정

2) C:\Users\사용자\Homestead 에서 init.bat 실행하면 Homestead 폴더에도 Homestead.yalm 생성

 

3) Homestead.yalm 

 

folders : map은 로컬에서 프로젝트 코드의 위치, to는 가상머신 vagrant의 경로

folders:
    - map: C:/Users/사용자/project/code
      to: /home/vagrant/code

sitest : map은 가상도메인

sites:
    - map: homestead.test
      to: /home/vagrant/code/생성할 프로젝트폴더명(project1)/public

 

Homestead.yalm

 

5. ssh 키 생성

ssh-keygen -t ras -C "메일주소"

Enter passpahrase : 개인키 암호

6. host 설정

1) 메모장을 관리자 권한으로 실행한 다음 C:\Windows\System32\drivers\etc\hosts 파일 열기

2) homestead.yalm 파일에서의 ip 와 sites의 map 부분과 같아야 함

192.168.56.56           homestead.test

 

7. Vagrant Box 구동 & ssh를 통해 홈스테드 환경에 접속

vagrant up : vagrant box 구동

vagrant reload --provision : 설정 변경 후 다시 가동

vagrant ssh : ssh를 통해 홈스테드 환경에 접속

vagrant up

vagrant reload --provision (설정 변경 후 vagrant 다시 실행시)

vagrant ssh

 

8. 프로젝트 생성

 

cd ~/code
laravel new proejct1

9. homestead.test


WRITTEN BY
beautifulhill

,

composer 설치가 지원되지 않는 버전에서 사용

 

1. wkhtmltopdf 다운로드 - OS에 맞게 다운로드를 한다.

 

https://wkhtmltopdf.org/downloads.html

 

wkhtmltopdf

All downloads are currently hosted via Github releases, so you can browse for a specific download or use the links below. Stable The current stable series is 0.12.5, which was released on June 11, 2018 – see changes since 0.12.4. OS Flavor Downloads Commen

wkhtmltopdf.org

 

 

 

2. .rpm 파일의 압축을 풀어준다.

- 7-Zip 을 추천

 

 

3. wkhtmltox-0.12.5-1.centos6.x86_64.cpio 압축을 풀어준다.

 

 

4. usr/local 폴더에 bin, include, lib, share 폴더가 나온다.

 

이 폴더 안의 파일들을 각 위치에 맞게 실서버에 올린다

 

 

5. 코드 작성

 

index.php

<form name="WkhtmlPdfForm" id="WkhtmlPdfForm" action="/pdf_down.php" method="post" accept-charset="UTF-8" enctype="multipart/form-data">
	파라미터들
</form>

pdf_down.php

<?

header('Content-Type: text/html; charset=UTF-8');
$url = "http://www.naver.com";
$down_name = "test";

//tmp폴더의 test.pdf 저장
exec('/usr/local/bin/wkhtmltopdf -L 10mm -R 10mm -T 10mm -B 10mm "'.$url.'" "tmp/'.$down_name.'.pdf" 2>&1');

//tmp폴더의 test.pdf를 클라이언트가 다운받을 수 있도록
$sFilePath = 'tmp/'.$down_name.'.pdf';
$sFileName = $down_name.'.pdf';

header("Content-Disposition: attachment; filename=\"".$sFileName."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strval(filesize($sFilePath)));
header("Cache-Control: cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");

echo file_get_contents($sFilePath);
flush();
unlink($sFilePath);//tmp폴더의 test.pdf 파일을 삭제

?>

 

 

6. wkhtmltopdf font 적용 안될 때

usr/share/fonts/원하는 폰트.ttf 을 업로드한다.(폰트 설치)

 

 

 


WRITTEN BY
beautifulhill

,

추상클래스

프로그래밍/C# 2020. 3. 22. 16:47

추상 클래스, 추상 메서드

   virtual 예약어로는 자식클래스가 반드시 재정의(override)를 하도록 강제 할 수 없음

   추상메서드를 통해 자식들이 반드시 재정의 하도록 강요 

   부모 클래스에서 abstract 예약어를 지정

   자식 클래스에서 override 예약어를 사용하여 재정의

   구현코드가 없음

   추상클래스는 new를 사용해 인스턴스를 만들 수 없음

   추상메서드는 추상클래스 안에서만 선언

   다중상속 불가능

 

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            //Food food = new Food();/*오류: 추상클래스 new 사용 불가능*/
            Food coke = new Coke();
            coke.Eat(); //마신다
            Console.WriteLine(coke.Sell(1000));// 1000원을 낸다.
        }
    }
    abstract class Food
    {
        public abstract string Sell(int won);
        virtual public void Eat()
        {
            Console.WriteLine("먹는다");
        }
    }    
    class Coke : Food
    {
        public override string Sell(int won)
        {
            return won + "원을 낸다.";
        }
        new public void Eat()
        {
            Console.WriteLine("마신다");
        }
    }
}

 

'프로그래밍 > C#' 카테고리의 다른 글

다형성  (0) 2020.03.22
Object 의 메서드 - ToString, GetType, Equals, GetHashCode  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

다형성

프로그래밍/C# 2020. 3. 22. 16:11

다형성 

   하나의 클래스나 메서드가 다양한 방식으로 동작하는 것

   override

   overrode

 

 

override

   부모 클래스의 메소드에는 virtual 예약어를 통해 가상 메서드 생성

   자식 클래스의 메소드에는 override를 통해 다형성 구현

   new 예약어는 override를 사용해 재정의한 것이 아니라 독립적인 메서드이므로 

       자식 클래스를 부모클래스로 암시적 형변환시 부모클래스의 메서드가 불러와진다.

   base 예약어는 부모클래스의 메서드를 호출함

   base 예약어는 부모클래스와 자식클래스 간 중복 된 코드가 있을 경우에 사용

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Food food = new Food();
            food.Eat(); //먹는다
            Food bibim = new Bibim();
            bibim.Eat(); //비빈다
            Food coke = new Coke();
            coke.Eat(); //먹는다
            Food bbq = new Bbq();
            bbq.Eat();//굽는다 먹는다
        }
    }
    class Food
    {
        virtual public void Eat() { 
            Console.WriteLine("먹는다"); 
        }
    }
    class Bibim : Food
    {
        override public void Eat()
        {
            Console.WriteLine("비빈다");
        }
    }
    class Coke : Food
    {
        new public void Eat()
        {
            Console.WriteLine("마신다");
        }
    }
    class Bbq : Food
    {
        override public void Eat()
        {
            Console.WriteLine("굽는다");
            base.Eat();
        }
    }

}

 

Object 기본메서드 확장 - ToString 확장

   ovveride(재정의) 안했을 때

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Food food = new Food();
            Console.WriteLine(food.ToString());
        }
    }
    class Food
    {
    }
}

   ovveride(재정의) 했을 때

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Food food = new Food();
            Console.WriteLine(food.ToString());
        }
    }
    class Food
    {
        public override string ToString()
        {
            return  "먹는다.";
        }
    }
}

 

 

overrode

   메서드의 이름만 같음

   매개변수의 수, 개별 매개변수 타입, 반환값 등은 다를 수 있음

   ex) 다중생성자

'프로그래밍 > C#' 카테고리의 다른 글

추상클래스  (0) 2020.03.22
Object 의 메서드 - ToString, GetType, Equals, GetHashCode  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

System.Object

   System이라는 네임스페이스의 Object라는 클래스

   모든 타입의 조상

   기본적으로 object에서 상속받는 가정하에 코드를 생성한다.

 

Object의 메서드 - ToString

   해당 인스턴스가 속한 클래스의 전체 이름 FQDN을 반환

   기본타입의 경우 클래스의 전체 이름이 아닌 값을 반환

   하위클래스에서 재정의 가능

using System;
namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Parent p = new Parent();
            string s = "sample";
            int n = 0;
            Console.WriteLine(p.ToString());
            Console.WriteLine(s.ToString());
            Console.WriteLine(n.ToString());
        }
    }
    class Parent{ }
    class Children : Parent {
        public void Method1()
        {
        }
    }
}

 

Object의 메서드 - GetType

  상속 Object -> MemberInfo -> Type 이므로 class 로 타입을 정의할 경우 System.Type 인스턴스를 보유한다.

   GetType은 타입 전체 이름을 반환

   FullName, IsClass, IsArray 프로퍼티를 가지고 있음

using System;
namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Parent p = new Parent();
            string s = "sample";
            int n = 0;
            Console.WriteLine(p.GetType());
            Console.WriteLine(s.GetType());
            Console.WriteLine(n.GetType());
        }
    }
    class Parent{ }
    class Children : Parent {
        public void Method1()
        {
        }
    }
}

 

Object의 메서드 - Equals

   stack에 할당된 값(참조형식의 경우 힙메모리 위치)를 비교

   값형식 : 값을 대상으로 비교

   참조형식 : 할당된 메모리의 위치를 가리키는 식별자의 값 비교

using System;
namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Parent p = new Parent();
            Parent p1 = new Parent();
            string s = "sample";
            string s1 = "sample";
            int n = 0;
            int n1 = 0;
            Console.WriteLine(p.Equals(p1));
            Console.WriteLine(s.Equals(s1));
            Console.WriteLine(n.Equals(n1));
        }
    }
    class Parent{ }
    class Children : Parent {
        public void Method1()
        {
        }
    }
}

 

 

Object의 메서드 - GetHashCode

   인스턴스를 식별할 수 있는 4바이트의 int값을 반환

   타입이 int인 경우는 값을 반환

   long 타입의 경우 8바이트이기 때문에 값이 다름에도 동일한 해시코드가 반환될 수 있음

   해시 충돌이 발생할 수 있으므로 Equals 와 같이 사용

   GetHashCode 의 반환값이 같으면 Equals로 재확인

 

'프로그래밍 > C#' 카테고리의 다른 글

추상클래스  (0) 2020.03.22
다형성  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

오류를 발생시키지 않고 형변환 할 수 있는 방법

as

   형변환 결과값 반환 

   참조형 변수만 사용가능

 

is

   형변환 가능성 반환

   값 형식도 사용가능

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            int n = 1;
            if(n is string)
            {
                Console.WriteLine("int to string 가능");
            }
            Parent parent = new Parent();
            Children children = new Children();
            if(children is Parent)
            {
            	/*as없이도 parent = children 가능 children = parent 불가능*/
            	children = parent as Children;
                Console.WriteLine("children to Parent 가능");
            }
            if (parent is Children)
            {
                Console.WriteLine("Parent to Children 가능");
            }

        }
    }
    class Parent{ }
    class Children : Parent { }
}

'프로그래밍 > C#' 카테고리의 다른 글

다형성  (0) 2020.03.22
Object 의 메서드 - ToString, GetType, Equals, GetHashCode  (0) 2020.03.22
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20
Main 함수를 알아보자  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

상속

   private으로 선언된 멤버는 상속 불가능

   protected 사용시 자식클래스가 부모의 멤버에 접근 가능

   추상클래스는 다중상속 불가능

using System;
using Product;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Idol idol = new Idol();
            idol.Numb = 0;
            idol.Numb = 0;
            idol.Numb = 0;
            bool getPrize = idol.Prize();
            if(getPrize)
                Console.WriteLine("경품받기");

        }
    }   
}
namespace Product {
    class Album
    {
        private int numb;
        private string singer;
        private string album_name;
        public Album()
        {
        }
        
        public int Numb
        {
            get { return numb; }
            set { numb += 1; }
        }
    }

    class Idol : Album
    {
        public bool Prize()
        {
            if (Numb > 2)
                return true;
            else
                return false;
        }
    }
}

protected 사용

using System;
using Product;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Idol idol = new Idol();
            idol.Numb = 0;
            idol.Numb = 0;
            idol.Numb = 0;
            bool getPrize = idol.Prize();
            if(getPrize)
                Console.WriteLine("경품받기");

        }
    }   
}
namespace Product {
    class Album
    {
        protected int numb;
        private string singer;
        private string album_name;
        public Album()
        {
        }
        
        public int Numb
        {
            get { return numb; }
            set { numb += 1; }
        }
    }

    class Idol : Album
    {
        public bool Prize()
        {
            if (numb > 2)
                return true;
            else
                return false;
        }
    }
}

'프로그래밍 > C#' 카테고리의 다른 글

Object 의 메서드 - ToString, GetType, Equals, GetHashCode  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20
Main 함수를 알아보자  (0) 2020.03.20
객체지향-1  (0) 2020.03.19

WRITTEN BY
beautifulhill

,

객체지향 -2

프로그래밍/C# 2020. 3. 20. 15:39

캡슐화

   관련이 있는 변수와 메소드들을 클래스로 묶어 외부로부터 내부 멤버를 은닉하는 것을 캡슐화라고 한다.

   숨겨야 할 변수, 메소드는 private 접근제한자로, 외부에 노출한 기능은 public 접근제한자를 사용한다.

 

접근제한자

   private                : 내부에서만 접근 가능

   protected            : 내부 OR 파생클래스에서 접근 가능

   public                 : 외부에서도 접근 가능

   internal               : 동일한 어셈블리 내에서 접근 가능

   internal protected : 동일 어셈블리 내에서 접근 가능, 다른 어셈블리의 경우 파생클래시인 경우에 접근  

 

default 접근제한자

   class : internal

   class내부 멤버 : private

 

접근자 메서드 & 설정자 메서드 ( getter, setter)

class Program
{
	static void Main(string [] args)
    {
    	Album album = new Product.Album();
        album.SetAlbum("아이들", "I am");
        album.SetAlbum("아이들", "I made");
        album.SetAlbum("아이들", "Uh-Oh");
        Console.WriteLine(album.GetAlbum() + "개");
    }
}
class Album
{
	private int numb;
	private string singer;
	private string album_name;
	public int GetAlbum()
	{
		return numb;
	}
	public void SetAlbum(string singer, string album_name)
	{
		numb += 1;
		this.singer = singer;
		this.album_name = album_name;
	}
}

 

프로퍼티

   setter, getter를 편리하게 사용할 수 있도록하는 문법

using System;
using Product;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Album album = new Album();
            album.Numb = 0;
            album.Singer = "아이들";
            album.Album_name = "Uh-Oh";

            album.Numb = 0;
            album.Singer = "아이들";
            album.Album_name = "I am";
            Console.WriteLine(album.Num+"개");
        }
    }   
}
namespace Product {
    class Album
    {
        private int numb;
        private string singer;
        private string album_name;

        public int Numb {
            get {
                return numb;
            }

            set
            {
            numb += 1;
            }
        }
        public string Singer
        {
            get
            {
                return singer;
            }

            set
            {
                singer = value;
            }
        }
        public string Album_name
        {
            get
            {
                return album_name;
            }

            set
            {
                album_name = value;
            }
        }


    }
}

'프로그래밍 > C#' 카테고리의 다른 글

as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
Main 함수를 알아보자  (0) 2020.03.20
객체지향-1  (0) 2020.03.19
break, continue, goto  (0) 2020.03.19

WRITTEN BY
beautifulhill

,