Using Ruby...
Given a String x = "blah_blah.do.dah[4543]junk_junk"
How do I remove all text after the last number/digit?
I thought the easiest way to do this might be by finding the index of last occurence and then removing everything after that index. However, I can't seem to figure out how to obtain that index. All my attempts at u...
I have a helper method that creates navigation links for some controllers.
def gen_associations(controllers)
content_for :leftnav do
sorted_controllers = controllers.sort
returning String.new do |content|
content << content_tag(:h3, "Associations") <<
content_tag(:ul, :class => "nav") do
sorte...
I got involved in a new project where Perl is a must. I'm coming from a good Ruby foundation and want a quick introduction or mapping between Perl and Ruby as I heard that Perl and Ruby are very close in syntax (know nothing about features).
Do you have any recommendations for me?
What great Perl book do you recommend as an extended ...
When I make a query...
is there any meaningful difference between using a find_by helper or not?
Are there any reasons I'm overlooking for opting for shorter lines of code when doing things like this?
Booking.find_all_by_user_id(1, :joins => :confirmation)
Booking.find(:all, :joins => :confirmation, :conditions => [ 'bookings.user_id...
I implemented a restfull controller with all the correct actions and views. It works currently perfectly with a new_html.erb view that uses a form_for containing a structure like:
<% form_for @ecard do |f| %>
when watching some tutorials i saw that people also use the structure:
<% form_for :ecard do |f| %>
It sounds logical.. but ...
I've found myself twice in this situation: I install a gem on my system and start using it from my Rails project. Eventually I need to make some changes to that gem. How should I proceed?
Ideally I'd like to check out the source code of that gem somewhere, like ~/third_party/gems, work on it and have my Rails project use that instead. I...
Is there a definitive gem for the YouTube API? I'm trying to use youtube_g, but it seems to break on some basic stuff.
...
How do you use gems from a MacRuby .5 application on Snow Leopard? Do I need to specify the gem path? If so, how do I do this?
Best scenario is to package the gems inside the application so the user would not have to install them when the app is distributed.
...
I am trying to program according to Behavior Driven Development,
which states that no line of code should be written without writing
failing unit test first.
My question is, how to use BDD with private methods?
How can I unit test private methods?
Is there better solution than:
- making private methods public first and then making th...
I'm interested in Ruby, Python, PHP and Java. Does programming training and consultancy the way I described exist for any of those programming languages? Is it good? Why? Is it on the internet? Where?
...
i'm still kind of newbie to ruby, but i became used on using ruby sockets, cause i used the 'Socket' class many times, and so i having full control to my sockets and their options.
the thing is i'm trying to make it a little easy for me, so i'm trying to use the 'TCPSocket' class ,witch (i guess) doesn't give u much control as the 'Sock...
how do i match each of the following with regex ?
some text includes [any number of character]. need to pull the entire [asdfasdf]
@tableid='sometext' I need to pull the sometext
mary and drugs I need to pull " and ", spaces included.
...
Is there any way to make methods and functions only available inside blocks? What I'm trying to do:
some_block do
available_only_in_block
is_this_here?
okay_cool
end
But the is_this_here?, okay_cool, etc. only being accessible inside that block, not outside it. Got any ideas?
...
doc = Nokogiri::HTML(open(url)).xpath("//*")
.xpath("//*[br]/text()[string-length(normalize-space()) != 0]")
.wrap("<span></span>")
puts doc
it just returns the text ... i was expecting the full html source with now wrapped around the specified xpath elements.
...
I have an xpath to grab each text node which is not surrounded by any html tags. Instead, they are separated via <br>. I would like to wrap these with <span> tags.
Nokogiri::HTML(open("http://vancouver.en.craigslist.ca/van/swp/1426164969.html"))
.xpath("//br/following-sibling::text()|//br/preceding-sibling::text()").to_a
will return t...
I'm trying to pass a byte array from inside my rails app into another ruby script (still inside my rails app), for example:
`./app/animations/fade.sh "\x01\x01\x04\x00" &`
Yields ArgumentError (string contains null byte)
I suppose I'm stumped with how I can form this string and than pass it to my script, which will use it in this sor...
Hi,
We use ACLs to grant access to svn repositories. The users/groups are stored in LDAP (openLDAP 2.4 (LDAP3). Does anyone know or used libraries/package (gems) I can use. Basically, I will traverse LDAP DIT and update my svn file based on that.
Connect to ldaps://xxxxxxxxxxx:636
Traverse DIT (subtree based on 'ou')
Read attributes
...
mkristgan's rack_datamapper gem says that it "can be wrapped to be used in a specific environement, i.e. Rack::Session::Datamapper".
Unfortunately, I don't know quite enough about Ruby to accomplish this task yet –Modules/Classes in Ruby are still above my head (coming from PHP).
Can anyone offer assistance with using rack_datamapper...
I have a query which searches two separate fields in the same table... looking for locations which are most likely a specific city, but could also be a country... ie the need for two fields.
Table looks like:
Country City
Germany Aachen
USA Amarillo
USA Austin
Result:
Keyword Sideinfo
Aachen Germany
USA ...
A predefined set of objects has to be aggregated into a new object. However I want the users to specify a custom function for that.
Now the naive approach would be
def foo; end
objects = [1,2,3]
# result = eval(user_script)
result = eval("objects.inject {|sum, n| sum + n }")
What I obviously do not want to do! I read about $SAFE = 4...