Skip to content

Instantly share code, notes, and snippets.

View rruhlen's full-sized avatar

Ricky Ruhlen rruhlen

  • San Francisco, CA
View GitHub Profile
@rruhlen
rruhlen / zd_load_temp_db.rb
Created February 21, 2013 21:59
Ruby script to load the ZD data into your temporary MySQL tables.
require 'nokogiri'
require 'rubygems'
require 'sequel'
#Connect to DB
DB = Sequel.connect(:adapter=>'mysql', :host=>'127.0.0.1', :database=>'zd_name', :user=>'root', :password=>'')
user_table = DB[:zd_users]
tickets_table = DB[:zd_tickets]
comments_table = DB[:zd_comments]
@rruhlen
rruhlen / zd_create_cases_ad.rb
Created February 21, 2013 22:04
Ruby script to import the cases into Desk.
# http://sequel.rubyforge.org/rdoc/files/doc/cheat_sheet_rdoc.html
require 'rubygems'
require 'json'
require 'sequel'
require 'oauth'
require 'yajl'
require 'yaml'
SITE_URL = "https://XXXX.desk.com"
API_CONSUMER_KEY = ""
@rruhlen
rruhlen / sql_commands.txt
Created February 21, 2013 22:29
SQL commands to Create Temporary MySQL tables.
1. Create Table to Import Users
CREATE TABLE `zd_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`zd_id` int(11) DEFAULT NULL,
`desk_id` int(11) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`role` varchar(255) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
@rruhlen
rruhlen / customers.rb
Created August 1, 2013 21:47
loop through customer records
url = "/api/v2/customers"
begin
response = JSON.parse desk_client.get url
response['_embedded']['entries'].each do |customer|
desk_client.patch customer['_links']['self']['href'], {
custom_fields: {
some_field: 'Some Value'
}
}
@rruhlen
rruhlen / customers.rb
Created August 1, 2013 21:47
loop through customer records
url = "/api/v2/customers"
begin
response = JSON.parse desk_client.get url
response['_embedded']['entries'].each do |customer|
desk_client.patch customer['_links']['self']['href'], {
custom_fields: {
some_field: 'Some Value'
}
}
@rruhlen
rruhlen / desk_sso.vb
Created August 6, 2013 17:48
VB.net example for Desk.com SSO
Public Class UserData
Public uid As String
Public expires As String = DateTime.Now.AddDays(1).ToString("s",
System.Globalization.CultureInfo.InvariantCulture)
Public customer_email As String
Public customer_name As String
End Class
Public Class MultiPass
Public status As Boolean = False
@rruhlen
rruhlen / mobile.js
Created September 9, 2013 19:51
Javascript to detect a mobile device
$(function() {
(function(a){(jQuery.browser=jQuery.browser||{}).mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|j
@rruhlen
rruhlen / multipass_sso
Created September 12, 2013 18:55
Multipass SSO Java example for Desk.com
package com.meetup.util.desk;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.meetup.util.MeetupLogger;
import com.meetup.base.util.U;
@rruhlen
rruhlen / suggest_articles.js
Created September 16, 2013 22:23
you can show suggested articles based on the subject you enter by sending an AJAX request to https://site.desk.com/customer/portal/articles/autocomplete?term=SUBJECT. This request returns a json formatted array of possible articles. We run through that result set and create a link to those articles in the list.
// run as soon as we have input in the subject field
$(‘#subject_input’).on(‘keyup’, function() {
// get the subject
var term = $(this).val();
// run the request – make sure to url encode the subject
$.getJSON(‘https://site.desk.com/customer/portal/articles/autocomplete?term=’ + encodeURIComponent(term), function(response) {
// empty the previous list
$(‘#thelist’).empty();
// for each article returned from the request
$.each(response, function(index, article) {
@rruhlen
rruhlen / translate_article_rating.js
Created September 17, 2013 19:43
jQuery to change the 'Thumbs up text', 'Thumbs down text', and 'Thank you text' to what you want it to be.
<script type="text/javascript">
$(function(){
$("#rate_article div:nth-child(1) a").click(function(){
$("#rate_article").css("visibility", "hidden");
window.setTimeout(showHello, 1000);
}).next().text("Thumbs Up text");
$("#rate_article div:nth-child(2) a").click(function(){
$("#rate_article").css("visibility", "hidden");
window.setTimeout(showHello, 1000);