Skip to content

Instantly share code, notes, and snippets.

View metadaddy's full-sized avatar

Pat Patterson metadaddy

View GitHub Profile
metadaddy / decodeIdToken.js
Created April 4, 2014 18:49
Decode a JSON Web Token (JWT), verifying against a bare RSA key
var jwt = require('jwt-simple');
var getpem = require('rsa-pem-from-mod-exp');
// Decode JWT token, verify with the relevant key from the supplied
// array
function decodeIdToken(idtoken, keys, code) {
var header = JSON.parse(new Buffer(idtoken.split('.')[0], 'base64').toString('utf8'));
for (var i = 0; i < keys.length; i++) {
if (keys[i].kid === header.kid) {
metadaddy /
Created April 10, 2014 20:31
S1 Visualforce page to create a case with location
<apex:page controller="CreateCaseCon" docType="html-5.0" showHeader="false">
html, body {
height: 100%;
h3 {
display: block;
margin-top: 30px;
margin-bottom: 10px;
metadaddy / PatTest.cls
Created June 4, 2014 21:08
Extract all field names from an SObject to use in a query
public class PatTest {
public static void queryAllFields(String objTypeName) {
Schema.DescribeSObjectResult[] descResult =
Schema.describeSObjects(new String[]{objTypeName});
Map<String, Schema.SObjectField> fsMap = descResult[0].fields.getMap();
List<String> fieldNames = new List<String>(fsMap.keySet());
String queryString = 'SELECT '+String.join(fieldNames, ',')+' FROM Account LIMIT 1';
SObject obj = Database.query(queryString);
// Registration handler to create internal users from a Google social sign-on
global class GoogleRegHandler implements Auth.RegistrationHandler{
global boolean canCreateUser(Auth.UserData data) {
// TODO: Check whether you want to allow creation of a user with this data
// e.g. test the domain name on the email address, or check some list
// somewhere, and return true as appropriate
return false;
metadaddy / app.js
Created February 24, 2015 20:49
Read Twitter handles and hashtags from Salesforce (via Heroku Connect), then subscribe to matching tweets and insert them in a Postgres table
var Twitter = require('twitter');
var pg = require('pg');
var tw = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
metadaddy / Agent
Created May 4, 2015 23:17
Press a button on the Electric Imp to upsert a record in Salesforce
#require "Salesforce.class.nut:1.0.0"
force <- Salesforce("CLIENT_ID_GOES_HERE",
PASSWORD <- "p455w0rd";
SECURITY_TOKEN <- "s3cr3t";
force.login(USERNAME, PASSWORD, SECURITY_TOKEN, function(err, data) {
metadaddy / Agent
Last active August 29, 2015 14:23
Run OAuth from the Agent, log 9DOF data from device, including click events
#require "Salesforce.class.nut:1.0.0"
// Uncomment to clear saved OAuth state
OAUTH <- server.load();
metadaddy / sessionTimeout.js
Created July 3, 2015 00:07
Retrieve session timeout from Salesforce via Metadata API in Node.js
var jsforce = require('jsforce');
var unzip = require('unzip');
var xml2js = require('xml2js');
var sessionTimeoutSeconds = {
FifteenMinutes : 900,
ThirtyMinutes : 1800,
SixtyMinutes : 3600,
TwoHours : 7200,
FourHours : 14400,
metadaddy /
Created August 31, 2015 21:51
Get job/batch status correctly with BulkTK
<apex:page docType="html-5.0" title="Bulk Uploader" sidebar="false">
<div id="byte_content"></div>
<input type="file" id="files" onchange="upload()"/>
<script src="" type="text/javascript"></script>
<script src="{!$Resource.forcetk}"></script>
<script src="{!$Resource.jxon}"></script>
<script src="{!$Resource.bulkTK}"></script>
<script src="{!$Resource.vkbeautify}"></script>
function readBlob(opt_startByte, opt_stopByte) {
metadaddy /
Created November 2, 2011 16:01
Set login IP ranges via the Metadata API
package com.force.samples;
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.metadata.AsyncRequestState;
import com.sforce.soap.metadata.AsyncResult;
import com.sforce.soap.metadata.MetadataConnection;
import com.sforce.soap.metadata.Profile;
import com.sforce.soap.metadata.ProfileLoginIpRange;
import com.sforce.soap.metadata.UpdateMetadata;