Skip to content

Instantly share code, notes, and snippets.


Thomas Stachl tstachl

View GitHub Profile
tstachl / implementation.html
Created Aug 23, 2012
NodeProxy implementation
View implementation.html
function callback() {
$.widget('', $.ui.autocomplete, require('contact'));
$('.salesforce input').contact({
category: 'company',
username: 'username',
password: 'password',
clientId: 'SalesforceClientId',
clientSecret: 'SalesforceClientSecret',
mapping: {
tstachl / gist:4132052
Created Nov 22, 2012
SSEGeoService allows you to set the new Geolocation fields of any object by running an address string through the Google Geolocation API.
View gist:4132052
public class SSEGeoService
class GeoException extends Exception {}
@future (callout=true)
static public void setLocation(String sobj, String field, String id, String address)
if (String.isBlank(address)) {
throw new SSEGeoService.GeoException('Address can not be blank.');
tstachl /
Created Apr 6, 2013 Multipass SSO example.
import org.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
import java.util.Arrays;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
tstachl /
Created Apr 13, 2013
Example talking to the API from Salesforce (Apex).
public class DeskSample
private static String OAUTH_KEY = 'youroauthkey';
private static String OAUTH_SECRET = 'youroauthsecret';
private static String ACCESS_TOKEN = 'youraccesstoken';
private static String ACCESS_TOKEN_SECRET = 'youraccesstokensecret';
public static String DESK_SITENAME = 'yoursite';
public static Void doRequest()
tstachl / oauth.php
Created May 28, 2013 OAuth with php.
View oauth.php
$subdomain = 'your-sitename';
$req_url = 'https://'.$subdomain.'';
$authurl = 'https://'.$subdomain.'';
$acc_url = 'https://'.$subdomain.'';
$api_url = 'https://'.$subdomain.'';
$callback = 'http://localhost:3000/auth/desk/callback';
tstachl / create_customer.ps1
Created Aug 13, 2013
This is a PowerShell v2 script that performs a simple customer creation action on the API and outputs the status text. Either "created" if the customer has been created or "Unprocessable Entity" if a customer with the same email already exists.
View create_customer.ps1
function createCustomer($first_name, $last_name, $title, $background, $email) {
$subdomain = "your-site-subdomain"
$username = ""
$password = "YoUrPaSsWoRd"
$body = @"
"first_name": "$first_name",
"last_name": "$last_name",
"title": "$title",
"background": "$background",
tstachl / api_content_type.rb
Created Aug 18, 2013
This is a simple Rack Middleware to set the request content type for specific routes. It checks if a content type is set and does not override the existing one. The options allow you to specify the request methods, path (with a string or a regular expression) and the content type to be set.
View api_content_type.rb
module Rack
class ApiContentType
def initialize(app, methods = [:post, :patch], path = /^\/api\/v2+/, content_type = 'application/json')
@app = app
@methods = (methods.is_a?(Array) ? methods : [methods]).map{ |item| item.to_s.upcase }
@path = path
@content_type = content_type
def call(env)
tstachl / mongoid_encrypted.rb
Last active Dec 21, 2015
Monkey patch field encryption into Mongoid.
View mongoid_encrypted.rb
class Mongoid::Fields::Standard
# Is the field encrypted or not?
# @example Is the field encrypted?
# field.encrypted?
# @return [ true, false ] If the field is encrypted.
# @since 4.0.0
def encrypted?
tstachl / google_apps_post_request.js
Created Sep 12, 2013
Creating a new email case using Basic Auth from Google Apps Script.
View google_apps_post_request.js
var url = "";
var options = {
"method": "post",
"headers": {
"Authorization": "Basic " + Utilities.base64Encode("")
"payload": {
"type": "email",
"subject": "Email Case Subject",
"priority": 4,
tstachl /
Created Sep 24, 2013 Multipass script written in python.
from Crypto import Random
from Crypto.Cipher import AES
from datetime import datetime, timedelta
from isodate import datetime_isoformat
import base64
import hashlib
import hmac
import urllib
import json