Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Stachl tstachl

View GitHub Profile
@tstachl
tstachl / create_user.sh
Created Feb 20, 2018
Steps I took to create a sudo user on my Digital Ocean Droplet (Ubuntu).
View create_user.sh
# SSH as root to your Digital Ocean Droplet
ssh root@[DROPLET_IP]
# create the new user
adduser example
# add new user to the sudo group
gpasswd -a example sudo
# logging in with the new user
su - example
@tstachl
tstachl / desk_oauth.php
Created Sep 1, 2016
Working example of Desk.com OAuth flow with PHP.
View desk_oauth.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();
View custom_search.html
<!doctype html>
<html>
<head>
<script src="//ajax.deskapi.com/libs/desk/opencti/current/interaction.min.js"></script>
<script>
(function() {
desk.ready(function() {
var form = document.querySelector('form')
, text = document.querySelector('input')
@tstachl
tstachl / Client.cs
Created Aug 19, 2016
Desk.com API Client for C#
View Client.cs
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace DeskApi
{
/// <summary>
@tstachl
tstachl / Note.user.js
Last active Aug 18, 2016
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.
View Note.user.js
// ==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 Jul 13, 2016
Salesforce Snippet - Allows you to create a contact for an account by domain matching.
View create_contact.js
/**
* 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
View signed_request.js
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 = {
View screenpop.js
desk.ready(function() {
desk.interaction.ajax('/api/v2/customers/search?email=tstachl%40salesforce.com', {
method: 'GET',
callback: function(data) {
if (data.status === 200 && data.payload.total_entries > 0) {
var customer = data.payload.entries.first;
desk.interaction.screenPop(customer.id, 'object=customer', function(response) {
if (response.result) {
alert('screenPop successful.');
} else {
View signed_request.rb
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
View server.js
#!/usr/bin/env node
var resolve = require('path').resolve
, connect = require('connect')
, https = require('https')
, fs = require('fs');
var server = connect()
, path = resolve('.')
, port = process.env['PORT'] || 3000;
You can’t perform that action at this time.