Wednesday 20 June 2012

Running Pow with Apache


If you want to run pow alongside the MacOS X built-in apache this page will instruct you on how to setup pow so that it doesn't takeover port 80 and instead apache will reverse proxy requests to pow.

For the Impatient

$ curl get.pow.cx/uninstall.sh | sh #if you have pow installed
$ echo 'export POW_DST_PORT=88' >> ~/.powconfig
$ sudo curl https://raw.github.com/gist/1058580/zzz_pow.conf -o /private/etc/apache2/other/zzz_pow.conf
$ sudo apachectl restart
$ curl get.pow.cx | sh

Full Installation Instructions

1. Before installing

Before you install pow, add the following line to your ~/.powconfig
export POW_DST_PORT=88
Here it is as a one-liner
$ echo 'export POW_DST_PORT=88' >> ~/.powconfig
This will cause pow's firewall run to redirect all traffic from port 88 instead of port 80. You can pick any port you like for this if you use 88 for something else. It doesn't affect the remainder of these instructions. If you have already installed pow, you will need to uninstall it before you you continue.

2. Install pow as normal

If you need those instructions, you can find them here: Installation

3. Configure Apache

You'll need to drop the file in this gist into
/etc/apache2/other/zzz_pow.conf
Here it is as a one-liner
$ sudo curl https://raw.github.com/gist/1058580/zzz_pow.conf -o /etc/apache2/other/zzz_pow.conf
This sets up apache to act as a reverse proxy to pow. It goes directly at pow's default listen port, not the firewall port we configured in the previous step. The file name zzz_pow.conf to ensure that apache picks up the vhost for pow last, allowing you to put vhosts for other apps in front of it.

4. Start/Restart Apache

You'll need to turn on "Websharing Sharing" in the MacOS X system preferences if you haven't already. You can find it in System Preferences -> Sharing -> Web Sharing. NOTE: This will make it so anyone with your machines IP Address can access your apache server. This is the default setting from apple. If you want to change this, you will want to change the IP address that apache binds to in /etc/apache2/httpd.conf.
If Apache is already running, you can restart by either turning Web Sharing off and then back on, or you use this on the command line
$ sudo apachectl restart

After Installation

Leveraging pow's DNS for other apps

If you now configure your vhosts for the apps you want to run in apache with *.dev hostnames, pow will provide the DNS resolution for you, which means you get to keep the benefit of not mucking with your hosts file. For example, if you have a php app, you can setup its vhost entry to use my_php_app.dev and you don't need to add that to your hosts file.

 https://github.com/37signals/pow/wiki/Running-Pow-with-Apache

Wednesday 13 June 2012

rake


namespace :pick do
  desc "Pick a random user as the winner"
  task :winner => :environment do
    puts "Winner: #{pick(User).name}"
  end

  desc "Pick a random product as the prize"
  task :prize => :environment do
    puts "Prize: #{pick(Product).name}"
  end
  
  desc "Pick a random prize and winner"
  task :all => [:prize, :winner]
  
  def pick(model_class)
    model_class.find(:first, :order => 'RAND()')
  end
end




In lib/task/something.rake

terminal:

rake pick:winner
rake pick:prize

rake -T

selectorgadget.com/

Drag this link to your bookmark bar: SelectorGadget (updated March 10, 09)

Monday 4 June 2012

render javascript in rails (text format)


headers["Content-Type"] = "text/javascript"
  render(:partial => "get_bookmark_script")