Roger's woze

March 30, 2010

ruby regex woe

Filed under: Uncategorized — rogerdpack @ 10:54 pm

irb(main):006:0> /(?:—|+++) (.*)/
SyntaxError: (irb):6: target of repeat operator is not specified: /(?:—|+++) (.*)/
from C:/Ruby19/bin/irb:12:in `

meant “you need to escape your plusses”

irb(main):007:0> /(?:—|\+\+\+) (.*)/
=> /(?:—|\+\+\+) (.*)/

ruby File.grep

Filed under: Uncategorized — rogerdpack @ 5:33 pm

ri doesn’t parse this well…appears it’s *actually* enumerable#grep.


C:\dev\ruby\ruby_core_ri>irb
irb(main):001:0> require 'ri_for'
=> true
irb(main):002:0> File.open("asdf", 'w')
=> #
irb(main):003:0> a = _
=> #
irb(main):004:0> a.ri_for :grep
sig: Enumerable#grep arity 1
appears to be a c method
Searching ri for
sig: Enumerable#grep arity 1
...
-------------------------------------------------------- Enumerable#grep
enum.grep(pattern) => array
enum.grep(pattern) {| obj | block } => array

From gem ruby_core_ri-0.5.1
------------------------------------------------------------------------
Returns an array of every element in _enum_ for which +Pattern ===
element+. If the optional _block_ is supplied, each matching
element is passed to it, and the block's result is stored in the
output array.

(1..100).grep 38..44 #=> [38, 39, 40, 41, 42, 43, 44]
c = IO.constants
c.grep(/SEEK/) #=> [:SEEK_SET, :SEEK_CUR, :SEEK_END]
res = c.grep(/SEEK/) {|v| IO.const_get(v) }
res #=> [0, 1, 2]

(end ri)
=> "#"

March 29, 2010

rdoc windows woe:

Filed under: Uncategorized — rogerdpack @ 11:00 pm

Generating RI…
uh-oh! RDoc had a problem:
No such file or directory – ./TestSprintf/T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/cdesc-T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.ri

run with –debug for full backtrace

C:\Ruby19\lib\ruby\gems\1.9.1\gems\ruby_core_ri-0.4.0\lib\downloaded_full_source>find | grep T0123456789012345

C:\Ruby19\lib\ruby\gems\1.9.1\gems\ruby_core_ri-0.4.0\lib\downloaded_full_source>rdoc –version
rdoc 2.5.0

C:\Ruby19\lib\ruby\gems\1.9.1\gems\ruby_core_ri-0.4.0\lib\downloaded_full_source>grep T01234567890 * -r
test/ruby/test_sprintf.rb: class T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
test/ruby/test_sprintf.rb: assert(T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.new.inspect =~ /^#$/)

C:\Ruby19\lib\ruby\gems\1.9.1\gems\ruby_core_ri-0.4.0\lib\downloaded_full_source>rm test/ruby/test_sprintf.rb

rdoc woe

Filed under: Uncategorized — rogerdpack @ 10:33 pm

C:\dev\ruby>ri File.grep
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rdoc-2.5.0/lib/rdoc/ri/driver.rb:952:in `trap’: unsupported signal SIGINFO (ArgumentError)
from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rdoc-2.5.0/lib/rdoc/ri/driver.rb:952:in `run’
from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rdoc-2.5.0/lib/rdoc/ri/driver.rb:309:in `run’
from C:/Ruby19/lib/ruby/gems/1.9.1/gems/rdoc-2.5.0/bin/ri:5:in `
from C:/Ruby19/bin/ri:19:in `load’
from C:/Ruby19/bin/ri:19:in `

means “go into that and delete that trap!” [bug in that it's not windows compatible...]

ruby scan and replace in a file(File.grep)

Filed under: Uncategorized — rogerdpack @ 10:07 pm

http://www.3till7.net/2010/02/23/convenient-file-searching-with-ruby-grep-and-file/

ruby hoe woe

Filed under: Uncategorized — rogerdpack @ 9:10 pm

yep

C:\dev\ruby\downloads\rdoc>rake gem
faster_gem_script cacheing bin location (1st time only) C:/Ruby19/bin/rake
(in C:/dev/ruby/downloads/rdoc)
rake aborted!
Don’t know how to build task ‘lib/rdoc/ruby_lex.rb.orig’

ev\ruby\downloads\rdoc>pik 191

C:\dev\ruby\downloads\rdoc>rake gem
(in C:/dev/ruby/downloads/rdoc)
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1731
fail “Don’t know how to build task ‘#{task_name}’”
(rdb:1) task_name
“gem”
(rdb:1) c
rake aborted!
Don’t know how to build task ‘gem’

C:\dev\ruby\downloads\rdoc>rake gem
(in C:/dev/ruby/downloads/rdoc)
mkdir -p pkg
rake aborted!
Don’t know how to build task ‘lib/rdoc/cache.rb’

meant “you have extra files listed in your MANIFEST.txt file for some reason”

rdoc woe

Filed under: Uncategorized — rogerdpack @ 8:19 pm

C:\Users\packrd\AppData\Local\Temp\d20100329-2652-odhke7>rake -T
(in C:/Users/packrd/AppData/Local/Temp/d20100329-2652-odhke7)
rake aborted!
No such file or directory – C:/Users/packrd/.rubyforge/user-config.yml
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile’
(See full trace by running task with –trace)

meant “you need to install the rubyforge gem and run rubyforge setup”

svn clean delete untracked files

Filed under: Uncategorized — rogerdpack @ 6:47 pm

Here’s how
download tortoise
do a “commit” (explorer right click)
highlight all untracked files
hit delete
(it deletes them all).

There’s probably a better way out there…

March 26, 2010

jruby+windows+cucumber+colors?

Filed under: Uncategorized — rogerdpack @ 10:29 pm

They say to use “wac”

http://wiki.github.com/aslakhellesoy/cucumber/console-colours

but that didn’t help me totally…needed the –color option as well as the pipe.

ruby udp socket example

Filed under: Uncategorized — rogerdpack @ 5:38 pm

server.rb (run first, in one window)


require 'socket'
BasicSocket.do_not_reverse_lookup = true
# Create socket and bind to address
client = UDPSocket.new
client.bind('0.0.0.0', 33333)
data, addr = client.recvfrom(1024) # if this number is too low it will drop the larger packets and never give them to you
puts "From addr: '%s', msg: '%s'" % [addr.join(','), data]
client.close

client.rb (run in another window


require 'socket'
sock = UDPSocket.new
data = 'I sent this'
sock.send(data, 0, '127.0.0.1', 33333)
sock.close

related:

http://betterlogic.com/roger/?p=1646

Older Posts »

Powered by WordPress