Latest Blog Activity From The Decider

The Decider said over 3 years ago permalink Comment? (0)
Tagged: ruby logic

De Morgan, Ruby

#De Morgan the Ruby way

[true,false].each do |p|
  [true,false].each do |q|
    puts "p=#{p} q=#{q}"
    if !(p or q) == (!p and !q)
      puts "De Morgan Rules! !(p or q) == (!p and !q)"
    else
      puts "De Morgan is a Liar!"
    end

    # if find yourself writing
    if !p and !q
      print "-"
      # you could be writing 
      unless p or q
        puts "if !p and !q equivalent to unless p or q"
      end
    end


    if !(p and q) == (!p or !q)
      puts "De Morgan Rules! !(p and q) == (!p or !q)"
    else
      puts "De Morgan is a Liar!"
    end

    # if find yourself writing
    if !p or !q
      print "-"
      # you could be writing 
      unless p and q
        puts "if !p or !q equivalent to unless p and q"
      end
    end

  end
end

The Decider said over 3 years ago permalink Comment? (0)
Tagged: testing shoulda

Run individual shoulda tests

When you run tests of just one model or controller you usually do something like:

ruby test/unit/evaluation_test.rb

If you want to target just one test you can use the -n option

ruby test/unit/evaluation_test.rb -n test_return_pending_evaluatees_from_composite_group

For shoulda users if you want to target just one test the -n option can also take regular expressions.

ruby test/unit/evaluation_test.rb -v -n "/have many/"

The -v lists the test name before every test, aka verbose mode.

The Decider said over 3 years ago permalink Comment? (0)
Tagged: spam site

Please Spam This Post

Just updated the code to detect the spamming bastards. Let’s see if it works.

The Decider said over 4 years ago permalink Comment? (0)
Tagged: ruby rails bdoc hanna

Pretty Local Rdoc

From the RubyInside site a couple of gems to make your local rdocs look and behave nicer.

activerecord-2.3.2 - Bdoc_1239019365281

To reap the benefits:

sudo gem install mislav-hanna sudo gem install manalang-bdoc sudo hanna —gems bdoc

The Decider said over 4 years ago permalink Comment? (0)
Tagged: rails mongrel ruby nginx

Protect Staging Server with Password

When developing a new application and releasing often you may want to protect the site from prying eyes. A simple way to do this when using the nginx web server is to use basic http authentication.

I prefer to do this in the nginx config file so it doesn’t impact local development.

You’ll need to create a password file using htpasswd command line utility. This file should be relative to the install directory of nginx. The default install would place this file in /usr/local/nginx

sudo htpasswd -cb /usr/local/this_hosts_password_file username password

Next, you need to tell nginx to use basic auth for any access to this (virtual) host. I place the 2 relevant lines in the server portion of the config file

server { listen 80;

  1. auth_basic “Login to see this alpha site.”;
    auth_basic_user_file this_hosts_password_file;

  2. }

A login will now be presented for any entry into the site.