Skip to content

Instantly share code, notes, and snippets.

View oheyandy's full-sized avatar

Andrew Frauen oheyandy

  • Salesforce
  • San Francisco
View GitHub Profile
@oheyandy
oheyandy / gist:886131f91c767af1c827
Last active August 29, 2015 14:13
JS snippets to make bulk-changes to admin easier
// delete resources from an admin page
// zero chance of recovering deleted data, so BE VERY CAREFUL WITH THIS
$(".a-delete.a-alert-trigger").trigger('click'); $(".a-button.a-button-secondary.a-alert-delete.a-small").trigger('click')
@oheyandy
oheyandy / helpscout.rb
Created October 8, 2014 00:03
Quick and dirty api helper for HelpScout from ages ago.
class HelpScout
include HTTParty
base_uri 'https://api.helpscout.net'
def initialize(api_key)
@auth = {username: api_key, password: 'x'}
end
def customers(page=1, options={} )
options.merge!({query: {page: page}})
@oheyandy
oheyandy / hide_fields
Last active August 29, 2015 14:07
Conditionally show/hide fields in Desk.com customer theme based on whether customer title field contains a specific word/phrase
####################################################################
## Always hide certain fields if title field contains 'MATCH_PHRASE'
####################################################################
{% assign do_not_render = customer.title | scan: 'MATCH_PHRASE' | size %}
{% unless do_not_render > 0 %}
<!-- HTML/Liquid to be hidden when title includes 'MATCH_PHRASE' -->
{% endif %}
@oheyandy
oheyandy / Gemfile
Last active August 29, 2015 14:06
Rough script demonstrating how to write data from the Desk.com /api/v2/insights3 API endpoint to CSV
source 'https://rubygems.org'
gem 'desk_api', '~> 0.6.1'
gem 'rake'
@oheyandy
oheyandy / encoding_hack.rb
Created September 16, 2014 00:33
memo to self for next time arbitrary encodings are an issue.
require 'pathname'
base_path = Pathname.new(File.expand_path('../', __FILE__))
Dir[base_path.join('translation_sources', '*.xml')].each do |source|
# only put cmd in a local var because #{} interpolation
# uglifies syntax highlighting w/ %x()
cmd = "file --mime-encoding #{source}"
source_encoding = %x(cmd)[(source.length + 2)..-2]
@oheyandy
oheyandy / conditional.html
Created April 16, 2014 18:37
Display fields in Desk.com case theme depending on whether or not a label is present
<!--
In this example assume we have some cases which are creatd with the a label called "Display Custom Field"
And ONLY when this label is present on a case we want to display a Case Custom Field on teh case theme called "Awesome List"
You would use the following (walkthrough of the logic below):
-->
<!--=======-->
<!--Snippet-->
@oheyandy
oheyandy / go_to_case.html
Last active August 29, 2015 13:57
Simple HTML example of how to implement an input on Private Portal-enabled support centers to direct customer to case page.
<form action="get" id="go_to_case">
<div><input type="text" id="case_id" name="case_id" placeholder="Enter Case ID"></div>
<div><button type="submit">Go to Case</button></div>
</form>
<script type="text/javascript">
$('#go_to_case').on({
submit: function(e) {
e.preventDefault();
var case_path = "/customer/portal/private/cases/" + document.getElementById('case_id').value;
window.location.href = case_path;
@oheyandy
oheyandy / setting_form_fields_via_query_string.html
Created February 19, 2014 18:39
Example of how to append labels to cases submitted from Desk.com email form via query string in the URL
<!-- Example link -->
<a href="https://SUBDOMAIN_GOES_HERE.desk.com/customer/portal/emails/new?ticket[labels_new]=LABEL_GOES_HERE">Email Form</a>
<!-- Example iframe -->
<iframe src="https://SUBDOMAIN_GOES_HERE.desk.com/customer/portal/emails/new?ticket[labels_new]=LABEL_GOES_HERE" frameborder="0"></iframe>
@oheyandy
oheyandy / autocomplete_highlight.html
Created February 13, 2014 02:39
JavaScript example how how to implement highlighting on matching text from search autocomplete in Desk.com support centers.
<!-- Past this script in your header -->
<script type="application/javascript">
$(function(){
// Enter CSS declarations for highlighted below
var highlight_css = "background-color: yellow;";
$("#q").bind("autocompleteopen", function(event, ui) {
var query_text = $('#q').val();
var queries = query_text.split(' ');
var search_results = $('.article-autocomplete-body, .article-autocomplete-subject');
@oheyandy
oheyandy / render_snippet_html.html
Last active August 29, 2015 13:56
Allow Desk.com snippets to render HTML in web themes with a jQuery function
<!--First, create a custom snippet in Desk and include some basic HTML in the "Custom Text" area-->
<!--Documentation:
https://support.desk.com/customer/portal/articles/566489-using-snippets-in-your-help-center-->
<!--Put the snippet in your theme twice, and wrap one of them in a div with a class of "render_snippet_html" -->
<div>
This snippet will display as raw HTML: {{system.snippets.testhtml}}
</div>
<div>
This snippet will display as bold: <span class="render_html_snippet">{{system.snippets.testhtml}}</span>