2015년 3월 30일 월요일

CSS How to automatically crop and center an image

http://stackoverflow.com/questions/11552380/how-to-automatically-crop-and-center-an-image

2015년 3월 25일 수요일

Python 위치 인수, 키워드 인수 | Arguments and Keyword Arguments in Python

함수에 인수를 넣어서 바로 출력하도록 정의

def function1(data):
    for arg in data:
        print(arg)

function1('A')
A

그러나, 함수에 복수의 인수를 넣었을 때는 실행이 안 된다.

function1('A', 'B')
Traceback (most recent call last):
  File "", line 14, in 
TypeError: function1() takes exactly 1 argument (2 given)

function1()은 인수를 1개만 받도록 되어 있다는 에러 메세지가 출력된다.

이 경우, 함수를 정의할 때 인수에 *을 붙여서 정의하면
함수를 실행할 때 인수가 몇 개가 되든 args에 튜플 자료형의 변수로 들어간다.
따라서 반복문에서도 문제 없이 실행된다.

def function2(*args):
    for arg in args:
        print(arg)

function2('A')
print('-' * 20)
function2('A', 'B')
print('-' * 20)
function2('A', 'B', 'C')
A
--------------------
A
B
--------------------
A
B
C

다음은 key값이 정해져 있는 인수를 받는 경우.
함수 안에서 kwargs라는 변수는 dict 자료형으로 변환된다.

def function3(**kwargs):
    print(kwargs['key'])

function3(key='A')
A
def function4(**kwargs):
    for arg in kwargs:
        print(kwargs[arg])

function4(a=1, b=2, c=3)
1
3
2
def function5(**kwargs):
    print(kwargs)

function5(a=1, b=2, c=3)
{'a': 1, 'c': 3, 'b': 2}

2015년 3월 10일 화요일

PHP Resize and crop image from center

http://polyetilen.lt/en/resize-and-crop-image-from-center-with-php

이미지를 center로 crop한 뒤 지정한 width, height로 resize하는 함수.

궁극적으로는 github의 프로필 사진처럼 사용자가 직접 crop의 범위를 선택할 수 있도록 하는 API를 만들어야 함.


해보진 않았지만

http://www.bewebdeveloper.com/tutorial-about-crop-photo-using-php-and-jquery

이거면 될 듯.

2015년 1월 23일 금요일

hilite.me 코드에 HTML 스타일 적용

http://hilite.me/

PHP 상하로만 셀병합된 데이터 HTML TABLE 소스로 자동 코딩하기

상하로만 셀병합된 Excel 데이터를 csv 형식으로 저장하고
이 데이터가 $csv_data 2차원 array에 들어 있다고 가정

<?php
$count_csv_data = count($csv_data);
for($i=0; $i<$count_csv_data; $i++) {
    for($j=0; $j<count($csv_data[0]); $j++) {
        $rowspan_csv_data[$i][$j] = 0;
    }
}
for($i=$count_csv_data-1; $i>=0; $i--) {
    for($j=0; $j<count($csv_data[0]); $j++) {
        if($csv_data[$i][$j] == "") {
            $rowspan_csv_data[$i-1][$j] = $rowspan_csv_data[$i][$j] + 1;
            $rowspan_csv_data[$i][$j] = 0;
        } else {
            $rowspan_csv_data[$i][$j] += 1;
        }
    }
}
$table_data = "<table>";
for($i=0; $i<$count_csv_data; $i++) {
    $table_data .= "<tr>";
    for($j=0; $j<count($csv_data[0]); $j++) {
        if($rowspan_csv_data[$i][$j] == 0) {
        } else if($rowspan_csv_data[$i][$j] == 1) {
            $table_data .= "<td>";
            $table_data .= $csv_data[$i][$j];
            $table_data .= "</td>";
        } else {
            $table_data .= "<td rowspan=".$rowspan_csv_data[$i][$j].">";
            $table_data .= $csv_data[$i][$j];
            $table_data .= "</td>";
        }
    }
    $table_data .= "</tr>";
}
$table_data .= "</table>";

MySQL 유용한 링크 모음

shell에서 sql script 실행하기
CSV File Import
JOIN을 이용한 여러 테이블 DELETE

http://moonlighting.tistory.com/category/Programming/sql



중복 제거

http://wus1590.blogspot.kr/2013/07/mysql-delete-from-in.html