Ciekawe narzędzia

showoff - https://showoff.io/

[quote]> show 3000

share this URL:
https://you.showoff.io[/quote]

pru - https://github.com/grosser/pru

[quote]# grep — all lines including foo
ls -al | grep foo
ls -al | pru /foo/

grep — all lines including current date

ls -al | ???
ls -al | pru ‘include?(Time.now.strftime("%Y-%m-%d"))’

grep — all lines including foo but not self

ps -ef | grep foo | grep -v grep
ps -ef | pru ‘include?(“foo”) and not include?(“pru”)’

awk — return second item

ls -al | awk ‘{print $2}’
ls -al | pru ‘split(" ")[1]’

awk — count and average of all integers on second position

ls -al | awk ‘{ s += $2; } END {print “average” ,int(s/NR);print "count ",int(NR)}’
ls -al | pru ‘split(" ")[1]’ ‘“average #{mean(&:to_i)}\ncount #{size}”’

every second line

ls -al | pru ‘i % 2 == 0’[/quote]

Nie można nieznać awk | sed | grep | uniqe | sort | other ad-hoc tool PRU to ciekawostka, ale w sumie, po co ?

ls -al | awk '{ s += $2; } END {print "average" ,int(s/NR);print "count ",int(NR)}' ls -al | pru 'split(" ")[1]' '"average #{mean(&:to_i)}\ncount #{size}"'
Czy jest lepiej ? Przupuszczam że wątpie. Wydajność IO też pewnie leży i kwiczy na sporych źródłach danych :wink:

Osobiście większy sens widze w używaniu HSH i haskell’a https://github.com/jgoerzen/hsh/wiki/Examples

pry - https://github.com/banister/pry

[quote]Pry is a powerful alternative to the standard IRB shell for Ruby. It is written from scratch to provide a number of advanced features, some of these include:

Source code browsing (including core C source with the pry-doc gem)
Documentation browsing
Live help system
Syntax highlighting
Command shell integration (start editors, run git, and rake from within Pry)
Gist integration
Navigation around state (cd, ls and friends)
Runtime invocation (use Pry as a developer console or debugger)
Exotic object support (BasicObject instances, IClasses, ...)
A Powerful and flexible command system
Ability to view and replay history
Many convenience commands inspired by IPython and other advanced REPLs[/quote]

pry(main)> class Hello pry(main)* @x = 20 pry(main)* end => 20 pry(main)> cd Hello pry(Hello):1> ls -i => [:@x] pry(Hello):1> cd @x pry(20:2)> self + 10 => 30 pry(20:2)> cd .. pry(Hello):1> cd .. pry(main)> cd ..

[code]pry(main)> cd Gem
pry(Gem):1> show-doc try_activate

From: /Users/john/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb @ line 201:
Number of lines: 3

Try to activate a gem containing path. Returns true if
activation succeeded or wasn’t needed because it was already
activated. Returns false if it can’t find the path in a gem.
pry(Gem):1>[/code]

[code]pry(main)> show-method Array#select

From: array.c in Ruby Core (C Method):
Number of lines: 15

static VALUE
rb_ary_select(VALUE ary)
{
VALUE result;
long i;

RETURN_ENUMERATOR(ary, 0, 0);
result = rb_ary_new2(RARRAY_LEN(ary));
for (i = 0; i < RARRAY_LEN(ary); i++) {
if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
    rb_ary_push(result, rb_ary_elt(ary, i));
}
}
return result;

}[/code]
I najlepsze (koniec debugu putsami i inspectami w kodzie) :D:

code:

[code]# test.rb
require ‘pry’

class A
def hello() puts “hello world!” end
end

a = A.new

start a REPL session

binding.pry

program resumes here (after pry session)

puts “program resumes here.”[/code]
Pry session:

[code]pry(main)> a.hello
hello world!
=> nil
pry(main)> def a.goodbye
pry(main)* puts “goodbye cruel world!”
pry(main)* end
=> nil
pry(main)> a.goodbye
goodbye cruel world!
=> nil
pry(main)> exit

program resumes here.[/code]
EDIT: I kolejna alternatywa (chyba nawet ciekawsza: https://github.com/cldwalker/ripl)

Mnie się tam ten pry całkiem podoba. Wydaje się, że może nawet coś jeszcze fajniejszego mogło powstać jakby autorzy się dogadali i stworzyli jedno narzędzie lepsze od irb o budowie modułowej i wielu ficzerach.

AWK =~ RUBY

http://tomayko.com/writings/awkward-ruby :wink:

Żegnaj rails console… Witaj pry!

http://railscasts.com/episodes/280-pry-with-rails

POTĘGA