Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
global class FetchGroupsAndUsers implements Schedulable, Database.Batchable<DeskResource>, Database.AllowsCallouts
{
public static String CRON_EXPRESSION = '0 0 0 * * ? *';
global static final DeskClient DESK_CLIENT = new DeskClient(new Map<String, String>{
'username' => 'support@example.com',
'password' => 'somepassword',
'subdomain' => 'devel'
});
'use-strict'
Emitter = require 'emitter'
_ = require 'lodash'
binder = require 'binder'
module.exports = class DrawingTracker extends Emitter
constructor: (@_element, visible = no) ->
if typeof this._element == 'string' or this._element instanceof String
this._element = document.getElementById this._element
@tstachl
tstachl / DeskTriggerHelper.class
Last active November 21, 2016 19:43
Fetch data trigger.
public class DeskTriggerHelper
{
private static DeskClient CLIENT = new DeskClient(new Map<String, String>{
'token' => 'TOKEN',
'tokenSecret' => 'TOKEN_SECRET',
'consumerKey' => 'CONSUMER_KEY',
'consumerSecret' => 'CONSUMER_SECRET',
'endpoint' => 'https://example.desk.com'
});
@tstachl
tstachl / unzip.rb
Created August 25, 2014 17:38
Unzip to S3
Zip::ZipFile.open(zipfile) do |zip|
zip.each do |f|
path = File.join('/your/aws/path', f.name)
aws = AWS::S3.new.buckets['yourbucket'][path]
aws.write(file: zip.get_output_stream(f))
aws_url = aws.public_url(secure: true).to_s
end
end
end
def parse_signed_request(request, max_age=3600)
# Split the signed request on the first period. The result is two strings: the hashed Based64 context signed with the consumer secret and the Base64 encoded context itself.
encoded_sig, enc_envelope = request.split('.', 2)
envelope = JSON.parse(base64_url_decode(enc_envelope)).with_indifferent_access # Needs ActiveSupport
algorithm = envelope[:algorithm]
# ADDITIONAL: Check the algorithm is HMAC SHA-256
if algorithm != 'HMACSHA256'
raise 'Invalid request. (Unsupported algorithm.)'
end
@tstachl
tstachl / desk_oauth.php
Created September 1, 2016 03:27
Working example of Desk.com OAuth flow with PHP.
<?php
$req_url = 'https://YOURSITE.desk.com/oauth/request_token';
$authurl = 'https://YOURSITE.desk.com/oauth/authorize';
$acc_url = 'https://YOURSITE.desk.com/oauth/access_token';
$api_url = 'https://YOURSITE.desk.com/api/v2';
$conskey = 'CONSUMER_KEY';
$conssec = 'CONSUMER_SECRET';
$cbk_url = 'http://localhost:3000';
session_start();
@tstachl
tstachl / Note.user.js
Last active August 18, 2016 17:32
This is a quick user script that hooks into the 'desk.agent.case.detail' state and clicks the note button as soon as it is available.
// ==UserScript==
// @name Note
// @namespace http://www.desk.com/
// @version 0.2
// @description This script defaults new interactions in Desk.com Next Gen Agent to note rather than reply.
// @author Thomas Stachl <tstachl@salesforce.com>
// @match https://*/web/agent*
// @grant none
// ==/UserScript==
@tstachl
tstachl / create_contact.js
Last active July 13, 2016 00:05
Salesforce Snippet - Allows you to create a contact for an account by domain matching.
/**
* USAGE Information
* 1. open the developer tools for a salesforce classic site
* 2. copy and paste the code of this snippet into the console
* 3. `createFromEmail('John Snow <john@nightswatch.com>').
*
* WHAT does the script do?
* 1. it parses the email string into name and email address
* 2. it runs an API search for an account with the website `https://www.nightswatch.com/`
* 3. it splits the name part `John Snow` into firstname and lastname
@tstachl
tstachl / google_apps_post_request.js
Created September 12, 2013 17:13
Creating a new desk.com email case using Basic Auth from Google Apps Script.
var url = "https://yoursitename.desk.com/api/v2/cases";
var options = {
"method": "post",
"headers": {
"Authorization": "Basic " + Utilities.base64Encode("you@example.com:yourpassword")
},
"payload": {
"type": "email",
"subject": "Email Case Subject",
"priority": 4,
function base64UrlDecode(str) {
str = (str + '===').slice(0, str.length + (str.length % 4));
return new Buffer(str.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8');
}
function readSecret() {
return process.env.DESK_SHARED_KEY;
}
module.exports = {