Showing posts with label Console. Show all posts
Showing posts with label Console. Show all posts

Sunday, June 26, 2011

TermKit

Goal: next gen terminal / command application
Built out of WebKit and Node.js.
Runs as a desktop app on Mac, Windows and Linux, and can be hacked into any WebKit browser (Chrome, Safari).
Follow TermKit on Twitter for the latest news and updates.
For the background and architecture, please read and comment on: http://acko.net/blog/on-termkit
TermKit 0.3 alpha
https://github.com/unconed/TermKit

Tuesday, June 21, 2011

Awesome Print

Awesome Print is Ruby library that pretty prints Ruby objects in full color exposing their internal structure with proper indentation. Rails ActiveRecord objects and usage within Rails templates are supported via included mixins.

https://github.com/michaeldv/awesome_print

Wednesday, May 4, 2011

Ruby on Rails: How to load session objects into console

  1. Look in tmp/sessions and find the most recent file (ls -alrt on UNIX). Let's say the file is called 'tmp/sessions/ruby_sess.8eb9614a7e4e1e3b'
  2. Open console and type:
    >> session = Marshal.load(File.open('tmp/sessions/ruby_sess.8eb9614a7e4e1e3b'))
    => {"hash"=>{:cart=...
    >> cart = session["hash"][:cart]
    ....
    
    In this case I was trying to access a cart object in the session, which was placed in the session with: session[:cart] = Cart.new
That's it

Session stored in the DB:
# Session.find_by_id(:my_session_id)
# CGI::Session::ActiveRecordStore::Session.find_by_session_id(session_id)

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

Tuesday, March 16, 2010

Display ActiveRecord generated SQL queries in the console

If you want the console to display the SQL query that ActiveRecord executes just do the following (before you do anything else in the console):
$ script/console
>> ActiveRecord::Base.logger = Logger.new(STDOUT)
=> #
>> User.first
User Load (3.3ms) SELECT * FROM "users" ORDER BY last_name, first_name ASC LIMIT 1
Each call to ActiveRecord now logs all of its activity to STDOUT (e.g., the console), via your custom logger instance.

Thursday, February 12, 2009

ruby script/console --sandbox

Loading development environment in sandbox (Rails 2.2.2)
Any modifications you make will be rolled back on exit