Skip to content

Instantly share code, notes, and snippets.

💭
Currently being awesome

Jeff Douglas jeffdonthemic

💭
Currently being awesome
View GitHub Profile
@jeffdonthemic
jeffdonthemic / do_magic.rb
Last active Jun 10, 2020
Delete a file using signed commits
View do_magic.rb
# 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://github.community/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 Jun 5, 2020
Remove github files from tree
View do_magic.rb
# https://github.community/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
@jeffdonthemic
jeffdonthemic / app.js
Created Jul 7, 2014
Simple socket.io example
View app.js
var http = require('http'),
fs = require('fs'),
// NEVER use a Sync function except at start-up!
index = fs.readFileSync(__dirname + '/index.html');
// Send index.html to all requests
var app = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
});
View org_connection.js
const jsforce = require('jsforce');
const jwt = require("salesforce-jwt-bearer-token-flow");
// create the connection to the org
let conn = new jsforce.Connection();
// load the private key for the token
let privateKey = require('fs').readFileSync('./server.key', 'utf8');
jwt.getToken({
@jeffdonthemic
jeffdonthemic / restforce.rb
Created Jan 24, 2020
Restforce monkey patch
View restforce.rb
module Restforce
class Mash < Hashie::Mash
class << self
def klass(val)
if val.key? 'records'
# When the hash has a records key, it should be considered a collection
# of sobject records.
Restforce::Collection
@jeffdonthemic
jeffdonthemic / UploadAttachment
Created May 30, 2014
Visualforce Page for customizing Attachments. See UploadAttachmentController.
View UploadAttachment
<apex:page standardController="Contact" tabStyle="Contact" extensions="UploadAttachmentController">
<apex:sectionHeader title="{!Contact.Name}" subtitle="Attach File"/>
<apex:form id="form_Upload">
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!back}" value="Back to {!Contact.Name}"/>
<apex:commandButton action="{!back}" value="Cancel"/>
@jeffdonthemic
jeffdonthemic / httparty.rb
Last active Dec 17, 2019
HTTParty Examples
View httparty.rb
options = { :body =>
{ :username => 'my',
:password => 'password'
}
}
results = HTTParty.post("http://api.topcoder.com/v2/auth", options)
##
## example for post with papertrail and basic auth
##
@jeffdonthemic
jeffdonthemic / apex-crud-fls.txt
Last active Oct 9, 2019
Simple Apex Controller with CRUD and FLS
View apex-crud-fls.txt
This simple controller (without CRUD and FLS) ...
public with sharing class AccountController {
@AuraEnabled
public static List<Account> findAll() {
return [SELECT id, name, Location__Latitude__s, Location__Longitude__s
FROM Account
WHERE Location__Latitude__s != NULL AND Location__Longitude__s != NULL
LIMIT 50];
@jeffdonthemic
jeffdonthemic / index.js
Last active Oct 4, 2019
Lambda function to commit code to github. See blog post for more details.
View index.js
var githubapi = require("github"),
async = require("async"),
AWS = require('aws-sdk'),
secrets = require('./secrets.js');
// the 'handler' that lambda calls to execute our code
exports.handler = function(event, context) {
// config the sdk with our credentials
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
@jeffdonthemic
jeffdonthemic / app.rb
Last active Sep 3, 2019
Refresh Token from Salesforce
View app.rb
begin
require 'sinatra'
require 'omniauth'
require 'omniauth-salesforce'
rescue LoadError
require 'rubygems'
require 'sinatra'
require 'omniauth'
require 'omniauth-salesforce'
You can’t perform that action at this time.