<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: console code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Oct 2008 13:08:06 GMT</pubDate>
    <description>DZone Snippets: console code</description>
    <item>
      <title>Generate a list of Rails controllers and methods</title>
      <link>http://snippets.dzone.com/posts/show/4792</link>
      <description>This code goes over the App/controllers directory and extracts a list&lt;br /&gt;of all controllers and their methods. &lt;br /&gt;&lt;br /&gt;use this script from rails console. &lt;br /&gt;&lt;br /&gt;I have used this script to generate a migration file with default authorization roles &amp; rights.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries&lt;br /&gt;controllers.each do |controller|&lt;br /&gt; if controller =~ /_controller/ &lt;br /&gt;  cont = controller.camelize.gsub(".rb","")&lt;br /&gt;  puts cont&lt;br /&gt;  (eval("#{cont}.new.methods") - &lt;br /&gt;    ApplicationController.methods - &lt;br /&gt;    Object.methods -  &lt;br /&gt;    ApplicationController.new.methods).sort.each {|met| &lt;br /&gt;       puts "\t#{met}"&lt;br /&gt;    }&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;to use it to create a Right object I used the following adjustments:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;controllers.each do |controller|&lt;br /&gt;    if controller =~ /_controller/ &lt;br /&gt;    name = controller.camelize.gsub(".rb","")&lt;br /&gt;     (eval("#{name}.new.methods") - &lt;br /&gt;       Object.methods -  &lt;br /&gt;       ApplicationController.new.methods).sort.each {|met| &lt;br /&gt;          name_short = name.gsub("Controller","").downcase&lt;br /&gt;          #it is possible to call the create directly from this script&lt;br /&gt;          #I wanted to review and revise the names. &lt;br /&gt;          puts "#{met}_#{name_short}=Right.create(:name=&gt;\"#{met} #{name_short}\",&lt;br /&gt;                                                  :controller=&gt;\"#{name_short}\",&lt;br /&gt;                                                  :action=&gt;\"#{met}\")"}&lt;br /&gt;  end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 17 Nov 2007 22:16:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4792</guid>
      <author>rubp (john)</author>
    </item>
    <item>
      <title>Add rails log to console</title>
      <link>http://snippets.dzone.com/posts/show/4371</link>
      <description>In order to show rails log in console, add theses lines to your .irbrc&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if ENV.include?('RAILS_ENV')&amp;&amp; !Object.const_defined?('RAILS_DEFAULT_LOGGER')&lt;br /&gt;  Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(SDTOUT))&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 31 Jul 2007 11:16:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4371</guid>
      <author>Mickael (Mickael)</author>
    </item>
    <item>
      <title>Create new repository with svnadmin</title>
      <link>http://snippets.dzone.com/posts/show/3590</link>
      <description>&lt;code&gt;&lt;br /&gt;svnadmin create REPOS_PATH&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 27 Feb 2007 08:27:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3590</guid>
      <author>dirtyaffairs (Dirty Affairs)</author>
    </item>
    <item>
      <title>Python - getchar()</title>
      <link>http://snippets.dzone.com/posts/show/3084</link>
      <description>&lt;code&gt;&lt;br /&gt;import os,sys&lt;br /&gt;import sys&lt;br /&gt;import termios&lt;br /&gt;&lt;br /&gt;def getchar():&lt;br /&gt;	'''&lt;br /&gt;	Equivale al comando getchar() di C&lt;br /&gt;	'''&lt;br /&gt;&lt;br /&gt;	fd = sys.stdin.fileno()&lt;br /&gt;	&lt;br /&gt;	if os.isatty(fd):&lt;br /&gt;		&lt;br /&gt;		old = termios.tcgetattr(fd)&lt;br /&gt;		new = termios.tcgetattr(fd)&lt;br /&gt;		new[3] = new[3] &amp; ~termios.ICANON &amp; ~termios.ECHO&lt;br /&gt;		new[6] [termios.VMIN] = 1&lt;br /&gt;		new[6] [termios.VTIME] = 0&lt;br /&gt;		&lt;br /&gt;		try:&lt;br /&gt;			termios.tcsetattr(fd, termios.TCSANOW, new)&lt;br /&gt;			termios.tcsendbreak(fd,0)&lt;br /&gt;			ch = os.read(fd,7)&lt;br /&gt;&lt;br /&gt;		finally:&lt;br /&gt;			termios.tcsetattr(fd, termios.TCSAFLUSH, old)&lt;br /&gt;	else:&lt;br /&gt;		ch = os.read(fd,7)&lt;br /&gt;	&lt;br /&gt;	return(ch)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 05 Dec 2006 16:16:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3084</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Linux - Escape Terminal</title>
      <link>http://snippets.dzone.com/posts/show/3073</link>
      <description>// Scrive sottolineato&lt;br /&gt;&lt;code&gt;&lt;br /&gt;echo -e "\033[4m\017Prova"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// Scrive in Blink&lt;br /&gt;&lt;code&gt;&lt;br /&gt;echo -e "\033[5m\017Prova"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 03 Dec 2006 23:32:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3073</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Console keyboard scheme switcher</title>
      <link>http://snippets.dzone.com/posts/show/1901</link>
      <description>Switches between us and swedish (or any other)&lt;br /&gt;keyboard-scheme in the console. Default is US.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# Keyboard switcher script&lt;br /&gt;# Written in 2006 by Davor Babic &lt;davorb@gmail.com&gt;&lt;br /&gt;# This software is realeased into public domain&lt;br /&gt;&lt;br /&gt;case $1 in&lt;br /&gt;sv)&lt;br /&gt;    echo "Switching to swedish keyboard layout."&lt;br /&gt;    loadkeys /usr/share/keymaps/i386/qwerty/se-latin1.kmap.gz&lt;br /&gt;    ;;&lt;br /&gt;us)&lt;br /&gt;    echo "Switching to US keyboard layout."&lt;br /&gt;    loadkeys /usr/share/keymaps/i386/qwerty/us.kmap.gz&lt;br /&gt;    ;;&lt;br /&gt;default)&lt;br /&gt;    echo "None selected. Loading US..."&lt;br /&gt;    loadkeys /usr/share/keymaps/i386/qwerty/us.kmap.gz&lt;br /&gt;    ;;&lt;br /&gt;esac&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Apr 2006 04:20:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1901</guid>
      <author>davor (Davor Babic)</author>
    </item>
    <item>
      <title>Console scheme snippet</title>
      <link>http://snippets.dzone.com/posts/show/1200</link>
      <description>&lt;code&gt;&lt;br /&gt;c: open/no-wait [scheme: 'console]&lt;br /&gt;forever [&lt;br /&gt;    wait [c]&lt;br /&gt;    print copy c&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;c: open/no-wait [scheme: 'console]&lt;br /&gt;forever [&lt;br /&gt;    wait [c]&lt;br /&gt;    print mold ch: copy c&lt;br /&gt;    insert c #"^M"&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;c: open/binary/no-wait [scheme: 'console]&lt;br /&gt;forever [&lt;br /&gt;    if not none? wait/all [c] [&lt;br /&gt;        print to-char copy to-integer c&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jan 2006 03:16:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1200</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>readable object output in Rails breakpointer</title>
      <link>http://snippets.dzone.com/posts/show/964</link>
      <description>breakpointer/console shows straight variable output as one long munge.  Console can simply run .to_yaml to organize, breakpointer requires:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt; client.puts @object.to_yaml&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 12 Dec 2005 06:46:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/964</guid>
      <author>jeffmcdonald (Jeff McDonald)</author>
    </item>
    <item>
      <title>script/console reload models</title>
      <link>http://snippets.dzone.com/posts/show/803</link>
      <description>&lt;code&gt;&lt;br /&gt;$ ./script.console&lt;br /&gt;Loading development environment...&lt;br /&gt;&gt;&gt; [do stuff / modify models]&lt;br /&gt;&gt;&gt; Dispatcher.reset_application!&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Picked this up from...&lt;br /&gt;&lt;br /&gt;http://habtm.com/articles/2005/10/04/script-console-reload-models&lt;br /&gt;&lt;br /&gt;... which would have been fine but the site is completely unusable, opting for cool drag-and-drop over the ability to copy and paste. Bad.</description>
      <pubDate>Wed, 12 Oct 2005 01:48:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/803</guid>
      <author>rtomayko (Ryan Tomayko)</author>
    </item>
  </channel>
</rss>
