Skip to content

Instantly share code, notes, and snippets.

View sirkirby's full-sized avatar
:octocat:

Chris Kirby sirkirby

:octocat:
View GitHub Profile
@sirkirby
sirkirby / VEAPI_VIN_RestSharp.cs
Created October 22, 2012 19:25
RyanTech VIN Explosion API Decode VIN w/ RestSharp
// using RestSharp and Json.Net
// client and authentication
var client = new RestClient("http://vinexplosion.com/api/");
client.Authenticator = new HttpBasicAuthenticator("username", "password");
// request
var request = new RestRequest("vin/decode/{vin}/?fuzzy=true", Method.GET);
request.AddUrlSegment("vin", "JA4AP3AU5BZ009787");
request.AddHeader("Accept", "application/json"); // use application/xml for xml response
// response
var response = client.Execute(request);
@sirkirby
sirkirby / VEAPI_VIN_jQuery.js
Created October 22, 2012 21:54
RyanTech VIN Explosion API Decode VIN w/ jQuery
// using jQuery and jQuery-base64 https://github.com/carlo/jquery-base64
var creds = "Basic " + $.base64.encode("username:password");
$.ajax({
url: "http://vinexplosion.com/api/vin/decode/3GYFNAE36CS509361/?fuzzy=true",
dataType: "jsonp",
beforeSend: function (req) {
req.setRequestHeader("Authorization", creds);
req.setRequestHeader("Accept", "application/json");
},
success: function(data, status) {
@sirkirby
sirkirby / VEAPI_VIN_Java.java
Created October 22, 2012 22:01
RyanTech VIN Explosion API Decode VIN w/ Java
//using Base64Coder and google-gson
// initiate the http request to the vin explosion api
HttpClient client = new DefaultHttpClient();
String getUrl = "http://vinexplosion.com/api/vin/decode/";
getUrl += vin + "/";
getUrl += "?fuzzy=" + URLEncoder.encode("true");
HttpGet get = new HttpGet(getUrl);
// set the appropriate request headers
get.addHeader("Authorization", "Basic " + Base64Coder.encodeString("username:password"));
get.addHeader("Accept", "application/json");
@sirkirby
sirkirby / VEAPI_VIN_AspNet.cs
Created October 22, 2012 22:05
RyanTech VIN Explosion API Decode VIN w/ Asp.Net
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://vinexplosion.com/api/vin/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var byteArray = Encoding.ASCII.GetBytes("username:password");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
// make the request and capture the response
var result = client.GetAsync("decode/JA4AP3AU5BZ009787/?fuzzy=true").Result;
// grab the json
var json = result.Content.ReadAsStringAsync().Result;
var rvef = JObject.Parse(json);
@sirkirby
sirkirby / VEAPI_Vehicle_AspNet.cs
Created October 22, 2012 22:23
RyanTech VIN Explosion API Vehicle Make w/ Asp.Net
// using Asp.net and Json.NET
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://vinexplosion.com/api/");
// credentials
var byteArray = Encoding.ASCII.GetBytes("username:password");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// grab most recent model year
var respYears = client.GetAsync("vehicle/years").Result;
var json = respYears.Content.ReadAsStringAsync().Result;
<?php
$creds = "username:password";
$headers = array("Accept: application/json");
// build the curl request
$request = curl_init();
curl_setopt($request, CURLOPT_URL, "http://vinexplosion.com/api/vin/decode/3GYFNAE36CS509361/?fuzzy=true");
curl_setopt($request, CURLOPT_USERPWD, $creds);
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
// exe the request and gather the code and response
@sirkirby
sirkirby / afts-1.cs
Last active January 3, 2016 09:59
Azure Full Text Search Ex 1
var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=my access key");
var azureDir = new AzureDirectory(storageAccount, "MyIndexBlobContainerName");
@sirkirby
sirkirby / afts-2.cs
Last active January 3, 2016 09:59
Azure Full Text Search Ex 2
var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true,
new IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH));
foreach (var book in Books)
{
var document = new Document();
// store the Id but don't need to index it
document.Add(new Field("Id",
book.BookId.ToString(),
Field.Store.YES,
@sirkirby
sirkirby / afts-3.cs
Last active January 3, 2016 09:59
Azure Full Text Search Ex 3
IndexSearcher searcher = new IndexSearcher(directory);
// for a multi column search
var multiParser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new[] {"Title", "Author"},
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
@sirkirby
sirkirby / afts-4.cs
Last active January 3, 2016 09:59
Azure Full Text Search Ex 4
// parse the query
var query = multiParser.Parse(phrase);
// search the index and return the top 10 best records
var results = searcher.Search(query, 10);
// loop over my top 10 hits and display the results to the console
foreach (var hit in results.ScoreDocs)
{
// gets the document from the hit index
var doc = searcher.Doc(hit.Doc);
// write out the best books matching my phrase