Register now and start sharing your code snippets.
-->

Configuring Apache to be a forward proxy

Apache posted 8 days ago by christian

This configuration makes Apache act as an HTTP proxy:

   1  <VirtualHost *:8080>
   2  
   3  	ProxyRequests On
   4  	ProxyVia On
   5  	#ProxyRemote * http://...:8080 Uncomment to route requests through another proxy
   6  
   7  	<Proxy *>
   8  		Order deny,allow
   9  		Deny from all
  10  		Allow from all # Not a good idea, set to allowed IP ranges
  11  	</Proxy> 
  12  	
  13  	CacheRoot "/tmp"
  14  	CacheMaxExpire 24
  15  	CacheLastModifiedFactor 0.1
  16  	CacheDefaultExpire 1
  17  
  18      ServerName my-proxy
  19  
  20      ErrorLog "/var/log/apache2/proxy-error.log"
  21      CustomLog "/var/log/apache2/proxy-access.log" common
  22  </VirtualHost>

Also read this.

Tagged apache, forward, proxy

How to create a separate development profile for Firefox

Shell Script (Bash) posted 15 days ago by christian

Extensions slow down Firefox so I prefer disabling all but the most important Firefox extensions when coding.

Here’s how to do it:

  1. First, create a development profile following these instructions http://support.mozilla.com/en-US/kb/Managing+profiles
  1. Next, create a shortcut that starts Firefox in development mode:

   1  # Mac OSX
   2  /Applications/Firefox.app/Contents/MacOS/firefox-bin -P development -no-remote
   3  
   4  # Linux
   5  /usr/lib/firefox/firefox-bin -P development -no-remote
   6  
   7  # Windblows
   8  "C:\Program Files\Mozilla Firefox\firefox.exe" -P development -no-remote

Tagged firefox, development, profile, mode

How to get monit to start mongrel_rails properly

Shell Script (Bash) posted 16 days ago by christian

Mongrel_rails and monit are not the best of friends. It’s difficult to get them to work together.

For example, this is the error I got in my monit logs when switching to a new mongrel_rails command that cleans up stale pids:

   1  'mongrel_1' process is not running
   2  'mongrel_2' trying to restart
   3  'mongrel_3' start: /usr/local/bin/mongrel_rails
   4  'mongrel_4' failed to start

To fix it I added the following start_command to the monit configuration:

   1  /usr/bin/env PATH=/usr/local/bin/:$PATH mongrel_rails cluster::start -C /var/www.... --clean --only 8000

The problem is that monit overrides the PATH environment variable, so it won’t find mongrel_rails unless you tell it where to find it.
Monit also contains a bug which doesn’t tell you why it can’t start mongrel_rails, but that’s another story…

Note that I’m using the —clean switch which will startup the mongrels even if a stale pid exists.

In fact I got so tired of the whole mess I wrote a plugin that generates a working monit configuration for mongrel_rails from one or more mongrel_cluster.yml configuration files.

Tagged mongrel_rails, monit, process, monitoring

(Re)Creating an auto incremented column using alter table in MySQL

SQL posted 20 days ago by marko

The column must become a key column.

   1  alter table my_table add id int primary key auto_increment;

Tagged mysql

Simple JavaScript countdown timer

JavaScript posted 21 days ago by christian

This JavaScript displays the days, hours, minutes and seconds left to the given date:

   1  function Countdown(then) {
   2  
   3  	this.then = then;
   4  	
   5  	function setElement(id, value) {
   6  		if (value.length < 2) {
   7  	    	value = "0" + value;
   8  		}
   9  	
  10  		window.document.getElementById(id).innerHTML = value;
  11  	}
  12  	
  13  	function countdown() {
  14  		now  		  = new Date();
  15  	  	diff		  = new Date(this.then - now);
  16  	  	
  17  		seconds_left  = Math.floor(diff.valueOf() / 1000);
  18  	
  19  		seconds  = Math.floor(seconds_left / 1) % 60;
  20  		minutes  = Math.floor(seconds_left / 60) % 60;
  21  		hours    = Math.floor(seconds_left / 3600) % 24;
  22  		days     = Math.floor(seconds_left / 86400) % 86400;
  23  		
  24  		setElement('countdown-days', days);
  25  		setElement('countdown-hours', hours);
  26  		setElement('countdown-minutes', minutes);
  27  		setElement('countdown-seconds', seconds);
  28  		
  29  		countdown.timer = setTimeout(countdown, 1000);
  30  	}
  31  	
  32  		
  33  	function start() {
  34  		this.timer = setTimeout(countdown, 1000);
  35  	}
  36  	
  37  	start(then);	
  38  }
  39  
  40  Countdown(new Date("Dec 04 2008 12:00:00"));

Required HTML:

   1  <span id="countdown-days"></span> days
   2  
   3  <span id="countdown-hours"></span>:<span id="countdown-minutes"></span>:<span id="countdown-seconds"></span>

Output is for example:

   1  23 days 23:00:12

Tagged countdown, timer, javascript