Showing posts with label History. Show all posts
Showing posts with label History. Show all posts

Monday, May 2, 2011

history, separate rails/console history, syntax highliting, ...

# .irbrc - last change: 2008-01-22 (ab)

### rubygems
require 'rubygems' rescue nil

### pretty print
require 'pp'

### less verbose prompt

#IRB.conf[:PROMPT_MODE] = :SIMPLE

IRB.conf[:PROMPT][:SHORT] = {
  :PROMPT_C => "%03n:%i* ",
  :RETURN   => "%s\n",
  :PROMPT_I => "%03n:%i> ",
  :PROMPT_N => "%03n:%i ",
  :PROMPT_S => "%03n:%i%l "
}
#IRB.conf[:PROMPT_MODE] = :SHORT

### automatic indentation
IRB.conf[:AUTO_INDENT] = true

### tab completion
require 'irb/completion'
IRB.conf[:USE_READLINE] = true

### preserve history
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:EVAL_HISTORY] = 100

### syntax highlighting
require 'wirble'
Wirble.init(:skip_prompt => true, :skip_history => true)
Wirble.colorize

### irb session duration
require 'duration'
IRB_START_TIME = Time.now
at_exit { puts "\nirb session duration: #{Duration.new(Time.now - IRB_START_TIME)}" }

### aliases
alias r require

### easy YAML
def y(*data); require 'yaml'; puts YAML::dump(*data); end

### Object#tap
class Object; def tap; yield self; self; end; end

### map by method
# http://drnicwilliams.com/2006/10/04/i-love-map-by-pluralisation/
require 'map_by_method'

### method finder, e.g. "foo".what?
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32844
# http://www.nobugs.org/developer/ruby/method_finder.html
# http://redhanded.hobix.com/inspect/stickItInYourIrbrcMethodfinder.html
require 'what_methods'

### gaining temporary access to private methods
# http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
class Class
  def publicize_methods
    saved_private_instance_methods = self.private_instance_methods
    self.class_eval { public *saved_private_instance_methods }
    yield
    self.class_eval { private *saved_private_instance_methods }
  end
end

### System-wide script/console logging
# http://toolmantim.com/article/2007/2/6/system_wide_script_console_logging
script_console_running = ENV.include?('RAILS_ENV') && IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers')
rails_running = ENV.include?('RAILS_ENV') && !(IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers'))
irb_standalone_running = !script_console_running && !rails_running

if script_console_running
  require 'logger'
  Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
end

### different history file for rails
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history_rails" unless irb_standalone_running
http://dotfiles.org/~localhost/.irbrc

Thursday, January 29, 2009

Ajax.History

Ajax.History provided features

Three parameters are provided by Ajax.History allowing you to configure the browsing history manager.
A callback has also been introduced: onStateChange(string state).
This callback is launched when the state of the browsing history points to the request.
This allows for example to change the title of the page according to the state (see example below).

Ajax.History.Request

Ajax.History.Request used exactly as Ajax.Request of Prototype.
For an interactive example, we create a simple function:
function ajaxHistoryRequest(url, myState)
{
new Ajax.History.Request(url, {
history : {
id : 'example',
state : myState,
cache : true,
onStateChange: function(state) {
// change title
History.setTitle(History.getTitle() + ' - Page Ajax #' + state);
}
},
onSuccess: function(transport) {
$('box-example').update(transport.responseText);
// some stuff
}
});
ajaxHistoryRequest('history/request1', 'first-test');
ajaxHistoryRequest('history/request2', 'second-test');
ajaxHistoryRequest('history/request3', 'third-test');
** The cache is enabled, if you use a module as FireBug on Firefox, you can see that the use of buttons back/forward of your browser does not reload the Ajax.Request.

Ajax.History.Updater

Ajax.History.Updater used exactly as Ajax.History.Request :
Automatic historyId :
Here, the historyId is not declared, the 'containerName' is used automatically.
new Ajax.History.Updater('containerName', 'my/url/to/load.html', {
history : {
cache : true
}
});

// location.href == '...#containerName={state}'
Disable historyCache :
The cache is disabled, so, when user perform back/forward of browser, the Ajax Request will be loaded whenever.
new Ajax.History.Updater('containerName', 'my/url/to/load.html', {
history : {
id : 'my-own-identifier',
cache : false
}
});

// location.href == '...#my-own-identifier={state}'
Ajax.Cache

How does the cache?
Ajax.Cache can "simulate" an Ajax Request from an Ajax Request made beforehand. It takes only one argument: the object Ajax.Request / Updater create first.
In fact, Ajax.Cache is based on a modified prototype Ajax.Request API. Yes, to simulate the request, I remove the mechanism (real) sending the HTTP request.
Perform simulation manually :
Ajax.Cache is already implemented in Ajax.History.* classes. However, you can use it manually :
// the request is executed firstly
var request = new Ajax.Request('my/url/to/load.html', {
method: 'POST',
...
});

// reproduced the Ajax.Request without HTTP request
new Ajax.Cache(request);
http://www.prototypextensions.com/history

Tuesday, January 27, 2009

History Manager for AJAX. Fix the back button on AJAX

One of the major issues on AJAX web applications is the accesibility and usability lacks. Many users have manies and don¡t undestands about AJAX, they only expects that if they click the back button then it must works as always and get them back to the previous screen.

Digitarald.de have developed a solution HistoryManager - The Ajax Back-Button (v1.0) for Mootools developers.

Download prototype.historyManager.js

http://www.flash-free.org/en/2008/07/05/history-manager-para-ajax-solucion-al-boton-back