2014. 4. 30. 21:33 PROGRAMMING
[GOOGLE/API] 구글 API 지도 클릭, 주소 알아내기





<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="map" style="width:730px; height:500px;"><br /></div>
<script type="text/javascript">
<!--
	var map = new google.maps.Map(document.getElementById("map"), {
		zoom: 12,
		center: new google.maps.LatLng(37.564615,126.98420299999998),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
	google.maps.event.addListener(map, 'click', function(mouseEvent) {
		getAddress(mouseEvent.latLng);
	});

	function getAddress(latlng) {
		var geocoder = new google.maps.Geocoder();
		geocoder.geocode({
			latLng: latlng
		}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				if (results[0].geometry) {
					var address = results[0].formatted_address.replace(/^日本, /, '');
					new google.maps.InfoWindow({
						content: address + "<br />(Lat, Lng) = " + latlng
					}).open(map, new google.maps.Marker({
						position: latlng,
						map: map
					}));
				}
			} else if (status == google.maps.GeocoderStatus.ERROR) {
				alert("ERROR");
			} else if (status == google.maps.GeocoderStatus.INVALID_REQUEST) {
				alert("INVALID_REQUEST");
			} else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
				alert("OVER_QUERY_LIMIT");
			} else if (status == google.maps.GeocoderStatus.REQUEST_DENIED) {
				alert("REQUEST_DENIED");
			} else if (status == google.maps.GeocoderStatus.UNKNOWN_ERROR) {
				alert("UNKNOWN_ERROR");
			} else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
				alert("ZERO_RESULTS");
			} else {
				alert(status);
			}
		});
	}
//-->
</script>
2014. 3. 6. 09:27 COMPUTER/JAVASCRIPT, JQUERY
[CSS] 커스텀 체크박스 스타일시트 예제, 모바일용, ✔

누군가 만들어놓은 커스텀 체크박스 스타일 시트 입니다.

사용법은 <input type="checkbox" class="custom-check"........

처럼 쓰면 됩니다.





input[type=checkbox].custom-check{ 
    position: absolute; overflow:hidden; width:1px;height:1px; 
    clip:rect(0 0 0 0);margin:-1px;padding:0;border:0; 
} 

input[type=checkbox].custom-check + label.custom-check{ 
    display:inline-block; 
    padding-left:1em; 
} 

input[type=checkbox].custom-check:checked + label.custom-check:before{ 
    position:absolute;margin-left:-1em; 
    content:'✔'; 
}


2014. 2. 17. 09:30 COMPUTER/JAVASCRIPT, JQUERY
[JS/JQUERY] 제이쿼리 셀렉터 예제, jQuery Selector Example, siblings, prevAll, append, parent, css

나(this)의 상위를 제외한 같은레벨의 백그라운드 컬러를 빨간색으로 변경

$(this).parent().siblings().css("background-color", "red");


나의 상위중 클래스가 .txt_2인 가장 가까운 객체의 백그라운드 컬러를 빨간색으로 변경

$(this).parent().prevAll('.txt_2:first').css("background-color", "red");


div의 lang속성에 안두리를 포함한 태그안에 html추가

$('div[lang*="kaudo"]').append('<p class="title_3">안녕하세요.</p>');



2012. 10. 5. 09:15 COMPUTER/JAVA, JSP
[JAVA] 자바 스플릿 함수 예제, Java Split Function

Java Split 함수

 

정규표현식에 의한 스트링 배열을 반환하는 함수입니다.

2번째 파라미터 limit 옵션 값으로 갯수를 제어할 수 있습니다.

public String [] split(String  regex, int limit)


 

특수문자 자르기, 자를 문자는 정규표현식이기 때문에 특수문자는 []로 표현해야합니다.

String str="1+2+10+15";
String splitted[]=str.split("[+]");
for (String value : splitted)
	System.out.println(value);

// RESULT
// 1
// 2
// 10
// 15

 

 

자를 문자열 사이가 비었을때 limit파라미터에 -1을 사용하면 빈값으로 배열을 만들 수 있습니다.

String str="1,,3,";

String splitted[]=str.split(",");
for (String value : splitted)
	System.out.println(value);
// RESULT
// 1
// 3

String splitted[]=str.split(",",-1);
for (String value : splitted)
	System.out.println(value);

// RESULT
// 1
// 
// 3
//
2012. 9. 5. 17:41 PROGRAMMING
[CHROME/JS] 크롬 익스텐션 사용자 변수 저장/로드 샘플 예제

크롬 익스텐션 개발시 사용자 변수를 저장하거나 로드하는 예제 입니다.

 

익스텐션 특성상 사용자가 입력한값을 저장해놨다가

다시 꺼내서 불러내어놔야 할 경우가 많이 있습니다.

 

나름 쿠키를 사용해도 별 문제는 없지만,

크롬에서는 localStorage라는 저장소가 있습니다.

 

 

저장하기 [SAVE]

localStorage["변수명"]=값; (popup.html 8줄)

 

불러오기 [LOAD]

var 변수=localStorage["변수명"]; (popup.html 15줄)

 

 

샘플 프로젝트(?)

 

1. 익스텐션에서 사용할 디렉토리를 만듭니다.

 

2. manifest.json 작성

