Jan 2, 2011

Survival guide: One PC climbed the GFW and share it to all devices

People who come to work in China must find it annoying when accessing to internet. Many of the popular websites have been blocked ("harmonized") thanks to the stupid policy. Since you can read this post, I supposed you are outside of China or you have found the way to climb through GFW.

OK, here's my way to "climb and share":

First, you have to use a tool to break through GFW, either by TOR (slow, not suggested), ssh tunneling (fast and convenient), Freegate (free), VPN (mostly not free) or other means.

Second, download Privoxy here.

Once you have downloaded and installed Privoxy, continue to the configuration steps as follows.

Right click on the Privoxy icon, select "Edit/Main configuration", find the following line:
listen-address 127.0.0.1:8118
and change it as follows:
listen-address 0.0.0.0:80
The reason I used port 80 is because iPhone needs this to make Safari works.

Next, permit access for the home network. Find the following line:
# permit-access 192.0.2.0/24
Remove "#" in the beginning of the line to make it work.

Then, forward the traffic to the proxy you're using. In my case, I am using ssh tunnel as socks5 proxy on 127.0.0.1:7070, so my settings are as follows:
forward-socks4a / 127.0.0.1:7070 .
forward-socks5 / 127.0.0.1:7070 .
You can add these two lines in the end of section sample 5.2.

So far it is basiclly working. Restart your Privoxy and you have a forwarding proxy functioning on your computer at port 80.

Trivial:
If you want to know what's happening in your Privoxy, you can turn the debug info on.
Find the 4 lines "debug 1, debug 1024, debug 4096, debug 8192" in the end of section 3.1, remove "#" in the beginning. Then you sould be able to see the logs in Privoxy main window.
debug 1 # Log the destination for each request Privoxy let through.
debug 1024 # Log the destination for requests Privoxy didn't let through, and the reason why.
debug 4096 # Startup banner and warnings
debug 8192 # Non-fatal errors

iPhone settings example:
Go to the network settings, pick the wireless you're using at home:
And take a look at the bottom part, switch the HTTP proxy settings from "Off" to "Manual", and put in your shared proxy PC's IP. Finally it will look quite similar as mine:

Try to use Facebook app afterwards ;)

Dec 2, 2010

Pain-killing one-liner for monitoring Phusion Passenger

Finally, I found a good article here describing the same problem I've met with Phusion Passenger which the memory usage can't be monitored by monit.

Here's the working command:
kill $(/opt/ruby-enterprise-1.8.7-2010.02/bin/passenger-memory-stats | grep '[56789]..\.. MB.*Rails' | awk '{ print $1 }')
This command means 'find out Rails sub-processes which consumes 500-999MB private memory will be killed.

I run it once per minute on my production server.


It just works.

Aug 11, 2010

Macport automatic upgrade caused some problems

Today while I'm upgrading Macport on my osx86 box, 2 serious errors were encountered.

  1. gcc43 upgrade to gcc44 compiling failed
  2. openssl upgraded from 0.9.8 to 1.0.0 caused libcrypto dependency broken
For me, it doesn't matter that gcc43 failed to upgrade to gcc44, so the macport team will fix it anyway.
The libcrypto dependency problem is a bit painful and I really don't care about what's improved in openssl 1.0.0, so I set it back to 0.9.8, following the instructions of this page.
Commands are simple:

First, list installed packages:
sudo port installed | grep openssl
I got the following returns:
  openssl @0.9.8k_0
  openssl @0.9.8l_0+darwin
  openssl @1.0.0a_0
So I decided to fall back to 0.9.8k_0...
sudo port deactivate openssl
sudo port activate openssl@0.9.8k_0
Done!

Apr 27, 2009

Very simple Ubuntu command line upgrade

While I would like to install some new component for our Ubuntu server (Gutsy) I found it's impossible to download packages any more, due to outdated system binary version. So here's the command to upgrade the whole system whilst I wish them to work properly ;)
It is better to run this command in the console, though I ran it in my screen session, who cares? It did notified me there's a 9004 port open for an emergency ssh connection.
Here's the command:

sudo do-release-upgrade

Then answer "Y" to any questions.
Simple, right?

Apr 16, 2008

Visualized evolution tree of R-Type Final ships

I prefer to get inspired through gaming experience. Like this one, while I am playing my favorite shooting game "R-Type Final", I have difficulties to get the ships I want. And then, I got inspired by graphviz and start to think how I can make the evolution tree of that since I found nothing on the net who has this kind of visualized tree which is very easy to understand.

Sorry I forgot where I got the text source. Here's the evolution progress which I've organized using dot language. Note: I just used the very basic part to draw the graph and I think simplicity is also a beauty.

