Using SSH as a SOCKS proxy

Ever needed a static IP for your browsing or to get around some network restriction?
If you have a server outside the network running an SSH server, then it's fairly easy ...

On your local machine, create an SSH tunnel to your server:
ssh -C -D 5673

Now, in your browser config, setup a socks proxy (I'm using firefox to demonstrate):
Firefox via Socks Proxy
If your server is sitting in Germany, then a good sign that things are working is Google will be in German all of a sudden or if you lookup your IP online, it'll show the IP address of you server:
Google in German

Solving the IP problem when using NGINX to proxy to Apache or Tomcat

NGINX + Apache - Resolving If you ever had to setup NGINX as a forwarding proxy to Apache, you would have noticed that all your IP addresses are being logged as

There's a simple solution for this, either update nginx.conf or your enabled site's config and add the following lines:
proxy_set_header   Host         	$host;
proxy_set_header   X-Real-IP    	$remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

Once you've updated NGINX, a little work is needed on Apache's side as well.
Assuming you're running Debian:

apt-get install libapache2-mod-rpaf
a2enmod rpaf
/etc/init.d/apache2 restart

Now you should be seeing real IP addresses in your logs again.

Hibernate C3P0 Connection Pool

In a Spring project that includes Hibernate, you'll typically see a BasicDataSource being setup in the applicationContext.xml
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">

For testing, this is fine, but this is not ideal for production since it will create a new connection to the database for every query you run.
A better approach is obviously keeping a set number of connections open and reusing them. The performance benefit of a connection pool is huge, especially if the database is sitting on a remote server.

In your pom.xml, add the following dependency:
I see C3P0 has been moved to here.

In your applicationContext.xml, replace the BasicDataSource with the C3P0 Connection Pool:
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" id="dataSource">
    <property name="driverClass" value="${database.driverClassName}" />
    <property name="jdbcUrl" value="${database.url}" />
    <property name="user" value="${database.username}" />
    <property name="password" value="${database.password}" /> 			

    <property name="acquireIncrement" value="1" />
    <property name="acquireRetryDelay" value="200" />
    <property name="acquireRetryAttempts" value="5" />
    <property name="minPoolSize" value="5" />
    <property name="initialPoolSize" value="10" />
    <property name="maxPoolSize" value="15" />
    <property name="maxIdleTime" value="1800" />
    <property name="idleConnectionTestPeriod" value="10" />
    <property name="preferredTestQuery" value="SELECT 1" />
    <property name="checkoutTimeout" value="40" />
That's it, you now have a connection pool that will automatically reconnect as soon as you kill a connection or retry a query if it failed due to connectivity issues.

Something else you can look at is enabling auto-close sessions in your persistence.xml:
<property name="hibernate.auto_close_sesions" value="true"/>

Connect to a Google Compute Engine instance using SSH

Usually when connecting to a Google Compute Engine instance, you'd copy-paste the gcutil string that you get from your GCE console:

gcutil --service_version="v1" --project="xyz-project" ssh --zone="europe-west1-b" "gitson"

How do you SSH to that instance without having to use gcutil?

Assuming you're using some sort of Unix, in your home directory, there's a directory called .ssh.
Create a new file called config and add the following:

Host gitson
    HostName [Instance public IP goes here]
    Port 22
    User [Your username]
    UserKnownHostsFile /dev/null
    CheckHostIP no
    StrictHostKeyChecking no
    IdentityFile ~/.ssh/google_compute_engine

Now you can SSH to your instance using a one-liner:

ssh gitson