Skip to content

Instantly share code, notes, and snippets.

View jeffdonthemic's full-sized avatar
💭
Currently being awesome

Jeff Douglas jeffdonthemic

💭
Currently being awesome
View GitHub Profile
@jeffdonthemic
jeffdonthemic / datacloud-ingestion-insert.rb
Last active December 7, 2023 15:12
Using the Data Cloud Ingestion to insert records with JWT connected app
require 'jwt'
require "faraday"
require "uri"
def token
private_key = './keys/server.key'
priv_key = OpenSSL::PKey::RSA.new(File.read(private_key))
JWT.encode payload, priv_key, 'RS256'
end
@jeffdonthemic
jeffdonthemic / Gemfile
Last active August 15, 2023 14:46
Salesforce 2GP Packaging CLI
source 'https://rubygems.org'
gem 'restforce', '~> 6.2.2'
gem 'thor'
public class AnimalsCallouts {
public static HttpResponse makeGetCallout() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if(response.getStatusCode() == 200) {
// Deserializes the JSON string into collections of primitive data types.
const jsforce = require('jsforce');
const { exec } = require('child_process');
exec("sfdx org display --json", (error, stdout, stderr) => {
let org = JSON.parse(stdout);
console.log('=================');
console.log(org.result.username);
console.log(org.result.instanceUrl);
console.log('=================');
@jeffdonthemic
jeffdonthemic / signer.rb
Last active May 9, 2023 17:48
Ruby crypto sign/verify
require 'openssl'
require 'base64'
private_key = File.read("./salesforce_private.key")
public_key = File.read("./salesforce_public.key")
data = "reports50"
priv_key = OpenSSL::PKey::RSA.new(private_key)
signature = priv_key.sign_pss("RSA-SHA512", data, salt_length: :digest, mgf1_hash: "RSA-SHA512")
@jeffdonthemic
jeffdonthemic / signer.js
Last active May 4, 2023 17:53
Node crypto sign/verify
const crypto = require('crypto')
const fs = require('fs')
function sign(plainText) {
const sign = crypto.createSign('RSA-SHA512')
sign.update(Buffer.from(plainText, 'utf8'))
signature = sign.sign(
{
key: fs.readFileSync('./salesforce_private.key', 'utf8'),
padding:crypto.constants.RSA_PKCS1_PSS_PADDING
public with sharing class EncryptionService {
// Keys are here for testing purposes. NEVER DO THIS!!!
// Use an approved secrets management solution like Shield Platform Encryption
public static final Blob PRIVATE_KEY = EncodingUtil.base64Decode(
'IMAGE-A-LOT-MORE-LINES-HERE\n' +
'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCS7LXFvLFELXwy\n' +
'UVKIYJEI3j/7b4HUIOJ1IU1la1g2Vr5SKPn+GziMFhFcBjx6LlJxAkJQlOgBOnkO\n' +
'cHC3etOoAsrrRh4LPzZ6CXQeSRjilQnzaCdq2CIu+f8UqVWbwPtb3K/aQAX905Ck\n' +
@jeffdonthemic
jeffdonthemic / clickupservice.cls
Created February 16, 2023 20:25
Apex REST GET
public with sharing class ClickUpTaskService {
private static String apiKey = '';
public static void call() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.clickup.com/api/v2/list/900600512507/task');
request.setMethod('GET');
@jeffdonthemic
jeffdonthemic / do_magic.rb
Last active June 10, 2020 14:49
Delete a file using signed commits
# This code is based upon the following links:
# https://developer.github.com/v3/git/trees/
# https://github.com/testcollab/rails-test
# https://stackoverflow.com/questions/23637961/how-do-i-mark-a-file-as-deleted-in-a-tree-using-the-github-api
# https://git.521000.bestmunity/t/deleting-files-via-trees-no-longer-works/14042
# This creates a signed commit on the correct branch, but there are 0 changed files.
# THIS IS THE METHOD THAT IS CALLED BY THE MAIN PROCESS TO REMOVE FILES
@jeffdonthemic
jeffdonthemic / do_magic.rb
Last active June 5, 2020 19:29
Remove github files from tree
# https://git.521000.bestmunity/t/deleting-files-via-trees-no-longer-works/14042
def commit_files_to_remove
# get the base branch tree that has all of the files in it
branch_tree = github.git_data.trees.get @repo.username,
@repo.repo_name,
new_branch_sha,
recursive: true
# select only the files for THIS badge