2016年2月21日星期日

Fwd: Caller Info

经常在打log的时候要把上下文带上,很麻烦,好在C#提供了一个功能,可以在编译时获得调用者的方法名、文件名和行号,十分方便。
如果你以前用C++写Logger,一定对这些宏不陌生:
二者功能类似。

常言道:If it can be done in authoring time, don't do it in compile time. If it can be done in compile time, don't do it in run-time.

是为一点小小的心得。

2016年2月14日星期日

ssh tunnel from the phone

sometimes I want to share a photo from my phone via facebook, then I need ssh tunnel on phone.
As I used Android, I get VX connectbot from my local app store. It has port forward functionality build-in.
As I cannot always open putty on my laptop, I put the proxy into background
cat start_proxy.sh
{{{
nohup python proxy.py --port 8080 --hostname '' > proxy.log 2>&1 &
}}}


On my phone, the proxy setting is not at browser level, but at WALN setting, which means the network traffic of any app will go to the proxy, but interesting, the ssh tunnel itself didn't go to the proxy.

Don't forget to stop the proxy when you want to save money.

{{{
pkill -f proxy.py
}}}


2016年2月12日星期五

Fwd: Proxy.py + SSH Tunnel

I have a Linux server S in JP WEST, which can connect to Google.
Then I setup a proxy.py, a single file web proxy which support HTTPS, at S:8080.
Then I use SwitchySharp locally and set S:8080 as proxy server.
However, when I open Google in browser and search something, the connection is closed.
Checked proxy.py log, it should be because the communication between local machine and S was detected contains Google in plain text. Then I understand what happened on the wire.

Then I use Putty to setup SSH Tunnel, map local:1234 to S:8080, and set localhost:1234 as proxy in SwitchSharp.

Finally the information goes like this: my browser -- local proxy at localhost:1234 -- remote proxy at S:8080 -- internet