Skip to content

Instantly share code, notes, and snippets.

View cmbaughman's full-sized avatar
🎯
Focusing

Chris Baughman cmbaughman

🎯
Focusing
View GitHub Profile
@cmbaughman
cmbaughman / undelete.sh
Created April 10, 2015 13:24
OSX Undelete Text Files
#!/bin/bash
# USE diskutil list to get the disk and "slice"
sudo grep --binary-files=text --context=10 '192.168.1.196' /dev/disk0 > recovered.txt
@cmbaughman
cmbaughman / create_ssh_key.sh
Created April 12, 2015 15:22
Simple script to create you a new RSA key.
#!/bin/bash
echo "Enter the email address you want to associate with this key, followed by [ENTER] "
read EMAIL
ssh-keygen -t rsa -C "$EMAIL"
echo "Enter the path and name of the key you just created: "
read SSHKEY
@cmbaughman
cmbaughman / query.cls
Last active May 11, 2017 06:01
Salesforce Apex Query with Wildcard
public static String getAllQuery(String query) {
String result = '';
String regex = '^select\\s+\\*\\s*(?:,\\s*[^\\s]+\\s*)*\\s+from\\s+([^\\s]+)(.*)$';
Matcher m = Pattern.compile(regex).matcher(query.toLowerCase());
if(m.matches()) {
String sObjectName = m.group(1);
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(sObjectName);
Map<String, Schema.SObjectField> fieldMap = targetType.getDescribe().fields.getMap();
@cmbaughman
cmbaughman / LeadToContactTrigger.md
Last active August 29, 2015 14:19
Salesforce (Apex) Lead to Contact,Account,Opportunity Conversions

Salesforce Lead to Contact Conversions

Here's a simple service class to perform manual Lead to Contact, Account, and Opportunity conversions with souped up built in duplicate checking! (You loose the SF dup checking by using a trigger to customize it, plus it doesn't do all of this as of now.)

public with sharing class LeadToContactTrigger {
	private final List<Lead> leadList;
	private final List<Contact> contList = [ SELECT Id, Name, firstname, lastname, Phone, Email, MailingPostalcode, MailingStreet FROM Contact  ];
	private LeadStatus convertStatus =  [ SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true ];
	private List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
#!/bin/bash
usage ()
{
cat <<UsageHERE
boot2docker-fwd -- Helper function to quickly manage port forwards between the boot2docker-vm and the host
Usage: boot2docker-fwd [ -n RULE_NAME ] [ -h HOST_PORT ] [ -p {tcp|udp} ] [ -i HOST_IP ] GUEST_PORT
or boot2docker-fwd -d RULE_NAME
or boot2docker-fwd -l
or boot2docker-fwd -A
@cmbaughman
cmbaughman / sf_to_wp_sso.md
Created May 1, 2015 19:00
Set up Salesforce as an Identity Provider for Single Sign On with Wordpress

##Wordpress Side:

  1. On WP install the plugin SAML 2.0 Single Sign-On

  2. Once installed, copy and paste into an email the section “Your SAML Info”

  3. Make sure to check only the box labeled ‘Allow SSO Bypass’.

  4. Click Service Provider tab and put a check in the “Generate new certificate and private key for me.” then click update at the bottom of the page.

@cmbaughman
cmbaughman / wordpress_encryption_fragment.php
Created May 7, 2015 13:17
Functions to decrypt and encrypt Wordpress passwords from plugin.
<?php
/* These need to go in your custom plugin (or existing plugin) */
private function encrypt($input_string, $key){
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$h_key = hash('sha256', $key, TRUE);
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $h_key, $input_string, MCRYPT_MODE_ECB, $iv));
}
@cmbaughman
cmbaughman / zshconf.md
Last active August 29, 2015 14:21
My ZShell Aliases

My ZShell Aliases

These are just a few of my favorite aliases for zshell. I'll keep this list up to date as I find and/or create them. Simply put these into your ~/.zshrc file.

alias zshconfig="atom ~/.zshrc"
alias path="echo ${PATH//:/$'\n'}"
alias reload="source ~/.zshrc"
# My functions
docker-ip() {
@cmbaughman
cmbaughman / MetadataBulkTest.apex
Created June 10, 2015 17:24
Example of using the Metadata API in Salesforce Apex to create a ton of checkboxes based on an array.
public with sharing class MetadataBulkTest {
public MetadataBulkTest() { }
public static void createFields() {
List<String> bigList = new List<String> {'LMSW', 'Caregiving', 'LMT', 'French', 'Art Therapy', 'PMS/PMDD', 'OCD', 'Magellen Behavioral Health', 'Psychopharmacology', 'Pastoral Care', 'Lactation Consultant', 'Empire', 'Chiropractic', 'Body Image', 'PsyD', 'Divorce', 'Couples', 'DC', 'Eating Disorders', 'Consolidated Health Plan', 'Nutritionist/Dietician', 'Gender Identity', '1199/SEIU', 'MagnaCare', 'Clinical Administrative', 'Gestalt', 'NP', 'High Risk Pregnancy', 'Special Needs', 'Pregnant Women', 'Relationship Issues', 'Cigna', 'Life Coach', 'PTSD', 'Somatic Pain', 'Postpartum Doula', 'Reproductive Endocrinologist', 'Hebrew', 'Workshop/Class', 'Psychodynamic', 'GHI', 'EMDR', 'Researcher', 'Trauma', 'Infants', 'Community Advocate', 'Relational', 'Domestic Abuse', 'LCAT', 'DBT', 'Outpatient', 'Eclectic', 'Chronic Pain/Medical Illness', 'General Practitioner', 'EdD', 'Menopause', 'Senior Citize
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");