ruby

array removal of elements based on the first letter of element for RUBY

I went to http://ruby-doc.org/core/classes/Array.html#M002198 and can't figure out the way to take an array of names for example people = [chris,george,jerry,bob,bill,julie,josh] I want to be able to have the user select a letter "b" then hit enter and extract all elements with the first letter 'b' and put them in a seperate array. In...

Address verification

A friend just brought by 1,000 lines of USA shipping addresses. (Excel.) I've read this into a Ruby program via CSV::. Now I would like to check the mailing addresses for sanity. It doesn't have to be a perfect check. Her shipping contractor will be using a UPS program of some sort and we are just trying to minimize the number of addres...

Using Paperclip to Process .tga (targa) Files

I've run into an annoying problem with Paperclip. Paperclip is working fine for uploading jpg/gif files but it's choking on .targa files with the error "not recognized by identify”. Just to confirm, it's working 100% with jpg/gif/png files and I have imagemagick installed and working, this error only occurs with .tga files. The general ...

One or more params in model find conditions with Ruby on Rails

Say I have model 'Car' and controller 'cars', and a method 'display'. I have multiple attributes like: in_production, year, make I can easily do something like this to find cars that match all the parameters passed: def display @cars = Car.find(:all, :conditions => { :in_production => #{params[:in_production]}, :year => #{param...

How to use Ruby to detect whether on Windows Platform, the SHIFT or ALT key is being pressed?

I wrote a script using Ruby to click on the screen automatically on Windows's apps. All is fine except there are situations where the program will keep on clicking and I have no opportunity to click on the Shell and click CTRL-C. So some "sleep" statement need to be placed somewhere in the loop, such as "sleep 3", so that there are 3 s...

Read in external links in PHP

I know how to do this in Ruby, but I want to do this in PHP. Grab a page and be able to parse stuff out of it. ...

state_machine only works for new records

I can't seem to get the state_machine gem (http://github.com/pluginaweek/state_machine/) to work on existing records (it works correctly on new records). Here's my model: class Comment < ActiveRecord::Base state_machine :state, :initial => :pending do event :publish do transition all => :published end end end and he...

[Ruby]: Perform variety of operations on a text document.

I am a beginner. I am making a text editor wherein a user can perform variety of operations and can even convert it to a rich text. Here are my queries: (1) I want to provide the user a text-editing window wherein they can type-in text. How to do this? Which control and what-so-ever is involved? (2) When the user has entered text, how...

Mac + Ruby: Can't access ioctl of Socket? How to fix?

Good time of day. Ruby Code: def hw_address(iface) sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM,0) buf = [iface,""].pack('a16h16') sock.ioctl(SIOCGIFHWADDR, buf); sock.close return buf[18..24].to_etheraddr end puts hw_address('lo0') What it do: gets mac-address of interface. Works on Debian as expect...

How to programmatically program a "Wheel Scroll" using Ruby on Windows?

Is there a way to program a "Scroll wheel" turn on the Windows platform using Ruby? Kind of similar to programming a click on Windows, or a keyboard key press, but this is to program a scroll wheel turn. thanks. ...

Ruby password SHA512 hash replication using PHP

Hi there, is there any way I can reproduce this ruby function: def Password.hash(password,salt) Digest::SHA512.hexdigest("#{password}:#{salt}") end In php. Cheers ...

How to create a REST API for a Ruby application?

I would like to know how to provide a Ruby application with a REST API. I could code something based on Ruby's TCPServer API, but that seems a bit low-level. Do you think it would be a good solution? Or do you recommend a better approach? ...

Python alternative of ruby watirrecorder?

Hello, I'm looking for a tool to record scripts for web application testing in python, similar to ruby watirrecorder. The latter is basically a tool that generates the script for watir (web application testing in ruby) which uses IE to test web applications. ...

Specify packet size with Ruby TCPSocket

I am using Ruby to test a C# networking application, which uses sockets. I open the connection with @socket = TCPSocket.new(IP,PORT) and it works - until the text I want to send is longer than 1024 characters. Then Ruby splits the message into 2 parts. C++ and C# send the message as one packet, so the C# application doesn't need to join ...

How can you check to see if a file exists (on the remote server) in Capistrano?

Like many others I've seen in the Googleverse, I fell victim to the File.exists? trap, which of course checks your local file system, not the server you are deploying to. I found one result that used a shell hack like if [[ -d #{shared_path}/images ]]; then ... but that doesn't sit well with me, unless it were wrapped nicely in a Ru...

appending to hash while looping

I will make this quick. I'm using Ruby/LDAP to search using my base_dn criteria. I get a result back (of type Entry). I can convert object of type Entry to Hash with to_hash method. The problem is when the result is returned it is multiple objects of type Entry. I want to convert them to hash append them while looping. Look at this: co...

What resources exist for WxRuby: documentation, tutorials, samples?

I found the RubyForge documentation, which is a little tricky to navigate. There's a basic tutorial on the Ruby On Windows blog. But I've already moved on from that. What other WxRuby resources have you found useful? Or, if not WxRuby specifically, what Wx resources have you found useful from a Ruby perspective? ...

[PHP]: Is it possible to access .NET DLL through PHP?

I have a .NET DLL containing functions that I can use in PHP. Though various PHP libraries are available, but I just wanted to know whether PHP supports libraries written in other languages? In future if I write a library in Ruby and want to use it with PHP, is it possible? ...

Bluetooth in Ruby (Mac/Cross Platform)

Hi all, I'm trying to get a list of the bluetooth addresses (the MAC address-like hex digits unique to each bluetooth device) within range of the bluetooth device inside my mac in the ruby language. I'm hoping to make my work publicly available, so it'd be nice if it was platform agnostic. Googling only helps so much: hcitool etc are...

Gem specification in Rakefile vs .gemspec

I am creating a new ruby gem using NetBeans as my IDE. The initial project structure contains a Rakefile with the gem specification and other rake tasks. My question is, what is the difference between having a gem specification located in a Rakefile compared with having it located in a .gemspec file? Is there a best-practice for where t...