Skip to content

Instantly share code, notes, and snippets.

@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:3183134
Created July 26, 2012 16:42
topaz signature pad java code
import java.awt.image.BufferedImage;
import java.beans.Beans;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import com.sun.image.codec.jpeg.JPEGCodec;
@pullmonkey
pullmonkey / gist:3188668
Created July 27, 2012 15:28
USB MagTek Card Reader in Ruby
require 'rubygems'
require 'usb' # this is the ruby-usb gem, I'm also using libusb 1.0 and linux
require 'logger'
class MagTek
def initialize
@device = find_device
interface = @device.interfaces.first
@endpoint = interface.endpoints.first
@logger = Logger.new("/var/log/monitor_usb.log")
@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:3374533
Created August 16, 2012 23:40
the erb version of dynamic select box js updater for rails 3
# app/views/home/update_artists.js.haml
$('#artists_select').html("<%= escape_javascript(options_for_select(@artists)) %>");
$('#songs_select').html("<%= escape_javascript(options_for_select(@songs)) %>");
# app/views/home/update_songs.js.haml
$('#songs_select').html("<%= escape_javascript(options_for_select(@songs)) %>");
@pullmonkey
pullmonkey / gist:3366572
Created August 16, 2012 03:56
erb alternative for the dynamic select box tutorial
# app/views/home/index.html.haml
<%= collection_select(nil, :genre_id, @genres, :id, :name, {:prompt => "Select a Genre"}, {:id => 'genres_select'}) %>
<br/>
<%= collection_select(nil, :artist_id, @artists, :id, :name, {:prompt => "Select an Artist"}, {:id => 'artists_select'}) %>
<br/>
<%= collection_select(nil, :song_id, @songs, :id, :title, {:prompt => "Select a Song"}, {:id => 'songs_select'}) %>
<script>
$(document).ready(function() {
$('#genres_select').change(function() {
@pullmonkey
pullmonkey / gist:3319691
Created August 11, 2012 01:08
dynamic select home index view
# app/views/home/index.html.haml
= collection_select(nil, :genre_id, @genres, :id, :name, {:prompt => "Select a Genre"}, {:id => 'genres_select'})
%br
= collection_select(nil, :artist_id, @artists, :id, :name, {:prompt => "Select an Artist"}, {:id => 'artists_select'})
%br
= collection_select(nil, :song_id, @songs, :id, :title, {:prompt => "Select a Song"}, {:id => 'songs_select'})
:javascript
$(document).ready(function() {
$('#genres_select').change(function() {
@pullmonkey
pullmonkey / gist:3319709
Created August 11, 2012 01:10
dynamic select routes
# config/routes.rb
DynamicSelectBoxes::Application.routes.draw do
get 'home/update_artists', :as => 'update_artists'
get 'home/update_songs', :as => 'update_songs'
root :to => "home#index"
end
@pullmonkey
pullmonkey / gist:3319683
Created August 11, 2012 01:05
dynamic select models
# app/models/artist.rb
class Artist < ActiveRecord::Base
belongs_to :genre
has_many :songs
attr_accessible :genre_id, :name, :genre
end
# app/models/genre.rb
@pullmonkey
pullmonkey / gist:3319690
Created August 11, 2012 01:07
dynamic select home controller
# app/controllers/home_controller.rb
class HomeController < ApplicationController
def index
@genres = Genre.all
@artists = Artist.all
@songs = Song.all
end
def update_artists
# updates artists and songs based on genre selected