ruby

Is there something like Ruby's Treetop for PHP?

Hi, as I wrote a small PHP framework with a DSL parser, and I'm not satisfied with the result, is there any tool like Treetop for PHP? It would lead to far better (and nicer) results. ...

Mysql / Ruby Sequel last insert ID value, what method?

I just want to get the last_insert_id() using Ruby's Sequel: insertret = @con.run("INSERT INTO `wv_persons` ( `id` ) VALUES ( NULL )") pp insertret.inspect # returns "nil", expected that.. last_insert_id = @con.run("SELECT LAST_INSERT_ID() AS last_id;") pp last_insert_id.inspect # returns "nil", should be an ID The SELECT query should ...

insert and update in single statement

INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE a='4', b='5', c='6' how to implement this type(insert and update) of sql in rails in single statement if possible ...

loops within ruby

Doing a very simple loop to display various data, for _test in @test ... I want to be able to, 1) get the first value _test.name.first()??? 2) get the previous value(meaning, the last iteration, so I i iterated the first time, I want to grab it again, when its in the second loop Thank you --- update What I mean is this Doug, 2. ...

Ruby/Rails: difference between "@item" and "item" in a view

I have a view which might be rendered from a controller or as a partial from another view. In all the code I've read, the controllers assign an instance variable "@item" and then call the view. On the other hand, when rendering it as a partial, it receives a parameter "item". So, all of my views start up this way: item ||= @item Ver...

Problem with quantifiers and look-behind

### Ruby 1.8.7 ### require 'rubygems' require 'oniguruma' # for look-behind Oniguruma::ORegexp.new('h(?=\w*)') # => /h(?=\w*)/ Oniguruma::ORegexp.new('(?<=\w*)o') # => ArgumentError: Oniguruma Error: invalid pattern in look-behind Oniguruma::ORegexp.new('(?<=\w)o') # => /(?<=\w)o/ ### Ruby 1.9.2 rc-2 ### "hello".match(/h(?=\w*)/) ...

Ruby Complex Event Processing

Is there an open-source complex event processing (CEP) engine for ruby? I'm looking specifically for something that offers stateful analysis, not just rules-engine-style antecedent-predicate productions. ...

Ruby on Rails: What to do when two models share a lot of similar validations/validation_methods

I have a couple of models that are both "password" centric models. They don't belong in a single inheritance table and need to be tracked in separate tables. Logically they are both completely different types of models, but both have password and password confirmation tracking. They also use the same business logic for the password rules...

diffrence between mongrel and mongrel cluster ?

can Anybody brief expain to diffrence between mongrel and mongrel cluster ? ...

RoR: Custom update for record

questions --------- id topic_id created_by created_at question_text closed_by closed_at response_text It appears in a nested table under the topics table. I can easily create a question, I just have to exclude :created_by, created_at, closed_by, closed_at, response_text from config.create.columns. (created_at and created_by is filled ...

Ruby + JSON + Regexp

I'm working on a RoR project and I am passing a JSON object to a script. Specifically, a list of events to a jquery calendar. First I get the necessary events from active record and convert them to json: @events = CalendarEvent.find(:all, :conditions => ["mentor_id = ?", current_user]).to_json(:only => [:id, :availability, :starts_at,...

Router backup script

I have the following code that connects to my router just fine. The problem is that once connected, I try to pass the "sh ver" command that never gets passed to the router. Thanks for your help! require 'net/telnet' cisco = '1.1.1.1' #Enter the IP address here user = 'admin' #Enter username here pass = 'mypass' #Enter password here tn...

Recursive to_json in Ruby

I have a simple class that overrides to_json to list the attributes in an array - class MyClass def initialize(a, b) @a = a @b = b end def to_json(*opt) [@a, @b].to_json(*opt) end end to_json works fine for an instance of the class - irb> m = MyClass.new(10, "abc") irb> m.to_json => "[10,\"abc\"]" But if I put ...

Watir magic escape sequence?

I am currently using Watir with Firefox and it seems that when I try to set a field with the following text: !@#$QWER7890uiop The command I am using is the following: text_field(:name, "password").value=("!@#$QWER7890uiop) I've also tried this: text_field(:name, "password").set "!@#$QWER7890uiop) Only the first 2 charac...

I found this POS tagger in ruby called EngTagger, but i'm having trouble installing it

C:\Users\cpable>gem install engtagger Building native extensions. This could take a while... ERROR: Error installing engtagger: ERROR: Failed to build gem native extension. C:/Ruby186/bin/ruby.exe extconf.rb checking for stdio.h... no * extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessa...

Nokogiri Compilation Error - Can't find libraries/headers

Trying to install a gem, but it can't find the headers, despite specifying them: sudo gem install nokogiri -- --with-xml2-lib=/usr/local/lib --with-xml2-include=/usr/local/include/libxml2 --with-xml2-include=/usr/local/include/libxml2 --with-xslt-include=/usr/local/include/libxslt Building native extensions. This could take a while.....

Adding Growl notifications after Rake tasks are finished

Is there a way to add Growl notifications to the end of all Rake tasks? I initially thought of creating a task that Growls, and adding it as a dependency to tasks I want alerts from, but realized the dependencies get run before the task begins. Is there a way to add tasks to be run after certain Rake tasks are finished? It'd be really...

How to parse a yaml file into ruby hashs and/or arrays?

I need to load a yaml file into Hash, What should I do? ...

Thread.join blocks the main thread

Calling Thread.join blocks the current (main) thread. However not calling join results in all spawned threads to be killed when the main thread exits. How does one spawn persistent children threads in Ruby without blocking the main thread? Here's a typical use of join. for i in 1..100 do puts "Creating thread #{i}" t = Thread.new(i...

Ruby element present in array or not

Possible Duplicate: how to check if my array includes an object - rails I have array array['one', 'two', 'three'] How i find that 'two' element present in array. Is any method in ruby which can find this? Thanks ...