Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
pullmonkey / gist:778735
Created January 13, 2011 22:22
Setup VinAPI ActiveResource
class VinApi < ActiveResource::Base
headers["X-VinApiKey"] = "YOUR_API_KEY_GOES_HERE"
self.site = "http://vinapi.skizmo.com"
self.element_name = "vin"
end
@pullmonkey
pullmonkey / gist:778747
Created January 13, 2011 22:30
VIN API call for complete dataset
VinApi.find('1HGCM82633A004352', :params => {:complete => "true"})
@pullmonkey
pullmonkey / gist:778755
Created January 13, 2011 22:35
XML example of the dataset from VIN API
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<telescopic-steering-column>Std.</telescopic-steering-column>
<front-split-bench-seat>N/A</front-split-bench-seat>
<powertrain-warranty-distance>36,000 mile</powertrain-warranty-distance>
<leather-seat>Std.</leather-seat>
<load-bearing-exterior-rack>N/A</load-bearing-exterior-rack>
<front-spring-type>Coil</front-spring-type>
<steel-wheels>N/A</steel-wheels>
<maximum-gvwr>No data lbs</maximum-gvwr>
@pullmonkey
pullmonkey / gist:778789
Created January 13, 2011 22:57
VB .NET example from one of VIN API's customers
Public Function DecodeVIN(ByVal VIN As String, Optional ByVal Complete As Boolean = False) As String
Try
Dim aResponse() As Byte
Dim sResponse As String = ""
Dim oWebclient As New WebClient
Dim oEncoder As New System.Text.ASCIIEncoding
'Call the API
oWebclient = New WebClient
oWebclient.Headers.Add("X-VinApiKey", "APIKEYGOESHERE")
@pullmonkey
pullmonkey / gist:783562
Created January 17, 2011 21:54
Comprehensive PHP VIN Decoder using VIN API
<?
// VIN API decoder for PHP 4.x+
define('ELEMENT_CONTENT_ONLY', true);
define('ELEMENT_PRESERVE_TAGS', false);
function getXML($vin) {
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, 'http://vinapi.skizmo.com/vins/'. $vin.'.xml');
curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', 'X-VinApiKey: #YOURAPIKEYGOESHERE#')); //use your API key here
module Pickle
module Session
def find_latest_model(a_model_name, fields = nil)
factory, name = *parse_model(a_model_name)
raise ArgumentError, "Can't find a model with an ordinal (e.g. 1st user)" if name.is_a?(Integer)
model_class = pickle_config.factories[factory].klass
fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
conditions = convert_models_to_attributes(model_class, fields)
# find the JUST created model
Then(/^#{capture_model} was just created(?: with #{capture_fields})?$/) do |name, fields|
find_latest_model!(name, fields)
end
@pullmonkey
pullmonkey / trigger_capybara_js_change_event.rb
Created March 3, 2011 22:47
capybara celerity driver does not trigger JS change event
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
with_scope(selector) do
select(value, :from => field)
# this is what changed .. 1) need to find the ID of the field that was passed in and then trigger a change event
id = "#" + find_field(field)[:id]
page.execute_script("$('#{id}').trigger('change');")
end
end
@pullmonkey
pullmonkey / gist:1322591
Created October 28, 2011 15:49
VIN API - ignore checksum validation
# first without ignoring the checksum, you'll see that we get an error
>> VinApi.find("VIN WITH BAD CHECKSUM GOES HERE")
=> #<VinApi @prefix_options={}, @attributes={"error"=>"Vin did not pass checksum test"}>
# next ignoring the checksum, we get our data
>> VinApi.find("VIN WITH BAD CHECKSUM GOES HERE", :params => {:ignore_checksum => "true"})
=> #<VinApi @prefix_options={}, @attributes={"body_style"=>"Coupe", "model"=>"ACCORD EX", "country"=>"USA", "world_region"=>"North America", "engine_type"=>"FWD", "vin"=>"VIN WITH BAD CHECKSUM GOES HERE", "transmission"=>"Automatic", "make"=>"Honda", "year"=>"2003"}>
@pullmonkey
pullmonkey / gist:1353088
Created November 9, 2011 21:23
consolidate a sequence of concurrent numbers with hyphens
# take list of 1,2,3,5,6,7,10 and turn into 1-3,5-7,10
def self.consolidate_pdsh_values(vals)
# vals is an array
# Examples:
# 005,006,007,008,009,010,011,012 => 005-0012
# 123,4,5,6,7,8,9,10,11,12,1234,1235,1236 => 4-12,123,1234-1236
sorted_vals = vals.sort{|a,b| a.to_i <=> b.to_i}
skipped_vals = sorted_vals.each_with_index.map do |x,i|
# replace with "-" if we are in the middle of a set of concurrent numbers
(i > 0 and i + 1 < sorted_vals.size and # make sure we are in bounds