The blog has moved to http://jessehouse.com/ ... Many google searches point here so I am leaving it operational, but there will be no new posts.

Sunday, August 23, 2009

scrolling screen shot on ubuntu

I've been using ubuntu for the last 6 months, really like it! But also really missing SnagIt :(

so far I have come across these screen shot tools

  • built in 'save screen' program - read this post for info about that and others
  • Shutter

but none that I came across would do scrolling screen shots; currently I only needed scrolling screen shots of web pages and I just came across a great tool for that - a firefox add-on called Abduction, it is really easy to use.

For full page screen shots (including all scrollable regions) or for cropped sections of a page. Just right click on the page and select 'Save Page as Image', if you are over an 'element' it will auto select that as the cropped area, you can then adjust the crop and save, if you want the entire page the easiest seems to be right clicking where there are no elements below the mouse and then adjust the fully selected page as needed

The saved png can then be opened in Shutter for applying arrows, boxes, etc...

Friday, August 21, 2009

Ajax error handling with ruby on rails and jquery

This sample is just a slight modification of this post 'Handling AJAX errors and displaying friendly error messages to users'. Basically I wanted to maintain the existing rails error handling for non-ajax pages and then have good handling for errors in both development and production mode; i.e. get errors in the browser when in development mode and show a nice message when in production mode.

Modify /app/controllers/application.rb; add the rescue_from macro and the handler_exception method


class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
# ...
rescue_from Exception, :with => :handler_exception
# ...
def handler_exception(exception)
if request.xhr? then
message = "Error: #{exception.class.to_s}"
message += " in #{request.parameters['controller'].camelize}Controller" if request.parameters['controller']
message += "##{request.parameters['action']}" if request.parameters['action']
message += "\n#{exception.clean_message}"
message += "\n\nFull Trace:\n#{exception.clean_backtrace.join("\n")}"
message += "\n\nRequest:\n#{params.inspect.gsub(',', ",\n")}"
# log the error
logger.fatal "#{message}"
message = "ajaxError, check the server logs for details" unless local_request?
respond_to do |wants|
wants.js { render :text => message, :status => :internal_server_error }
end
else
# not an ajax request, use the default handling;
# actionpack-2.2.2/lib/action_controller/rescue.rb
rescue_action_without_handler(exception)
end
return # don't risk DoubleRenderError
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Then add a global javascript method for presenting the errors; most likely in application.js

function defaultAjaxErrorHandler(result, isAjaxError) {
// do stuff, hide spinner etc...
var defaultAjaxError = "Your friendly error message";
var errorToken = "Error:";
if(!isUndefinedOrNull(result) && !isUndefinedOrNull(result.responseText)) {
if(result.responseText.startsWith(errorToken)) {
// localhost
var x = (result.responseText.length > 350) ? 350 : result.responseText.length;
alert(result.responseText.substring(0, x) + "...\n\n - Check firebug console for more info.\n - This message for localhost only.");
}
else {
// production error
alert(defaultAjaxError);
}
}
else {
// production error
alert(defaultAjaxError);
}
}
function isUndefinedOrNull(x) {
var u; // undefined var
if(x === u) { // similar to [typeof x == "undefined"]
return true;
}
// else
return x === null;
}
view raw gistfile1.js hosted with ❤ by GitHub

Then a sample usage, jquery making an ajax post to a rails controller action

$j.ajax({
type: "POST",
url: "/some_controller/some_action",
data: {
first_name: $j("#first_name").val(),
last_name: $j("#last_name").val(),
},
success: function(data, textStatus) {
// do what you like
},
error: function(result) { defaultAjaxErrorHandler(result, true); }
});
view raw gistfile1.js hosted with ❤ by GitHub

in development mode the error message is returned in an easier to read view in the firebug console and an alert message is presented that has a truncated version of the error

dev mode

in production mode just a friendly error message.

production mode

Resources

Tuesday, August 4, 2009

Get list of MSSQL jobs that are currently running

The following sql statement will return information about the currently executing MSSQL jobs.
Run it against the msdb database



EXEC dbo.sp_help_job @execution_status = 0;
view raw gistfile1.sql hosted with ❤ by GitHub