Skip to content

Instantly share code, notes, and snippets.

View dschach's full-sized avatar

David Schach dschach

View GitHub Profile
@stephenlf
stephenlf / strip-trailing-newlines.js
Last active January 15, 2026 20:29
Simple node script to remove trailing newlines and carriage returns from files. Addresses issues associated with prettier, Salesforce source tracking, and git diff.
#!/usr/bin/env node
/**
* This script removes trailing newlines and carriage returns from files.
*
* Read related issue
* https://github.com/prettier/prettier/issues/6360#issuecomment-3380097220
*
* By default, SFDX installs a prettier pre-commit git hook. Prettier always adds
* newlines to the end of files. Salesforce strips those newlines away. This leads
@jongpie
jongpie / UniqueIdBenchmarkingTests.cls
Created January 30, 2024 00:23
Apex - Unique ID Generation Benchmarks
@IsTest
private class UniqueIdBenchmarkingTests {
@IsTest
static void ulidBenchmark() {
Long ulidStartTime = System.now().getTime();
System.debug('ULID generation start: ' + System.now().getTime());
for (Integer i = 0; i < 1000; i++) {
ULID.generate();
}
Long ulidStopTime = System.now().getTime();
@peterknolle
peterknolle / preChat.html
Created January 25, 2014 23:15
Live Agent Pre-Chat API in Pre-Chat Form for Service Cloud
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
(function() {
function handlePageLoad() {
var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
document.getElementById('prechatForm').setAttribute('action',
decodeURIComponent(endpointMatcher.exec(document.location.search)[1]));
}
@metadaddy
metadaddy / MessageToTask.cls
Last active December 23, 2015 00:49
Visualforce TwiML page and Apex REST method for transcribing a voice message in Twilio and saving is as an Activity to a Lead.
@RestResource(urlMapping='/messagetotask')
global class MessageToTask {
@HttpPost
global static void incomingMessage() {
String expectedSignature =
RestContext.request.headers.get('X-Twilio-Signature');
String url = 'https://' + RestContext.request.headers.get('Host') +
'/services/apexrest' + RestContext.request.requestURI;
Map <String, String> params = RestContext.request.params;
@joshbirk
joshbirk / geocontact.page
Created October 8, 2012 21:27
Geolocation
<apex:page StandardController="Contact" showHeader="true" sidebar="false">
<script>
var pos = {};
function success(position) {
pos = position.coords;
console.log(pos);
}
function error(msg) {