ruby – PullMonkey Blog http://pullmonkey.com Sun, 05 Aug 2012 00:10:47 +0000 en-US hourly 1 https://wordpress.org/?v=5.6 VIN API – Do you know about the complete data set? http://pullmonkey.com/2012/08/04/vin-api-do-you-know-about-the-complete-data-set/ Sat, 04 Aug 2012 15:42:04 +0000 http://pullmonkey.com/?p=57715 Looking at our data trends for VIN API, we show about 15% of all requests are for the complete data set. It's the same price as the basic data set and rich with a ton of data.

Check out the data set from this post over 1 and half years ago. On top of the basic data set's year, make and model, the complete data set comes with data like MSRP, MPG (city and highway), dealer invoice, gas tank size, etc.

We get tons of hits for basic data, but at no additional charge we also provide the complete data set. Just add a complete
=> "true" to your request. So simple and there's no performance hit.

For more information, check out or examples and faq.

Enjoy!

Here's another look at the data elements from a comprehensive query:

]]>
Using Ruby to read from a MagTek USB Card Reader http://pullmonkey.com/2012/07/27/using-ruby-to-read-from-a-magtek-usb-card-reader/ Fri, 27 Jul 2012 15:39:59 +0000 http://pullmonkey.com/?p=57712 Been playing around with a lot of USB devices lately, to get them to play nicely with some of our touch screen Rails apps.
One of the devices is a card reader - specifically a MagTek reader, and the same code works for the ELO reader.

I've tried a billion different ways to ensure we're reading in all the data. At first, I was just asking the usb stream to present me with a certain number of characters, b/c that's how all the examples do it.
But we're using a lot of different cards with the readers, so that didn't work too well. So now I just read one character at a time until we find the new line.
Here's the code to find the device, open it, close it and read from it, all whilst finding and converting the data as required.

So using this code, we take the swiped data and send it to our server for storage.

]]>
Rubygem version incompatability with older Rails versions http://pullmonkey.com/2012/05/30/rubygem-version-incompatability-with-older-rails-versions/ Wed, 30 May 2012 15:35:39 +0000 http://pullmonkey.com/?p=57701 We maintain a rails 2.3.8 application and haven't had to touch it in quite some time. But when we did, we came across this error:

uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

Then after applying the solution found here, we started getting this error:

