Hello,
how would I develop an Email client in Ruby-on-rails taking Gmail as an example? I would be especially interested in the send email functions
Thanks for any pointers
In the effort to learn python and/or ruby, I was wondering how a file shredder would be implemented? I would like it to take in a file as an argument and then employ an algorithm to make that file unrecoverable. Would possibly add the support for multiple files or even whole directories later.
What are the best practices for reading and writing binary data in Ruby?
In the code sample below I needed to send a binary file using over HTTP (as POST data):
f = File.new("resp.der", "r") # binary file
begin
while true
out.syswrite(f.sysread(1)) # out is an output stream (type IO)
end
rescue EOFError => err
puts "Sent response."
end
While this code seems to do a good job, it probably isn't very idiomatic. How can I improve it?
Hello,
I've a remote cgi script hosted on Apache using SSL. It takes in two input variables a and b.
I want to call call the cgi script with right input variables using ruby.
Any clues would be appreciated.
I want to unescape the following string:
'\u00020\u0002Standard\u00023\u0002Doe John\u000169\u0002\u0010\u0002Lorem\u0002\u0011\u0002Ipsum\u0002\u0014\u0002'
Javascripts unescape function works ok, however how can I unescape it in ruby?
Take in mind that unescape(previousString) is 0Standard3Doe John69LoremIpsum.
In ruby, how do I test that one array not only has the elements of another array, but contain them in that particular order?
correct_combination = [1, 2, 3, 4, 5]
[1, 5, 8, 2, 3, 4, 5].function_name(correct_combination) # => false
[8, 10, 1, 2, 3, 4, 5, 9].function_name(correct_combination) # => true
I tried using include, but that is used to test whether [1,2,3].include?(2) is true or not.
Inspired by this discussion, after some googling I wasn't able to find an answer to a pretty simple question regarding methods in Ruby: are they objects or not?
There are different opinions here and there, and I would really like to hear, let's say, an in-depth explanation.
I'm aware of Object#method method, which takes a method name and returns a Method instance, but, on the other hand, there's a similar thing you can do with blocks to make them into Proc instances, and blocks aren't objects, so what makes methods any different?
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'm building a library in ruby, what's the best way to allow users of the library to set module-wide settings that will be available to all sub classes etc of the library?
A good example would be if I'm writing a library for posting to a webservice:
TheService::File.upload("myfile.txt") # Uploads anonymously
TheService::Settings.login("myuser","mypass") # Or any other similar way of doing this
TheService::File.upload("myfile.txt") # Uploads as 'myuser'
The idea would be that unless TheService::Settings.logout is called then all TheService operations would be conducted under myuser's account.
Any ideas?
If I have no to little experience in either of them, but know enough Java and Ruby to be comfortable, is one framework harder to learn than the other? Is one easier to use for the beginner on these?
I know it is hard to answer. Just looking for general thoughts on it.
I'm looking for a much more idiomatic way to do the following little ruby script.
File.open("channels.xml").each do |line|
if line.match('(mms:\/\/{1}[a-zA-Z\.\d\/\w-]+)')
puts line.match('(mms:\/\/{1}[a-zA-Z\.\d\/\w-]+)')
end
end
Thanks in advance for any suggestions.
i cant understand what the difference is between a namespace and a scope in the routing of ruby-on-rails 3.
could someone please explain?
namespace "admin" do
resources :posts, :comments
end
scope :module => "admin" do
resources :posts, :comments
end
thanks
In Ruby on Rails, where does one put the code from this snippet in http://gist.github.com/376389? I want to extend ActiveRecord::Errors with the code that's available there so I can merge error messages.
Is this something for ApplicationController? or for lib?
Could somebody please explain why the variable named foo remains true in the code below, even though it's set to false when the method is called? And why the symbol version behaves as expected?
def test(options = {})
foo = options[:foo] || true
bar = options[:bar] || :true
puts "foo is #{foo}, bar is #{bar}"
end
>> test(:foo => false, :bar => :false)
foo is true, bar is false
I've only tried this using Ruby 1.8.7.
I'm very newbie in ruby and need your help.
I must save a "Topic" and make it like this :
@topic = Topic.new(params[:topic])
But I would like to pass an other information to this topic. It has a field "community_id" that link it to a community.
The logged user has this information on his table.
How can I pass the "community_id" from the logged user to the "community_id" of the "topic" created ?
thx for your help
hey Folks,
Is there any way in ruby to get the memory address of objects..
say..
(i = 5) is that possible to get the mem address of that object 5..
I have been trying to get this over some time..,
Any answer would be really appreciated...
thanks,
Regards levirg
I'm trying to produce some Ruby code that will take a string and return a new one, with a number x number of characters removed from its end - these can be actual letters, numbers, spaces etc.
Ex: given the following string
a_string = "a1wer4zx"
I need a simple way to get the same string, minus - say - the 3 last digits. In the case above, that would be "a1wer". The way I'm doing it right now seems very convoluted:
an_array = a_string.split(//,(a_string.length-2))
an_array.pop
new_string = an_array.join
Any ideas?
In Ruby, why does defining a class evaluate to nil? Same goes for defining a method: why does it evaluate to nil? Wouldn't it be useful if defining a class would evaluate as the class?
I need to run multiple background threads in a thread pool with timeout.
The scheme is something like:
#!/usr/bin/env ruby
require 'thread'
def foo(&block)
bar(block)
end
def bar(block)
Thread.abort_on_exception=true
@main = Thread.new { block.call }
end
foo {
sleep 1
puts 'test'
}
Why if i run that i get no output? (and no sleep wait?)
Hi,
I'm using ruby to sort an array where each element in the array is another array.
I have this:
Data = Data.SortBy { |Info| info[3] }
example data in this column:
3.1
2
5.65
-1
0.4
-9.43
-10.87
-2.3
It should sort this into:
5.65
3.1
2
0.4
-1
-2.3
-9.43
-10.87
But it comes out like this:
5.65
3.1
2
0.4
-1
-10.87
-2.3
-9.43
It's only comparing the first char of the float... not the whole number?