Skip to content

Instantly share code, notes, and snippets.

View shanerk's full-sized avatar
Wizards only, fools!

Shane K shanerk

Wizards only, fools!
View GitHub Profile
@shanerk
shanerk / ApexDmlUtil.java
Last active December 13, 2018 15:08
Apex Generic method to process Database.SaveResults
public with sharing class ApexDmlUtil {
public void processSaveResults(List<Database.SaveResult> results) {
List<String> errors;
for (Database.SaveResult r : results) {
if (!r.isSuccess()) {
RAL_MetricService.increment(RAL_MetricService.Metric.Errored, this.file.Id);
errors = new List<String>();
for (Database.Error e : r.errors) {
errors.add(e.message);
}
@shanerk
shanerk / .gitignore
Created December 28, 2018 20:04 — forked from leosoto/bb2gh.sh
Moves all your organization's bitbucket repositories to GitHub. Note that when a repository is correctly uploaded to GitHub it is *removed* from BitBucket. Requires https://bitbucket.org/zhemao/bitbucket-cli/. Set the variables BB_* with your bitbucket credentials and GH_* variables with your GitHub credentials.
env.sh
*.git
@shanerk
shanerk / crypto.java
Last active January 4, 2019 01:45
Using Crypto in Apex for Fun and Profit
// Using Crypto for a Random string
nickname += String.valueOf(Crypto.getRandomInteger()).substring(1,7);
// Using Crypto to create a GUID
// TODO
@shanerk
shanerk / gitclean.sh
Created April 8, 2019 18:16
Git Script to Delete Local Branches Removed from the Remotes
# Creates alias which does the following:
# 1. Changes to master branch
# 2. Performs a fetch
# 3. Attempts to delete branches which have been removed from remote
# 4. Performs a verbose branch list
alias gitclean="git checkout master; git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done; git branch -vv"
@shanerk
shanerk / shaner.terminal
Created April 8, 2019 20:21
Awesome OSX Terminal Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundAlphaInactive</key>
<real>0.80000000000000004</real>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGKyxYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKcHCBMZHSQoVSRudWxs1QkKCwwNDg8QERJcTlNDb21wb25lbnRzVU5TUkdCXE5T
@shanerk
shanerk / DelegateApex.cls
Last active April 9, 2019 16:52
Delegation Example in Salesforce Apex
public class DelegateApex {
public interface SObjectDelegate {
List<SObject> getObject(String search);
}
public class AccountDelegate implements SObjectDelegate {
public List<SObject> getObject(String searchVar) {
List<Account> accounts = [SELECT Id, Name
FROM Account
@shanerk
shanerk / ApexDeprecated.cls
Created April 29, 2019 16:41
Apex Packages & @deprecated Annotation
global with sharing class ApexDeprecated {
@Deprecated
global enum FOOBAR { FOO, BAR }
// Not Allowed - Deprecated FOOBAR return type illegal in global
global static FOOBAR bar(Integer ord) {
return FOOBAR.values()[ord];
}
// Allowed - Deprecated type is not exposed globally, so can still be used internal to the method
/**
* Checks and converts strings when they contain accounting negative format ($1,000.00)
* to standard negative format -$1,000.00
*
* @param str Input String to evaluate
*
* @return String containing converted value, or original value if there was no match found
*/
public static String toStandardNegative(String str) {
Pattern negPattern = Pattern.compile('^\\((.+)\\)$');
@shanerk
shanerk / undentBlock.js
Last active July 17, 2019 01:41
Un(in)dents a block of text (removing unwanted whitespace at the beginning of a line, but preserving desired indentation)
function undentBlock(block) {
let REGEX_INDEX = /^[ \t]*\**[ \t]+/g;
let indent = null;
block.split("\n").forEach(function (line) {
let match = line.match(REGEX_INDEX);
let cur = match !== null ? match[0].replace(/\*/g, "").length : null;
if (cur < indent || indent === null) indent = cur;
});
let ret = "";
block.split("\n").forEach(function (line) {
@shanerk
shanerk / ParseEmailHeaders.cls
Created September 13, 2019 16:39
ParseEmailHeaders.cls
public with sharing class ParseEmailHeaders {
public Map<String, String> parseEmailHeaders(String headers) {
Map<String, String> headersMap = new Map<String, String>();
List<String> rows = headers.split('\n');
for (String row : rows) {
Integer div = row.indexOf(':');
String rowKey = row.substring(0, div).trim();
String rowValue = row.substring(div + 1, row.length()).trim();
String existingValue = headersMap.get(rowKey);
if (existingValue != null) {