Nginx에서 sub-directory에 proxy pass 설정하기

btsync 서버를 띄우면 기본적으로 0.0.0.0:8888에 Web UI가 바인딩 되는데 아무리 http basic auth를 지원한다지만 어차피 평문으로 전송되기에 별 의미는 없다. 그래서 nginx에 있는 reverse proxy 기능을 이용해서 /btsync/에 물려보기로 했다. 이러면 https로 통신하니 조금 안전해지기 때문이다.
설정은 대충 아래와 같다.

location /btsync/ {
    proxy_pass http://localhost:8888/;
    proxy_redirect / /btsync/;
}

처음에 proxy_redirect를 써주지 않았는데 이러면 btsync에서 처음에 302 redirect를 주는데 이걸 nginx에서 그대로 전달하기 때문에 /btsync/gui/로 가야 할 것을 /gui/로 가게 된다. 그래서 저렇게 써야 하는데 왜 nginx는 저렇게 설계했나 모르겠다. 저 정도는 써주지 않아도 알아서 잘 동작해야 하는 것 아닌가.

nginx로 넘어오고나서 저렇게 중복해서 적어줘야 하는 게 많은 것 같아 아쉽다.

[userscript] remove ‘ㅋ’ in facebok and twitter

For facebook:

// ==UserScript==
// @name remove ㅋ
// @namespace Kjwon15
// @description remove ㅋ in any page
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
// ==/UserScript==

removeFunc = function(){
	var divs = document.querySelectorAll('div.storyContent');
	var count = 0;
	for(var i=0; i<divs.length; i++){
		count += (divs[i].innerHTML.match(/ㅋ/g)||[]).length;
		divs[i].innerHTML = divs[i].innerHTML.replace(/ㅋ/g, '');
	}
	if(count > 0){
		alert('removed ' + count + ' ㅋs');
		beeper(count);
	}
}

window.addEventListener('load', removeFunc, false);

//var button = document.createElement('button');
//button.innerHTML = 'click';
//button.style.cssText = "position: fixed; top: 0; left: 0; z-index: 9999; background-color: #808080;";
//button.onclick = removeFunc;
//document.body.appendChild(button);

For twitter

// ==UserScript==
// @name remove ㅋ at twitter
// @namespace Kjwon15
// @description remove ㅋ in twitter
// @include http://twitter.com/*
// @include https://twitter.com/*
// ==/UserScript==

removeFunc = function(){
	var count = 0;
	var tweets = document.querySelectorAll("p.js-tweet-text");
	for(var i=0; i<tweets.length; i++){
		count += (tweets[i].innerHTML.match(/ㅋ/g)||[]).length;
		tweets[i].innerHTML = tweets[i].innerHTML.replace(/ㅋ/g, '');
	};
	if(count > 0){
		alert('removed ' + count + ' ㅋs');
	}
	return false;
}

window.addEventListener('load', removeFunc, false);

var li = document.createElement('li');
var button = document.createElement('a');
button.id = 'kuchen';
button.href = "/";
button.innerHTML = '<span>remove</span>';
button.className = "js-nav";
//button.style.cssText = "display: block; height: 12px; color: #00a7e1; padding: 13px 12px 15px; font-weight: bold; line-height: 1;";
button.onclick = removeFunc;
li.appendChild(button);
document.querySelector('ul#global-actions').appendChild(li);

vim에서 자바스크립트 인덴트 제대로 하기.

을vim에서 html 코딩을 하다보면 정렬이 잘 안되서 짜증난다. 각종 플러그인을 받아서 해 봐도 script 태그 내부의 스크립트가 정렬이 잘 된다 싶으면 html 태그 자체가 정렬이 하나도 안되고 function을 작성한 후에는 그 밑의 줄이 줄의 처음으로 가서 정렬이 안되는 등 아주 불편하다.

게다가 jquery등을 하다 보면 아래처럼 되버리는 경우도 많다.

$(function(){
		some_statement;
		});

이렇게 중간에 쓸데없이 들여쓰기가 두 번 되고 끝부분은 정렬이 안된다.

그래서 몇 달간 계속 찾아다니다가 결국 발견한 플러그인이다.
html파일 내부의 script태그에서도 잘 동작하고 .js파일에서도 잘 동작한다.

http://www.vim.org/scripts/script.php?script_id=3081

혹시 모르니 첨부파일로도 넣겠지만 왠만하면 저 링크를 타고 받길 바란다.

cfile6.uf.1518973850EFEE922D306C.gz

2013/01/25 수정:
저 플러그인은 인덴트 기능 자체는 엄청 좋지만 canvas 태그를 지원 안하기도 하고 자동으로 인덴트를 해주지 않는다(gg=G를 항상 저장 전에 해줘야 한다.)
그래서 Youcef Mamar라는 사람이 알려준 플러그인(https://github.com/othree/html5.vim)을 써봤는데 이것도 다른 플러그인과 마찬가지로 script 태그의 function 인덴팅이 문제가 있다.
그래서 직접 잘 되는 부분만 합쳐서 완벽한 플러그인을 만들었다. 아래는 내가 vim 커뮤니티에 쓴 글이다.

I solve this problem.
open html.vim (at https://github.com/othree/html5.vim)
in line 264, change this
return cindent(a:lnum)
to
GetJsIndent(a:lnum)

and line 31, add this
if exists(“g:js_indent”)
    so g:js_indent
else
    ru! indent/javascript.vim
endif

finaly, install javascript.vim (at http://www.vim.org/scripts/script.php?script_id=3081)

perfectly auto indented, and no problem with <script> tag
thx for all

완성된 플러그인은 여기에 올린다.

cfile10.uf.20482E4B5101D6382E2845.tgz