I'm looking for a way to load up an existing png image, and do a pixel by pixel manipulation of the values. Ideally, something like
image = Image.open('my.png')
image = image.map_each_rgb do |r, g, b|
[r-12, g+2, b+30]
end
image.save('my.png')
I've looked into rmagick, but couldn't find a way to achieve this.
Are there any alternat...
I need to write web-service that will get files over http and convert them. This service in future might be included in rails application. I wonder what I need to use for that?
Mount as Rack-middleware? Sinatra app? Write Rails-engine? Simple ruby script with networking? Anything else?
Thanks
...
Hi All,
I am a PHP dev trying to start using HAML, using this implementation:
http://phphaml.sourceforge.net/
HAML looks awesome, but I don't understand if/how it supports partials (or includes, as they are called in the PHP world).
I would like to have a master template HAML file that then goes and loads up a bunch of partials for al...
This does not seem to work:
class Test
private
define_method :private_method do
"uh!"
end
end
puts Test.new.private_method
...
So, we use SDB to store lots of data and currently I'm using the RightAWS gem for Ruby to access that data. I'm trying to get the results of a query which returns about 16,000 items. This process takes a long time because I only get 100 back each token, so about 160 requests must be made. The documentation says: "The limit is the maxi...
I have a bunch of recurring tests for some of my controller actions, all of which require authentication. As a result, you end up seeing a lot of code like the following:
describe "authentication requests" do
it "should return 401 for unauthenticated :show" do
get :show
...
end
it "should return 401 for unauth...
I'm using a inherited controller for an abstracted class. I'm trying to avoid overriding actions within all of the descendant controllers. How could I find out the name of the key where the array of form values is living? For example:
The master class currently uses this to update rows
if @parent.update_attributes(params[:parent])
...
I have a piece of code that checks that a survey response picked by user to a survey question is in fact one of valid choices:
Question.find_by_id(question_id).question_choices.all(:select => 'id').map {|x| x.id}.include?(user_choice_id)
Is there an easier way?
Thanks!
...
I've noticed this little oddity(I think) in If Statements in Ruby. Here's an example:
my_number = nil
if my_number < 3
'number is less than 3'
end
Obviously, when you run this code you'll get a "comparison of Fixnum with nil failed" error. Now here's something strange. If I make a little change in the If Statement to check for nil,...
rand 10 works but not 1 + rand 10. Why must it be 1 + rand(10)?
> RUBY_DESCRIPTION
=> "ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]"
> rand 10
=> 8
> (1 + rand 10)
SyntaxError: (irb):15: syntax error, unexpected tINTEGER, expecting keyword_do or '{' or '('
(1 + rand 10)
^
from /Users/peter/.rvm/r...
I was looking through some tab-completions that were automatically set up for my editor, and I found one where y was mapped to:
:yields: arguments
What is this syntax called, when, where, how and for what is this used?
...
Ok guys, so I'm making a scheduler.
So I have two tables so far,
Shows with "title:string" and "description:text" and I also have
ShowTime; with "show_id:integer", "day:string", and "show_time:time".
I did the has_many, and belongs_to, I honestly do not know where to go from here on,
I want a user to be able to add the times when cr...
>> current_user.first_visit
=> 0
>> if current_user.first_visit
>> puts "test"
>> end
test
=> nil
Why does it print test?
...
Hi i am using Ruby on rails. I am developing application where users can import their blogposts from wordpress , blogger and may be typepad into my site. can any one guide me how can i do it. Even if it's not a ROR solution do give me some ideas. I tried using Gdata api for blogger but that just gave me the link to post.
...
I want write a ruby wrapper for a existing C library (.so files). Can anyone point me to books/websites that can get me started with this.
Thanks,
Sivakumar
...
I know Twitter initially ran on the Ruby on Rails platform.
Is this true today?
...
Just moving over to vim at the moment. In textmate I could format code by hitting cmd-alt-[. How do I achieve the same in vim?
See the answer below for the command. I found I also need the following in my vimrc so that vim new how to autoindent ruby.
if has("autocmd")
filetype indent on
endif
...
Greets to all!
I want to describe each kind of product by a class:
# Base product class
class BaseProduct
prop :name, :price # Common properties for all inheritable products
end
class Cellphone < BaseProduct
prop :imei # Concrete property for this product
end
class Auto < BaseProduct
prop :max_speed, :color # Concrete properties...
I need to add the ability to upload and store any kind of file, PDF, XLS, DOC, etc. What is the best way to do this in a ruby on rails application?
...
I know that some say the @@class_var syntax should be avoid in Ruby and should use the @instance_var in the class' scope instead ...
def MyClass
@@bad_class_var # Should not do this.
@good_class_var # Should do this.
end
My question is why the @@ notation is frowned upon in Ruby?
...