Hi there,
I'd like to scrape the discussion list of a private google group. It's a multi-page list and I might have to this later again so scripting sounds like the way to go.
Since this is a private group, I need to login in my google account first.
Unfortunately I can't manage to login using wget or ruby Net::HTTP. Surprisingly googl...
c:/ruby/lib/ruby/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:259:in `get': 500 => Net::HTTPInternalServerError (Mechanize::ResponseCodeError)
I get the above error when I try to navigate to the following webpage
http://fakewebsite.com//admin/edit_building.cfm?page=buildings&updateMode=yes&id=1251
I can navigate just fine ...
I'm sitting with massive amounts of legacy C code that needs to be converted to Ruby for a project.
I've seen Ruby to C translators online, but not the other way around. Would there be a simple way to approach this particular problem?
...
Hey,
I have recently started a project in Ruby on Rails. I used to do all my projects before in Python but decided to give Ruby a shot.
In the projects I wrote in Python I used a nice little technique explained by the correct answer in this post:
http://stackoverflow.com/questions/277965/dictionary-or-if-statements-jython
I use this...
I'm using mechanize to login into a website and then retrieve a page. I'm running into some problems and I suspect this is due to some values in the cookies. When Mechanize logs into a website I assume it stores the cookies.
How do I print out all the data stored in the cookies by Mechanize?
...
What do you lose in practice when you choose a statically-typed language such as Scala (or F#, Haskell, C#) instead of dynamically-typed ones like Ruby, Python, Clojure, Groovy (which has macros or runtime metaprogramming capabilities)? Please consider best statically-typed languages and best (in your opinion) dynamically-typed languages...
How can I use Nokogiri with having html entities (like German umlauts) untouched?
I.e.:
# this is fine
node = Nokogiri::HTML.fragment('<p>ö</p>')
node.to_s # => '<p>ö</p>'
# this is not
node = Nokogiri::HTML.fragment('<p>ö</p>')
node.to_s # => '<p>ö</p>'
# this is what I need
node = Nokogiri::HTML.fragment('<p>ö</p>')
...
Hi,
I am working with the following piece;
def index
@user = User.find(params[:id])
rescue
flash[:notice] = "ERROR"
redirect_to(:action => 'index')
else
flash[:notice] = "OK"
redirect_to(:action => 'index')
end
Now I either case whether I have a correct ID or not, I am always getting "OK" in my view, what am I...
I found ruby class Timeout very useful for my project.
But i need to run a block of code in background and keep it under a timeout..
For example
Timeout::timeout(2) { block.call }
How to do that?
...
If I have an empty tag:
<tag/>
How can I add text so that I end up with:
<tag>Hello World!</tag>
I can only seem to swap the whole tag with different content or add content before/after it.
...
I have the following that I retreive the title of each url from an array that contains a list of urls.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
@urls = ["http://google.com", "http://yahoo.com", "http://rubyonrails.org"]
@found_titles = Array.new
@found_titles[0] = Nokogiri::HTML(open("#{@urls[0]}")).search("title").inn...
I can't seem to get JSON.pretty_generate() to actually generate pretty output in Rails.
I'm using Rails 2.3.5 and it seems to automatically load the JSON gem. Awesome. While using script/console this does indeed produce JSON:
some_data = {'foo' => 1, 'bar' => 20, 'cow' => [1, 2, 3, 4], 'moo' => {'dog' => 'woof', 'cat' => 'meow'}}
som...
Does DataMapper provide a convenient way to create a new record when none exists or update an existing one? I couldn't find anything in the API documentation.
This is what I have at the moment which doesn't seem very elegant:
foo = Foo.get(id)
if foo.nil?
foo = Foo.create(#attributes...)
else
foo.update(#attributes...)
end
foo.save...
Is there a shorter (and cleaner) way to write the following reader method:
class Foo
attr_writer :bar
def bar
return_value = @bar
self.bar = nil
return_value
end
end
Here's some output on the console to show what it does:
>> foo = Foo.new
=> #<Foo:0x1010e9cf8>
>> foo.bar
=> nil
>> foo.bar = "ok"
=> "ok"
>> foo.bar
...
Hey. I would like to understand what "class << self" stands for in the next example.
module Utility
class Options #:nodoc:
class << self
def parse(args)
end
end
end
end
Thx!
...
I've heard both MacRuby and Ruby CocoaBridge discussed in relation to iPhone/iPad development in Ruby. Do I need one or both of these?
...
So I have a webserver I've built using sinatra, the meat of which goes like this:
set :variable,"value"
get '/' do
erb :index
end
And, of course, the template in views/index.erb which looks something like this:
<html>
<!-- etc -->
<ul>
<% my_array.each do |thing| %>
<%="Something: #{thing}, variable from sinatra: #{settings.v...
Hi,
I am a newbie in amazon ec2 setup.
I have now setup a machine to my taste - and I now want to bundle it.
I am running the following command from the launched instance -
root@domU-21-34-67-26-ED-Z4:~# ec2-bundle-vol -r i386 -d /mnt \
-p ACT-VOL -u 8940-1355-4155 -k /tmp/pk-key.pem \
...
I tried to install the following gem:
http://github.com/maxjustus/sinatra-authentication
on Windows 7 running Ruby 1.9 from the One-Click Installer.
I got the following error:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Joel>gem install sinatra-authentication
Buildin...
I'm writing a simple Qt4 application in Ruby (using qtruby) to teach myself both. Mostly it has gone well, but in trying to use Ruby's "duck typing" I've run into a snag; respond_to? doesn't seem to reflect reality.
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'Qt4'
=> true
irb(main):003:0> require 'qtuitools'
=...