Skip to content

Instantly share code, notes, and snippets.

View jeonghwan-kim's full-sized avatar

김정환 jeonghwan-kim

View GitHub Profile
@jeonghwan-kim
jeonghwan-kim / cut-text-hangul.php
Created October 12, 2013 10:24
한글 문자열 자르기 $text: 자를 문자열 $count: 잘라서 반환할 텍스트 길이 $more: 반환할 텍스트 마직막에 붙일 길고
function cut_text($text, $count, $more = "...") {
$length = mb_strlen($text, "UTF-8");
if($length <= $count)
return $text;
else
return mb_substr($text, 0, $count, "UTF-8") . " " . $more;
}
echo cut_text('우리 나라 만세', 10);
@jeonghwan-kim
jeonghwan-kim / file-upload.php
Created October 12, 2013 10:25
php 파일 업로드
<?php
if(isset($_POST['submit'])) {
$save_dir = "./";
//파일이 HTTP POST 방식을 통해 정상적으로 업로드되었는지 확인한다.
if(is_uploaded_file($_FILES["upload_file"]["tmp_name"])){
echo "업로드한 파일명 : " . $_FILES["upload_file"]["name"];
//파일을 저장할 디렉토리 및 파일명
$dest = $save_dir . $_FILES["upload_file"]["name"];
//파일을 지정한 디렉토리에 저장
if(move_uploaded_file($_FILES["upload_file"]["tmp_name"], $dest))
@jeonghwan-kim
jeonghwan-kim / slide-images.html
Created October 12, 2013 15:43
slide images by using Bootstrap.
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap.css"rel="stylesheet"media="screen">
<style type="text/css">
.foo {
margin-left: 30px;
width: 300px;
border: solid 10px #AAA;
}
@jeonghwan-kim
jeonghwan-kim / detect-mobile-devices.php
Created October 14, 2013 01:48
Detect mobile devices such as iPhone, android phone.
<?php
//Detect devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
if ( $Android )
echo 'Android';
else if ( $iPod || $iPhone || $iPad )
@jeonghwan-kim
jeonghwan-kim / my-daum-editor-sample.php
Last active December 25, 2015 11:49
daum editor sample. 데이터 입력 및 세팅 기능 테스트
<?php
/**
* 참고주소:
*/
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@jeonghwan-kim
jeonghwan-kim / fork-sample.c
Created October 15, 2013 02:14
fork() sample
#include <sys/types.h>
#include <stdio.h>
int a = 6;
int main( void )
{
int b;
pid_t pid;
@jeonghwan-kim
jeonghwan-kim / html-auth.php
Created October 19, 2013 08:57
html authorization
<?php
$username = 'user name';
$password = 'password';
$range = 'range';
if (!isset($_SERVER['PHP_AUTH_USER']) ||
!isset($_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] != $username) ||
($_SERVER['PHP_AUTH_PW'] != $password))
{
@jeonghwan-kim
jeonghwan-kim / select_sort.c
Created October 25, 2013 01:21
select sort
void select_sort(int a[], int n) {
for (int i = 0; i < n - 1; i++) {
int min = i;
for (int j = i + 1; j < n; j++) {
if (a[j] < a[min]) min = j;
}
// swap
int temp = a[i];
a[i] = a[min];
a[min] = temp;
@jeonghwan-kim
jeonghwan-kim / insert_sort.c
Created October 25, 2013 01:25
insert sort
void insert_sort(int a[], int n) {
for (int i=1; i<n; i++) {
int temp = a[i];
// 정렬되어 있는 배열의 경우 루프를 실행하지 않는다.
for (int j=i; j>0 && a[j-1] > a[j]; j--) {
a[j] = a[j-1];
a[j-1] = temp;
}
}
@jeonghwan-kim
jeonghwan-kim / bubble_sort.c
Created October 25, 2013 01:28
Bubble sort
void bubble_sort(int a[], int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}