I'm using Nokogiri to grab the contents of the title tag on a webpage, but am having trouble with accented characters. What's the best way to deal with these? Here's what I'm doing:
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open(link))
title = doc.at_css("title")
At this point, the title looks like this:
Rag\30...
I'm having trouble making an image semi-transparent. I have one image I'd like to set to 50% opacity and position it over another image(using composite operator:OverCompositeOp). Anyone know how an easy way to do such a thing?
A little background: I'm trying to make a good watermark to place over images, but I'm not fan of rmagick's bu...
I'd like to use ngrep and/or perl to monitor the incoming data stream on a socket, then, when the appropriate characters arrive, like in this case, the string "192.168.1.101:8080", input to the data stream a redirect to another ipaddress, such as "192.168.1.102"
Is this even possible?
...
I realize this sounds a little crazy, but I'm working on a project for which I need a server to run user-provided Ruby code and return the result.
I'm looking to prevent something like this:
system("rm -rf /")
eval("something_evil")
# etc...
I'm sure there must be some reasonably safe way to do this, as it already exists at places li...
Here is my script
#!/usr/bin/env ruby
if __FILE__ == $0
`cd ..`
puts `ls`
end
which runs fine, but when it exits, I'm back where I started. How can I "export" the changes I've made to the environment?
...
I'm sending a byte array to a piece of hardware.
The first 7 bytes contain data and the 8th byte is a checksum.
The 8th byte is the Least Significant Byte of the sum of the first 7 bytes.
Examples that include the correct checksum. The last byte of each of these is the checksum
200-30-7-5-1-2-0-245
42-0-0-1-176-0-148-39
42-0-0-3-17...
I have an object which whether validation happens or not should depend on a boolean, or in another way, validation is optional. I haven't found a clean way to do it. What I'm currently doing is this (disclaimer: you cannot unsee, leave this page if you are too sensitive):
def valid?
if perform_validation
super
else
super ...
there is a list of ruby gems for twitter
could anybody recommend me one that is good to start to learn/use? that have some history of development etc etc?
I want to the stuff below on my linux box
search for keywords and follow
autofollow
rewteet
...
I am using Watir on Windows and when my script tries to run on Firefox, I see this error on my console:
JsshSocket::JSReferenceError: Components is not definedReferenceError: Components is not defined
C:/xampp/Ruby/lib/ruby/gems/1.8/gems/firewatir-1.6.5/lib/firewatir/jssh_socket.rb:12:in `js_eval'
C:/xampp/Ruby/lib/ruby/gems/1....
I am new to the world of Rake and currently writing a Rake Script which consists of various tasks depending on the arguments passed to it on runtime.
From some Tutorials over the web, I figured out how to pass parameters to the Script as well how to make a task which is dependent on other subtasks.
For reference, I have mentioned a sam...
I have Ubuntu 9.04
Ruby 1.8
Rubygems 1.3.5
In irb,
irb(main):002:0> require 'rubygems'
=> true
In a script
$ ./test.rb
./test.rb:2:in `require': no such file to load -- rubygems (LoadError)
from ./test.rb:2
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.6 (2009-08-04 patchlevel 383) [i686...
You can define a class in a namespace like this
class Gem
class SystemExitException
end
end
or
class Gem::SystemExitException
end
When code uses first method of class definition, ctags indexes the class definition like this:
SystemExitException test_class.rb /^ class SystemExitException$/;" c class:Gem
Wit...
For example, suppose I have this:
001, "john doe", "male", 37, "programmer", "likes dogs, women, and is lazy"
The problem is that the line is only supposed to have 6 fields. But if I separate it with split I get more, due to the comma being used improperly to separate the fields.
Right now I'm splitting everything, then when I get to ...
Hey. How would you optimize this SQL
SELECT SUM(tmp.cost) FROM (
SELECT DISTINCT clients.id as client, countries.credits_cost AS cost
FROM countries
INNER JOIN clients ON clients.country_id = countries.id
INNER JOIN clients_groups ON clients_groups.client_id=clients.id
WHERE clients_groups.group_id IN (1,2,3,4,5,6,7,8,9)
...
You can serve static files with Sinatra by placing them in public/ (by default) -- I have an index.html in there at the moment, but how can I make the root point to that file without having to parse it as a template?
To be clear, I can access /index.html successfully, and I'd like to route / to be the same static file, but without redir...
Hello, I am creating a Ruby On Rails website, and for one part it needs to be dynamic so that (sorta) trusted users can make parts of the website work differently. For this, I need a scripting language. In a sort of similar project in ASP.Net, I wrote my own scripting language/DSL. I can not use that source code(written at work) though, ...
Hi gurus, I've found a weird effect when trying to track down a memory leak in a Rails app. Can anyone explain what's going on here?
Save this script as a plain Ruby script (Rails not necessary):
class Fnord
def to_s
'fnord'
end
end
def test
f = Fnord.new
end
test
GC.start
sleep 2
ObjectSpace.each_object do |o|
...
I'm trying to figure out the best way to stitch together a fast, repeatable, unbreakable build process for the following environment. I've got a plan for how to do it, but I'd really appreciate a critique. (I'd also appreciate some sample code, but more on that later)
Ecosystem - Logical:
Website - asp.net MVC 2, .net 3.5, Visual St...
Notice those buttons atop http://techcrunch.com/2010/04/04/he-even-makes-coldplay-sound-fun/ for sharing the url on social networks?
I want to do something very very similar for a site I'm building. ShareThis offers a widget that does the same thing but it's branded and external.
I'm looking for a pure Ruby solution. A gem containing a...
am trying to load a file where i have all my setting into rails console.
i want to do it because when i use the console there is too much repetition .
thank you
...