Configuring Apache to be a forward proxy
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.
How to create a separate development profile for Firefox
Extensions slow down Firefox so I prefer disabling all but the most important Firefox extensions when coding.
Here’s how to do it:
- First, create a development profile following these instructions http://support.mozilla.com/en-US/kb/Managing+profiles
- 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
How to get monit to start mongrel_rails properly
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.
(Re)Creating an auto incremented column using alter table in MySQL
The column must become a key column.
1 alter table my_table add id int primary key auto_increment;
Simple JavaScript countdown timer
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