Archive for December, 2007

FAQ_U Rails FAQ Generator Plugin

December 20th, 2007 by pyrat

Faq u

For a christmas present I give you the Rails FAQ Generator plugin FAQ_U.

This is a simple layout-less unbranded Frequently Asked Questions system. The idea is you generate the default system and then customise it to the requirements of the particular project that you are working on.

Remember to add some authentication to the faq_admin controller.

Requires HAML. To install it:

gem install --no-ri haml
haml --rails path/to/app

To install the plugin:

./script/plugin install http://vorlich.ath.cx/code/excited/plugins/faq_u

To run the generator:

./script/generate faq

This generates a FAQ admin controller, FAQ view controller, the necessary views, a model, db migration and a collection of
tests.

After the generator is complete run the migration to get the database up to scratch.

rake db:migrate

The faq admin is available at */faq_admin* and the front end at */faq*. As you can see below it looks pretty filthy, but as you can see below that, with the introduction of a layout it looks nicer.

unstyled

styled

A would be nice would be a nice AJAX ordering interface in the faq_admin. Feel free to send me some svn patches of any improvements you make. Please write some tests to prove the new functionality works. Cheers now, Merry Christmas.

Racentries has had a makeover

December 18th, 2007 by pyrat

racentries-logo

I have further developed and refined racentries over the past few weeks. Some of the changes are as follows:

  • Google checkout as the payment gateway – much better to use and more robust that paypal.
  • Emergency contact information captured with entrants.
  • New branding, design fixes and numerous small improvements.

This system now offers a genuinely good service to event organisers and competitors but my problem now is marketing. I need to get people using it and find event organisers that want to use it.

I am going to try investing a little bit of money on online advertising and we will see how it works out.

Watch this space for a follow up on how this goes.

Rupdf - Simple Ruby PDF Rails Plugin

December 15th, 2007 by pyrat

Rupdf

This is a plugin which I have developed internally with Iformis. I realised it would be nice to share yet another pdf plugin with the rails community. This is designed to render pdfs with layouts. This is especially useful when working on projects where the pdf has to conform to a set design and where the data is presented in a generate report style. Banks often operate their tools in this manner.

Simple PDF reporting rails plugin designed to render layout based pdfs. Built on top of Ruport which is in turn built on top of pdf-writer.

Requires Ruport

Step 1: Install Ruport

gem install ruport

Step 2: Install the plugin (from RAILS_ROOT)

./script/plugin install http://iformis.svnrepository.com/svn/rupdf

Step 3: Create a class extending Rupdf::Base

Note: The only methods calls required are define_header, define_body and define_footer
The other methods are helper methods. Remember that html doesnt work in the body.

class Simple < Rupdf::Base
 
  define_variables :report_title
  renders :pdf, :for => Rupdf::Renderer
 
  define_header do
    add_header(report_title)
  end
 
  define_body do
    add_text("hello man\n\n\n")
    add_text("bye man.")
 
    add_text("bye man.")
    add_text("hello man\n\n\n")
    add_text("bye man.")
    add_text("hello man\n\n\n")
    add_text("bye man.")
 
    # add image (path defined at runtime)
    image(smile_path)
 
    add_text("hello man\n\n\n")
    add_text("bye man.")
    add_text("hello man\n\n\n")
 
  end
 
  define_footer do
    footer_text = %(
    This is the beautiful footer text.
    )
    add_footer(footer_text)
  end
 
 
 
  def add_header(title)
    rounded_text_box("<b>#{title}</b>") do |o|
      header_color = Color::RGB.from_html("#FFDE16")
      o.fill_color = header_color
      o.stroke_color = header_color
      o.radius     = 0
      o.width      = options.header_width || 550
      o.height     = options.header_height || 80
      o.font_size  = options.header_font_size || 12
      o.x          = pdf_writer.absolute_right_margin - o.width
      o.y          = pdf_writer.absolute_top_margin
    end
 
 
 
  end
 
  def add_footer(text, options = nil)
 
    unless options
      options = OpenStruct.new(:font_size => 6)
    end
 
    rounded_text_box(text) do |o|
      footer_color = Color::RGB.from_html("#EAECEE")
      o.fill_color = footer_color
      o.stroke_color = footer_color
      o.radius     = 0
      o.width      = options.header_width || 550
      o.height     = options.header_height || 60
      o.font_size  = options.font_size || 12
      o.x          = pdf_writer.absolute_right_margin - o.width
      o.y          = pdf_writer.absolute_bottom_margin + o.height
 
    end
 
  end
 
