Skip to content

Instantly share code, notes, and snippets.

# find the JUST created model
Then(/^#{capture_model} was just created(?: with #{capture_fields})?$/) do |name, fields|
find_latest_model!(name, fields)
end
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)
@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
@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: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:778747
Created January 13, 2011 22:30
VIN API call for complete dataset
VinApi.find('1HGCM82633A004352', :params => {:complete => "true"})
@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 / simple_rotated_box_using_cairo.rb
Created November 19, 2010 21:14
Simple Rotated Box Cairo Example for pullmonkey.com
require 'rubygems'
require 'cairo'
class Box
# height and width for the rectangle, angle for the rotation
attr_accessor :height, :width, :angle
def initialize(height=200, width=200, angle=45)
@height, @width, @angle = [height, width, degrees_to_radians(angle)]
# The first argument for a surface is the filename, the next two are our canvas/surface size.
@pullmonkey
pullmonkey / vinapi.php
Created November 16, 2010 03:40
Way to use the Skizmo VINAPI in PHP
<?php
function decodeVIN($vin){
$curl = curl_init();
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_URL, 'http://vinapi.skizmo.com/vins/'.$vin.'.xml');
curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', 'X-VinApiKey: YOUR_API_KEY_GOES_HERE'));
$result = curl_exec ($curl);
curl_close ($curl);
return $result;
}
<h2>Testing home top for speedeals.com</h2>
<b>Really?</b>
<ul>
<li>Hello THere...</li>
</ul>