undefined method `name' for "actionmailer":String (NoMethodError)

Both errors were resolved by using RVM to specify the rubygem version best suited for this application.

rvm rubygems 1.3.7

So our .rvmrc file now looks like this:

rvm use @
rvm rubygems 1.3.7
]]>
Headers and Footers in ruby’s Spreadsheet gem http://pullmonkey.com/2012/04/26/headers-and-footers-in-rubys-spreadsheet-gem/ http://pullmonkey.com/2012/04/26/headers-and-footers-in-rubys-spreadsheet-gem/#comments Thu, 26 Apr 2012 19:17:20 +0000 http://pullmonkey.com/?p=57696 Have you ever needed to add a header or footer to your spreadsheets in ruby?
Yah, well, we have 🙁
Yes, you can do this with the Write Excel gem.
But we've already written years worth of spreadsheet code with the spreadsheet gem and don't want to rewrite it all.

Anyway, we thought we'd share our little trick to get page headers using the spreadsheet gem.

So what you see here (above) goes into a config/initializer, something like RAILS_ROOT/config/initializer/enable_headers_in_spreadsheet_gem.rb. Here's what's going on:

1) We know that the write_from_scratch method is called when everything is said and done and the data is ready to be written to the spreadsheet file. So we make use of this and alias that method to write_from_scratch_without_header. Which opens us up to call our write_header method inside our write_from_scratch method which, of course, will call the original write_from_scratch method.

2) Our write_header method makes use of the already existing opcode for Header in the spreadsheet gem. It's not being used, so my guess is the developers intend on solving this issue at some point. We have to send the opcode, the length info and the string we want to write out. This was the trickiest part to figure out.

3) We expose an add_header method that simply takes a string and stores it in the header accessor. This means, to set the header, you simply say sheet.add_header("foo header").

To implement the footer, you'd just do the same thing, create a footer accessor, add a method to update it. Then build the writer_footer method with opcode(:footer) and append write_footer at the end of write_from_scratch.

Well, that took us some time to figure out, so enjoy and let me know if you have any questions.

]]>
http://pullmonkey.com/2012/04/26/headers-and-footers-in-rubys-spreadsheet-gem/feed/ 1
Hello Android – Pindah (with Mirah) Application http://pullmonkey.com/2011/11/13/hello-android-pindah-with-mirah-application/ Sun, 13 Nov 2011 04:38:08 +0000 http://pullmonkey.com/?p=57638 Did you install the Android SDK / JDK, etc?  If not, start here - http://developer.android.com/sdk/index.html.
If you're running 64-bit like me, make sure to install the ia32-libs, since the SDK is 32-bit.

This is completely based on the Hello Android tutorial - I didn't really do a whole lot, but the hope is that this will help get some more ruby devs into android development with a simple how-to.

Step 1 - Setup RVM with jruby

Note: RVM is awesome, if you don't use it or don't know about it - read more here.

rvm install jruby
cd /path/to/your/android/pindah/mirah/project/dir/
# using your .rvmrc will trigger `rvm use jruby` when you cd into your project dir.
echo "rvm use jruby" > .rvmrc
# this will make sure your .rvmrc is working, you should then be able 
# to use rvm info and see jruby
cd .

Step 2 - Install the mirah and pindah gems

# too easy
gem install mirah pindah

Step 3 - Create your first pindah app

pindah create com.example.android.hello_world
cd hello_world

Step 4 - Create your activity - HelloAndroid.mirah

# from your project dir and inside your pindah app dir 
<editor> src/com/example/android/hello_world/HelloWorld.mirah

This is the code I used:

Step 5 - Setup your AndroidManifest.xml file

This is where you define your app, version, name, etc, but more importantly for this example - what activity will handle your main intent.
Mine looks like this:

Step 6 - Install to your device

# make sure a device is recognized  ... 
# and make sure adb is in your path (platform-tools in the SDK)
adb devices
rake install

]]>
Playing with Mirah http://pullmonkey.com/2011/11/10/playing-with-mirah/ http://pullmonkey.com/2011/11/10/playing-with-mirah/#comments Thu, 10 Nov 2011 06:14:37 +0000 http://pullmonkey.com/?p=57622 Mirah (formally duby) is pretty freaking cool.   Plans are to scrap java and use mirah for future android development, we'll see.  Here's a rough example of some pretty basic mirah.

To get started, you'll need jruby and the mirah gem:

rvm install jruby
rvm use jruby (or put in your .rvmrc)
gem install mirah

Then create an example:

puts "hello world!!"
500.times do |x|
  puts x
end

Time in ruby:

time ruby test.mirah

...
=> .457s

Compile to Java and time:

mirahc test.mirah
time java Test

....
=> .081s

Less than 1/5 the time and it compiles to Java ... neat 🙂

mirahc -j test.mirah

// Generated from test.mirah
public class Test extends java.lang.Object {
  public static void main(java.lang.String[] argv) {
    int __xform_tmp_1 = 0;
    int __xform_tmp_2 = 0;
    int x = 0;
    java.io.PrintStream temp$1 = java.lang.System.out;
    temp$1.println("hello world");
    __xform_tmp_1 = 0;
    __xform_tmp_2 = 500;
    label2:
    while ((__xform_tmp_1 < __xform_tmp_2)) {
      x = __xform_tmp_1;
      label3:
       {
        java.io.PrintStream temp$4 = java.lang.System.out;
        temp$4.println(x);
      }
      __xform_tmp_1 = (__xform_tmp_1 + 1);
    }
  }
}
]]>
http://pullmonkey.com/2011/11/10/playing-with-mirah/feed/ 1
Using ruby to consolidate a list of numbers by shortening with hyphens http://pullmonkey.com/2011/11/09/using-ruby-to-consolidate-a-list-of-numbers-by-shortening-with-hyphens/ Wed, 09 Nov 2011 21:34:09 +0000 http://pullmonkey.com/?p=57619 Check it out -

]]>
VIN API – ignore checksum validation http://pullmonkey.com/2011/10/28/vin-api-ignore-checksum-validation/ Fri, 28 Oct 2011 15:55:35 +0000 http://pullmonkey.com/?p=57615 It's been mentioned a few times that there should be a way to skip the checksum validation. This means if the check digit calculation generally fails, VIN API will continue to process the VIN to see if there is a "like" VIN match. So here it is:

]]>
Vin API – Phase II http://pullmonkey.com/2011/01/13/vin-api-phase-ii/ http://pullmonkey.com/2011/01/13/vin-api-phase-ii/#comments Thu, 13 Jan 2011 22:42:14 +0000 http://pullmonkey.com/?p=57563 We've just finished adding A LOT more details to VIN API's result set. This time we've added things like MPG, MSRP, cargo room/volumn, etc. See the full list below, it is very comprehensive.

If you use ruby (look for a future post with .NET and PHP examples), and want the complete dataset, you would setup your ActiveResource like this:

And then call our API like this:

The only change (for those of you who have already implemented phase I) is to send in a "complete" parameter with value of "true" ... upon doing so, VIN API will send you the complete dataset versus the basic (and default) dataset.

The results would look like this (in XML) and be prepared because it is lengthy:

That's it, just thought I'd share VIN API's Phase II.

]]>
http://pullmonkey.com/2011/01/13/vin-api-phase-ii/feed/ 1
2D Vector Graphics in Ruby / Rails http://pullmonkey.com/2010/11/19/2d-vector-graphics-in-ruby-rails/ Fri, 19 Nov 2010 21:42:27 +0000 http://pullmonkey.com/?p=57544 I've been working with Cairo the last day or two to build a sign generator.   I chose Cairo because it seemed like a good fit for building a sign that had to be loss-less in detail and scalable, this rang vector graphics.   I found a few good examples here and there, but they were very few and the documentation was not exactly ruby-friendly.

So I'm going to do a few posts about what I learned and I am going to start with the very basics, since all I could find were completed and elaborate images, way too complicated for a beginner.

Let's start with rotating a square box by 45 degrees.  Very simple.

rotated_square

That's it, pretty simple, right?

]]>