ruby

Encryption-Decryption in Rails

Hi All, I am using require 'digest/sha1' to encrypt my password and save into database. During login I authenticate by matching the encrypted password saved in database and again encrypted the one use enter in password field. As of now everything works fine but now I want to do 'Forgot Password' functionality. To do this I need to decry...

require 'rubygems'

I have seen many samples of Ruby code with this line (for example, http://www.sinatrarb.com/). What is purpose of this require? # require 'rubygems' require 'sinatra' get '/hi' do "Hello world!" end In all cases the code works without this line. ...

convert Ruby to C languge, Would anyone care to take a look?

I have seen this sample written in Ruby code, how i can simulate it in C language? Open3.popen3(command) do |stdin, stdout, stderr| @stop_stdin = stdin while !stdout.eof do output = stdout.read(1024 * 100) list_pipes.each do |out| out.print output end end end ...

How to detect identical part(s) inside string?

I try to break down the http://stackoverflow.com/questions/2711961/decoding-algorithm-wanted question into smaller questions. This is Part I. Question: two strings: s1 and s2 part of s1 is identical to part of s2 space is separator how to extract the identical part(s)? example 1: s1 = "12 November 2010 - 1 visitor" s2 = "6 July 201...

emacs-rails vs rinari?

Hi all, I'm just coming back to rails coding after a long hiatus. I was using rinari previously but noticed that there's a new version of emacs-rails. Is anyone using either? Any preferences for one over the other? What are people using for their rails projects within emacs these days? ...

Ruby Rails, jQuery, Uploadify - weird UTF-8 error

Hi everyone, I'm setting up jQuery and Uploadify in my Rails app (with the uploadify-rails plugin). Its all going fine, the flash is loaded, the authenticity paramater is passed through along with the session key and so on. However, my MySQL queries on the way to handling the upload from the flash are all reporting a 'redundant UTF-8 se...

Ruby socket server thread question: how to send to all clients?

I'm making a TCP socket server(ruby). A thread is created for each connected client. At some point I try to send data to all connected clients. The thread aborts on exception while trying.(ruby 1.8.7) require 'socket' # I test it home right now server = TCPServer.new('localhost', 12345); while(session = server.accept) #Here is the thre...

Concurrent web requests with Ruby (Sinatra?)?

I have a Sinatra app that basically takes some input values and then finds data matching those values from external services like Flickr, Twitter, etc. For example: input:"Chattanooga Choo Choo" Would go out and find images at Flickr on the Chattanooga Choo Choo and tweets from Twitter, etc. Right now I have something like: @images =...

Populate array from vector

Hi, I would like to populate an 2 dimensional array, from a vector. I think the best way to explain myself is to put some examples (with a array of [3,5] length). When vector is: [1, 0] [ [4, 3, 2, 1, 0], [4, 3, 2, 1, 0], [4, 3, 2, 1, 0] ] When vector is: [-1, 0] [ [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4] ] ...

Ruby/python Script to convert html text to plain text in csv file

Hi all: So i have a large(ish) file in a csv format, that contains a column that has html and i need to transform that to plain text (ie readable by people ,ie with no script tags) I dont have much experience with ruby, but it seems like the perfect language to do this The File should still be in a cv format after the parsing ( ie, o...

User avatar cropping/resizing with paperclip and jquery in rails

Hello fellow stackoverflow users. I am building my first Ruby on Rails app which is going to be my own little community. I have made the User model with several fields and information. But now i am thinking of adding avatar support for the users. And i've been researching and found that my best option would be using Paperclip. But then ...

Dynamic languages for embedded devices?

I need to deploy a dynamic language to a small embedded Linux device, and have difficulty finding the right one: I want to build a small web-application with this language (with a small framework like Sinatra or Camping ) and write some scripts for maintenance. I would prefer Ruby, as I have some experience in it, but after several days...

Doing math with colors like SASS but in Ruby

In SASS I can do !pink = #ff43a7 !darker_pink = !pink - #333333 I'd like to the same in ruby. ...

Path parsing in rails

Hi! I am looking for method for parsing route path like this: ActionController::Routing.new("post_path").parse #=> {:controller => "posts", :action => "index"} It should be opposite to url_for Upd I've found out: http://stackoverflow.com/questions/2222522/what-is-the-opposite-of-url-for-in-rails-a-function-that-takes-a-path-and-gener...

Problem running Thinking Sphinx with Rails 2.3.5

Hi, I just installed Sphinx (distro: archlinux) downloading the source. Then I installed "Thinking Sphinx" plugin for Rails. I followed the official page setup and this Screencast from Ryan Bates, but when I try to index the models it gives me this error: $ rake thinking_sphinx:index (in /home/benoror/Dropbox/Proyectos/cotizahoy) Sph...

Passing Index Ranges

I'm currently trying to figure out how to pass an index range as a string, but so far have not been having any luck. Here is an example of what I'm trying to do: pos = %w{1 2..4} values = %{x cat} test_string = "This is a test with a string." test_string[pos[1]] = values[1] I know I could just break it down with split or something s...

Paperclip won't save image in Rails app

Hello stackoverflow. I am trying to use Paperclip with my Rails app to add an avatar to a user but it won't save my image or update the database column when creating the user. This is what the model looks like: class User < ActiveRecord::Base has_attached_file :avatar And the registerform in haml: - form_for :user, @user, :url =>...

Does Ruby have a special stack for returning a value?

The following Ruby code def a(b,c) b+c end is the same as follows with Python def a(b,c): return b+c It looks like that ruby has the special stack that stores the final evaluation result and returns the value when a function is called. If so, what's the name of the stack, and how can I get that stack? If not, how does the Ruby ...

call parent constructor in ruby

Hi! How can I call parents constructor ? module C attr_accessor :c, :cc def initialization c, cc @c, @cc = c, cc end end class B attr_accessor :b, :bb def initialization b, bb @b, @bb = b, bb end end class A < B include C attr_accessor :a, :aa def initialization (a, b, c, aa, bb, ...

watermark existing pdf with ruby

Is there a way to watermark an existing pdf in ruby ? I want to add a dynamically generated text, Thanks, ...