Skip to content

Instantly share code, notes, and snippets.


Pat Patterson metadaddy

View GitHub Profile
metadaddy / decodeIdToken.js
Created Apr 4, 2014
Decode a JSON Web Token (JWT), verifying against a bare RSA key
View decodeIdToken.js
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 Apr 10, 2014
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 Jun 4, 2014
Extract all field names from an SObject to use in a query
View PatTest.cls
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);
View GoogleRegHandler.cls
// 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 Feb 24, 2015
Read Twitter handles and hashtags from Salesforce (via Heroku Connect), then subscribe to matching tweets and insert them in a Postgres table
View app.js
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
Press a button on the Electric Imp to upsert a record in Salesforce
View Agent
#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 Aug 29, 2015
Run OAuth from the Agent, log 9DOF data from device, including click events
View Agent
#require "Salesforce.class.nut:1.0.0"
// Uncomment to clear saved OAuth state
OAUTH <- server.load();
metadaddy / sessionTimeout.js
Created Jul 3, 2015
Retrieve session timeout from Salesforce via Metadata API in Node.js
View sessionTimeout.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 Aug 31, 2015
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 Nov 2, 2011
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;