July 10, 2008

log_buddy and Windows

I recently started playing around with the log_buddy gem for Rails and because my development machine is on windows, the “d” method wasn’t playing nice with some paths.  it didn’t like paths that included the drive letter.

this is a sample of a line that would cause log_buddy to barf.  it just so happens to also be the line that causes the error.  :)

c:/ruby/lib/ruby/gems/1.8/gems/log_buddy-0.0.5/lib/log_buddy.rb:98:in `read_line'

the original line looked like this…

file, line_number = frame.split(/:/, 2)

the fix is to replace that line with

file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&:reverse).reverse

yeah.  ugly, and maybe could be written better but it works for me.

now if only I could get log_buddy to output good inspections of objects I toss to it… like “current_user”.  I’m prolly using it wrong right now, but this isn’t helpful…

current_user = '#<User:0x47143d8>'

just saying.  :)

UPDATE: I monkeypatched log_buddy to fix this functionality. I created a “RAILS_ROOT/lib/log_buddy_extensions.rb” file with the following code.

class LogBuddy

  private

  # Return the calling line
  def self.read_line(frame)
    file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&:reverse).reverse
    line_number = line_number.to_i
    lines = File.readlines(file)
    lines[line_number - 1]
  end

end

and I figured out that the “current_user” line above shouldn’t be …

d { current_user }

it should be

d { current_user.inspect }

that outputs what I want …

current_user.inspect = '#<User id: 1, login: "matte", email: "matte@localhost", crypted_password: "...", salt: "...", created_at: "2007-08-30 18:23:32", updated_at: "2008-07-08 18:57:45", remember_token: "...", remember_token_expires_at: "2008-07-22 18:57:45", name: "...", password_reset_code: nil, company_id: 2, active: true>'

May 13, 2008

XSendFile note

I coulda had a V8Note to everyone using Apache and the XSendFile module. If you’ve included the module and are getting 0-byte files, like I was today, make sure you have the following lines in your VirtualHost config

XSendFile on
XSendFileAllowAbove on

The website needs to know you want to use the module. Duh. :)

February 14, 2008

before_create gotcha with BetterNestedSet plugin

I’m using BetterNestedSet at work in my Rails work but I’ve been having trouble understanding why my code was giving me an error of “Impossible move, target node cannot be inside moved tree”.
Read rest of this entry »

April 16, 2007

Restarting mongrel_cluster with capistrano

Update 4/17: Bradley, the author of mongrel_cluster, was already aware of this issue and is getting ready to release a new version with some fixes for this issue. Best practice for now is to update your config files to place the pid files in /var/run/mongrel_cluster. He mentioned it way back on February 23rd. I shoulda read closer.

If you’ve been experiencing problems with restarting your mongrel cluster through Capistrano then I have two solutions that have worked for me and I’m pretty sure will for you as well. Read rest of this entry »

May 5, 2005

Sparkline PHP Graphing Library

Hmmm. New toy/concept. How can I make use of this?

Sparkline PHP Graphing Library

April 13, 2005

Google Ride Finder

Continued Google inventiveness. The maps technology was just the start. Truly incredible.

Google Ride Finder

March 25, 2005

if a website falls in a forest…

… where is a mouse when it spins.

:: texone.org :: code :: tree ::

January 20, 2005

Ta-da List: Simple sharable to-do lists.

This is a great new free service from a company I use for web-based project management.

Ta-da List: Simple sharable to-do lists

or try it’s big brother…

Basecamp

October 9, 2004

PEAR HTML_QuickForm and file upload rules

NOTE: This has been fixed in HTML_QuickForm version 3.2.4.

If you are working with the PHP PEAR package HTML_QuickForm and file uploads and you are registering rules for both “maxfilesize” and “uploadedfile” then you might be puzzled by some errors you might receive like I was. Let me see if I can explain this plainly.

An important component is your php.ini setting for “upload_max_filesize”. If this is smaller than your setting for “maxfilesize” then if you upload a file that is larger than the “upload_max_filesize” you will NEVER encounter the “maxfilesize” error you set for QuickForm. You will instead receive the “uploadedfile” error because, I’m guessing here, PHP is discarding the file that is too large and therefore QuickForm thinks there isn’t a file. I’ve put together this little example to explain.

Uploaded filesize upload_max_filesize = 20MB / QF Rule maxfilesize = 10MB upload_max_filesize = 10MB / QF Rule maxfilesize = 20MB
5 MB success success
15 MB

Error: maxfilesize

Reason: filesize larger than maxfilesize but less than upload_max_filesize

Error: uploadedfile

Reason: filesize larger than upload_max_filesize

25 MB

Error: uploadedfile

Reason: filesize larger than upload_max_filesize

Error: uploadedfile

Reason: filesize larger than upload_max_filesize

What was puzzling me was when I uploaded a file larger than PHP would let me, I thought I’d get the maxfilesize error but instead I kept getting the uploadedfile error. And the uploadedfile error only returns what you tell it to return so I was telling myself what I was telling the form.

I think QuickForm should be smart enough about the maxfilesize to indicate when a programmer has specified a larger maxfilesize than PHP will allow but I’m not quite sure how that should be done. Should the form automatically adjust itself to the php.ini setting or throw a PHP error? Personally, I’d rather QF automatically adjust itself. We’ll see what the package owners think.

September 27, 2004

The Definitive Post on Gzipping your CSS

Another SAMF. Must read and implement on my new servers.

The Definitive Post on Gzipping your CSS

« Older Entries