digraph "R-Type Family Tree"
{
node [shape=box]; Start; 001; 027;
label = "R-Type Family Tree"
Start -> 001;
001 -> "Finished Stage 1.0";
027 -> "Finished Stage 1.0";
001 -> "Finished Stage 3.0";
027 -> "Finished Stage 3.0";
"Finished Stage 1.0" -> 002;
002 -> 003 [label="password 41704170"];
003 -> 004 [label="60min"];
004 -> 005 [label="004 cleared\n120min passed"];
054 -> 005 [label="Finished with 054"];
"Finished Stage 3.5" -> 005;
005 -> 006 [label="005 cleared\n60min passed"];
006 -> 007 [label="006 used 60min"];
007 -> 008 [label="007 used 120min"];
"Finished Stage 3.0" -> 009;
009 -> 010 [label="009 used 15min"];
009 -> 011 [label="009 used 30min"];
011 -> 012 [label="011 used 30min"];
012 -> 013 [label="012 used 60min"];
002 -> 014 [label="002 cleared\n120min passed"];
"Finished Stage 6.2" -> 014;
014 -> 015 [label="014 used 15min"];
015 -> 016 [label="015 used 60min"];
"Finished Stage F-A" -> 016;
016 -> 017 [label="016 used 60min"];
015 -> 018 [label="015 cleared\n15min passed"];
018 -> 019 [label="018 used 30min"];
018 -> 020 [label="018 cleared\n15min passed"];
020 -> 021 [label="020 used 15min"];
021 -> 022 [label="021 used 15min"];
020 -> 023 [label="020 cleared\n180min passed"];
058 -> 024 [label="password 50501060"];
024 -> 025 [label="024 cleared\n15min passed"];
025 -> 026 [label="025 used 30min"];
032 -> 026 [label="032 cleared"];
Start -> 027;
027 -> 028 [label="027 used 15min"];
"Finished Stage 2.2" -> 029;
029 -> 030 [label="029 used 15min"];
030 -> 031 [label="030 used 30min"];
029 -> 032 [label="029 cleared\n45min passed"];
032 -> 033 [label="032 used 30min"];
032 -> 034 [label="032 cleared\n120min passed"];
034 -> 035 [label="034 used 30min"];
035 -> 036 [label="035 used 30min"];
"Finished Stage 6.1" -> 036;
"Game time" -> 037 [label="5min passed"];
"Game time" -> 038 [label="45min passed"];
"Game time" -> 039 [label="120min passed"];
"Game time" -> 040 [label="360min passed"];
"Game time" -> 041 [label="540min passed"];
Start -> 042;
"Game time" -> 043 [label="90min passed"];
043 -> 044 [label="043 used 30min"];
044 -> 045 [label="044 used 30min"];
045 -> 046 [label="045 cleared\n60min passed"];
046 -> 047 [label="046 used 60min"];
043 -> 048 [label="043 cleared\n20min passed"];
048 -> 049 [label="048 used 90min"];
049 -> 050 [label="049 used 15min"];
050 -> 051 [label="050 used 30min"];
051 -> 052 [label="051 used 60min"];
052 -> 053 [label="052 used 60min"];
048 -> 054 [label="048 cleared\n15min passed"];
054 -> 055 [label="054 cleared\n30min passed"];
054 -> 056 [label="054 used 15min"];
056 -> 057 [label="056 cleared\n30min passed"];
057 -> 058 [label="057 used 30min"];
058 -> 059 [label="password 59595959"];
057 -> 060 [label="057 cleared\n15min passed"];
060 -> 061 [label="060 cleared\n15min passed"];
010 -> 062 [label="010 cleared"];
056 -> 062 [label="056 cleared\n30min passed"];
044 -> 063 [label="044 cleared"];
062 -> 063 [label="used 15min"];
021 -> 064 [label="021 cleared"];
063 -> 064 [label="063 cleared\n30min passed"];
064 -> 065 [label="064 cleared\n30min passed"];
003 -> 066 [label="003 cleared"];
065 -> 066 [label="065 used 15min"];
065 -> 067 [label="065 cleared\n60min passed"];
071 -> 067 [label="071 cleared"];
067 -> 068 [label="067 used 30min"];
072 -> 068 [label="072 cleared"];
043 -> 069 [label="043 used 30min"];
"Finished Stage F-A" -> 069;
069 -> 070 [label="Finished Stage 3.5"];
070 -> 071 [label="070 used 30min"];
071 -> 072 [label="071 used 30min"];
072 -> 073 [label="072 used 120min"];
"Finished Stage 6.1" -> 074;
074 -> 075 [label="074 used 5min"];
075 -> 076 [label="075 used 5min"];
076 -> 077 [label="076 used 15min"];
075 -> 078 [label="075 cleared\n30min passed"];
078 -> 079 [label="078 used 5min"];
079 -> 080 [label="079 used 15min"];
078 -> 081 [label="078 cleared\n30min passed"];
081 -> 082 [label="081 used 5min"];
082 -> 083 [label="082 used 15min"];
081 -> 084 [label="081 cleared\n30min passed"];
084 -> 085 [label="084 used 5min"];
085 -> 086 [label="085 used 15min"];
084 -> 087 [label="084 cleared\n30min passed"];
087 -> 088 [label="087 used 5min"];
088 -> 089 [label="088 used 15min"];
088 -> 090 [label="088 cleared"];
090 -> 091 [label="090 used 15min"];
090 -> 092 [label="090 cleared\n30min passed"];
092 -> 093 [label="092 used 15min"];
092 -> 094 [label="092 cleared\n30min passed"];
094 -> 095 [label="094 used 5min"];
095 -> 096 [label="095 used 5min"];
096 -> 097 [label="096 used 15min"];
097 -> 098 [label="097 used 30min"];
098 -> 099;
"Get 001~098\n1min passed" -> 099;
099 -> 100;
058 -> 100 [label="password 99100101"];
100 -> 101 [label="100 used 30min"];
}
OK, here is it, the generated picture, you may wish fine tune it a little bit or add more tastes.
How's that?