end

Step 4: Tie it into a controller and pass the variables at runtime.

class TestController < ApplicationController
 
  def pdf
    simple = Simple.new
    pdf = Rupdf::Renderer.render_pdf do |o|
      o.report_title = 'This is a test of a var being passed.'
      o.smile_path = RAILS_ROOT + '/public/images/smile.jpg'
    end
    send_pdf(pdf)
  end
 
end

The send_pdf function sends the rendered pdf to the browser.

If you need to perform more complicated pdf rendering operation
please refer to the API Documentation for pdf-writer. The API docs for
ruport will also be useful if you are involved in presenting tabular
data from activerecord.

Example programming code along with how to call it is supplied in the
examples directory. I suggest you use these as a base for pdf generation code you write.

This has been tested with both Rails 1.2 and Rails 2.01. Thanks for listening.

Prototype Script onbeforeunload when leaving a page

December 14th, 2007 by pyrat

  <script type="text/javascript">
  var FormWatch = Class.create();
  FormWatch.prototype = {
     initialize : function(form, options) {
        this.submitted = false;
        this.form = $(form);
        // Let's serialize this.form and store it...
        this.formcontents = $(form).serialize();
        // Observe beforeunload event...
        Event.observe(this.form, 'submit', function() {this.submitted =
  true; }.bind(this));
        Event.observe(window, 'beforeunload',
  this.confirmExit.bind(this));
     },
     confirmExit : function(ev) {
        this.newcontents = this.form.serialize();
        if ((this.formcontents != this.newcontents) && !
  (this.submitted)) {
           ev.returnValue = "You have unsaved information.";
           //return Event.stop(ev);
        }
     }
  }
 
  </script>
  <script type="text/javascript">
        new FormWatch('property_form');
   </script>

This will shout at you if you leave a form when you have edited it.

Power to the Poachers

December 4th, 2007 by pyrat

Power Poachers

There are only four resorts left which dont allow snowboarding in America. Burton is offering $5000 cash to people or ‘crews’ that can poach these resorts.

Burton Poaching Competition

Already the submitted videos are pretty funny.

Poach Info

Building a Booter

December 3rd, 2007 by pyrat

Kicker top

First thing to do is find the best spot. Ideally this is waaay off-piste where there is virgin snow everywhere. Make sure avalanche risk is low and you are with friends.

The spot where to build it is pretty important, it should be on a flat spot between two steep spots.

Kicker Sweetspot

Now start stacking a lot of snow on the flat spot. It takes some time and a bit of effort. A few bifters, food and some tunes will be great. Use shovels to cut out large blocks of snow as these are great for building with.

Kicker Shovel

Then use the snowboards to pack down the the kicker and smooth out the run in. It important to have a really smooth run in with a long enough wedge on the kicker. The length of the transition should be longer than a board length.

Ideally the landing should be into deep untracked powder, this will allow you to really go off and try out some new tricks which you can blast out onto the hard packed park jumps once you have mastered them.

This landing is a bit sketchy!

Kicker gap

This landing was lush.

Kicker Landing

If you do it right you should have something as follows:

Kicker Fyeah

Send me some photos of kickers you have made in the past!

HTTPS Generating Private Key and CSR For RapidSSL

December 3rd, 2007 by pyrat
  • Generate a private key

openssl genrsa -out domainname.key 1024

  • Generate a certificate signing request

openssl req -new -key domainname.key -out domainname.csr

When it asks for common name enter the fully qualified domain name. eg. www.racentries.com