{
	"name": "kaudo chrome extension sample",
	"version": "1.0",
	"description": "blog.nachal.com",
	"browser_action": {
		"popup": "popup.html"
	},
	"permissions": [
	],
	"background": {
	}
}

 

3. popup.html 작성

<html>
<style>
textarea{width:300px;height:50px}
input{width:300px}
</style>
<script type="text/javascript">
var update=function(str){
	localStorage["source"]=str;
	result.value=str.toLowerCase().replace(/(\_[a-z])/g, function($1){
		return $1.toUpperCase().replace('_','');
	});
}

var load=function(){
	if(localStorage['source']) source.value=localStorage['source'];
	update(source.value);
}
</script>
<body onload="load()">
<textarea id="source" onkeyup="update(this.value)" onfocus="update(this.value)" onblur="update(this.value)">
AHNDOORI DOORI AHN
</textarea><br/>
<textarea id="result"></textarea>
</body>
</html>

 

 

 

2011. 3. 9. 09:56 COMPUTER/JAVA, JSP
[JAVA/JSTL] JSTL 예제 FOR, FOREACH, 변수선언, 배열선언
간단한 JSTL 예제 입니다.


배열 선언은 못하는대신에 토큰으로 구현할 수 있습니다.
2011/03/09 - [SCRIPTING] - [JAVA/JSTL] JSTL Tokenizer, 배열대용


변수 선언
<c:set var="testVar" value="${param.testVar}" />


루프, FOREACH STATEMENT
<c:forEach items="${resultList}" var="resultList" varStatus="status">
${status.count}
...CODE...
</c:forEach>


루프, FOR STATEMENT
<c:forEach var="i" begin="0" end="5" step="1">
...CODE...
</c:forEach>


비교, IF
<c:if test="${i==0}">
...CODE...
</c:if>

2010. 8. 24. 02:00 ANDROID IOS
[iPhone/Xcode] 이미지피커 델리게이트 경고, UIImagePickerController delegate, Class does not implement the 'UINavigationControllerDelegate' protocol

-(IBAction)touchButtonBackground{

UIImagePickerController *imagePicker=[[UIImagePickerController alloc] init];

imagePicker.delegate=self;

imagePicker.allowsEditing=NO;

//picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

imagePicker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;

[self presentModalViewController:imagePicker animated:YES];

[imagePicker release];

}


코드는 이미지피커에 사용되는 버튼 코드입니다.

UIImagePickerController는 선택한 이미지를 받아 처리할수 있는 델리게이트를 설정해야합니다.

당큰 대부분은 코드가 있는 현재클래스인 self를 사용하는데,

무심코 예제코드만 넣으면 경고가 뜹니다.


Class 'XXXXX' does not implement the 'UINavigationControllerDelegate' protocol


이거슨 델리게이트로 설정된 클래스에 UINavigationControllerDelegate가 정의되지 않았기때문입니다.

간단하게 클래스.h파일에 

UINavigationControllerDelegate를 추가해주면 경고는 사라집니다.


이미지 피커를 사용할때는 클래스 인터페이스에 UIImagePickerControllerDelegate와 UINavigationControllerDelegate를 정의하세요.

2009. 6. 25. 10:49 PROGRAMMING
[PHP] REGULAR EXPRESSION EXAMPLE preg_replace, preg_match, str_replace

PHP 정규표현식 예제

iframe 제거

$STRING=preg_replace("!<iframe(.*?)<\/iframe>!is","",$STRING);

script 제거

$STRING=preg_replace("!<script(.*?)<\/script>!is","",$STRING);

meta 제거

$STRING=preg_replace("!<meta(.*?)>!is","",$STRING);

style 태그 제거

$STRING=preg_replace("!<style(.*?)<\/style>!is","",$STRING);

&nbsp;를 공백으로 변환

$STRING=str_replace("&nbsp;"," ",$STRING);

연속된 공백 1개로

$STRING=preg_replace("/\s{2,}/"," ",$STRING);

태그안에 style= 속성 제거

$STRING=preg_replace("/ style=([^\"\']+) /"," ",$STRING); // style=border:0... 따옴표가 없을때
$STRING=preg_replace("/ style=(\"|\')?([^\"\']+)(\"|\')?/","",$STRING); // style="border:0..." 따옴표 있을때

태그안의 width=, height= 속성 제거

$STRING=preg_replace("/ width=(\"|\')?\d+(\"|\')?/","",$STRING);
$STRING=preg_replace("/ height=(\"|\')?\d+(\"|\')?/","",$STRING);

img 태그 추출 src 추출

preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$STRING,$RESULT);
preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$STRING,$RESULT);

호스트 추출

<?
preg_match("/^(http:\/\/)?([^\/]+)/i","http://www.kaudo.com/index.html",$matches);
$host = $matches[2];
echo$matches[0]."<br>";
echo$matches[1]."<br>";
echo$matches[2]."<br>";
?>
http://www.kaudo.com
http://
www.kaudo.com


매뉴얼:
http://kr2.php.net/manual/kr/function.preg-replace.php
http://kr2.php.net/manual/kr/function.preg-match.php
http://kr2.php.net/manual/kr/function.str-replace.php

최근에 올라온 글

최근에 달린 댓글