Skip to content

Instantly share code, notes, and snippets.

#require "Salesforce.class.nut:1.1.0"
#require "Rocky.class.nut:1.2.3"
#require "bullwinkle.class.nut:2.3.0"
#require "promise.class.nut:3.0.0"
// EXTEND SALESFORCE CLASS TO HANDLE OAUTH 2.0
// ----------------------------------------------------------
class SalesforceOAuth2 extends Salesforce {
//window.location.href = "test"
@joshbirk
joshbirk / agent.nut
Last active December 28, 2016 08:03
Tilt meter with Electric Imp impExplorer to control LIFX lights
current_bright <- 0.5;
current_scene <- 2;
const low_scene = 0;
const high_scene = 3;
const lowest_bright = 0.0;
const highest_bright = 1.0;
const bearer = "YOURBEARERIDS";
related_scenes <- [IFNEEDED+YOURSCENEIDSHERE];
function motion(data) {
if(data.dir == "TAP") {
@joshbirk
joshbirk / agent.nut
Created December 28, 2016 03:22
Quick Electric Imp impExplorer Tilt Meter
function motion(direction) {
server.log(direction);
}
device.on("direction.sent", motion);
@joshbirk
joshbirk / plumb.js
Created June 1, 2016 19:31
Module version of plumb
"use strict";
var plumb = (function (initial_data) {
// Properties
///////////////////////////
var raw_data = [];
var data = [];
var load = function(raw_data,data) {
app.post('/token',function (req, res) {
console.log(req.body);
var sr = sync_request('POST', 'https://login.salesforce.com/services/oauth2/token',
{
headers: {'Content-Type':'application/x-www-form-urlencoded','Accept':'application/json'},
body: 'grant_type='+req.body.grant_type+'&code='+req.body.code+'&refresh_token='+req.body.refresh_token+'&client_id='+req.body.client_id+'&client_secret='+req.body.client_secret+'&redirect_uri='+req.body.redirect_uri
});
console.log(sr.getBody('utf8'));
response = JSON.parse(sr.getBody('utf8'));
@joshbirk
joshbirk / SpeedTest Apex Controller
Last active March 29, 2019 20:04
Lightning Chart Component w/ D3.js
public with sharing class SpeedTestController {
@AuraEnabled
public static List< SpeedTest__c > getData() {
List<SpeedTest__c> speeds = [SELECT ID, TimeString__c,Download__c,Upload__c from SpeedTest__c LIMIT 1000];
return speeds;
}
}
@joshbirk
joshbirk / DestroyAllTheThings.cls
Last active April 12, 2016 10:21
Simple class to try and destroy all records in a Salesforce instance. Does not currently destroy Apex, or Visualforce, or Lightning components. It probably will never do the latter, I'm not sure I want it to do the former. Does not destroy custom metadata, but I'm looking into it. TODO: Parameters to avoid limits.
public class DestroyAllTheThings {
public DestroyAllTheThings() {}
public void destroySimpleCRMStuff() {
//First clear out known dependents, leads and cases etc.

Salesforce Developer Workshop

@joshbirk
joshbirk / RejectDoubleBooking.apex
Created August 21, 2015 00:03
Bulkified project triggers
trigger RejectDoubleBooking on Session_Speaker__c (before insert, before update) {
//collect ID's in one list to reduce SOQL
List<Id> speakerIds = new List<Id>();
Map<Id,DateTime> requested_bookings = new Map<Id,DateTime>();
//get all speakers related to the trigger
for(Session_Speaker__c newItem : trigger.new) {
requested_bookings.put(newItem.Session__c,null);
speakerIds.add(newItem.Speaker__c);