Skip to content

Instantly share code, notes, and snippets.

/*
Requires npm installs for
* nforce (handles salesforce API)
* faye (handles streaming API -- there's an old version in nforce, but install a new one)
* serialport (this handles serial communication and will do a little compiling on your machine)
Configure Salesforce as follows
* Start with a standard developer org -- http://developer.force.com/join
* Install the package for the simple Streaming API demo here
https://github.com/ReidCarlberg/LAB-Streaming-API-Demo
/*
Reid Carlberg
reid.carlberg@gmail.com
v4 - With updated alarm LED wiring and new DISCO handler
v3 - With alarm LED, Longer duration, 00 is key for "ALL DEVICES"
v2 - Custom serial scheme & fixed ID
v1 - JSON & Random ID
@ReidCarlberg
ReidCarlberg / 29-Salesforce-Push-Topic.html
Created December 19, 2013 20:27
The HTML portion of the push topic -- this is where you configure your Client ID, etc.
<!-- Sample html file that corresponds to the 99-sample.js file -->
<!-- This creates and configures the onscreen elements of the node -->
<!-- If you use this as a template, replace IBM Corp. with your own name. -->
<!-- First, the content of the edit dialog is defined. -->
<script type="text/x-red" data-template-name="salesforce in">
// If you use this as a template, replace IBM Corp. with your own name.
// Sample Node-RED node file
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var nforce = require('nforce');
var http = require('http'),
faye = require('faye');
Challenge: deploy node-red to a heroku endpoint.
2013/12/27
First challenge -- you have to have red.js listen on process.env.PORT rather than 1880.
https://devcenter.heroku.com/articles/getting-started-with-nodejs
Second challenge -- web sockets -- node-red uses web sockets, so the server comes up and disconnects right away.
When you enable the lab:websockets it doesn't fix it out of the box.
https://blog.heroku.com/archives/2013/10/8/websockets-public-beta
@ReidCarlberg
ReidCarlberg / Date - This week, Next 90 Days, Past or Future
Last active November 25, 2019 15:53
A formula field for calculating a timeframe.
if (
and (
YEAR(Date_Start__c) == YEAR(TODAY()),
IF(
CEILING( ( Date_Start__c - DATE( YEAR( Date_Start__c ), 1, 1) + 1) / 7) > 52,
52,
CEILING( ( Date_Start__c - DATE( YEAR( Date_Start__c ), 1, 1) + 1) / 7)
) ==
IF(
@ReidCarlberg
ReidCarlberg / WildThumper-I2C
Created February 10, 2014 03:56
I wanted to control an Arduino with a Raspberry Pi and Node.js using I2C.
#include <Servo.h>
#include "IOpins.h"
#include "Constants.h"
#include <Wire.h>
//-------------------------------------------------------------- define global variables --------------------------------------------
unsigned int Volts;
unsigned int LeftAmps;
unsigned int RightAmps;
var i2c = require('i2c');
var device1 = new i2c(0x18, {device: '/dev/i2c-1', debug: false});
device1.setAddress(0x4);
var AckCounter = 0;
var nforce = require('nforce');
var http = require('http'),
faye = require('faye');
var hue = require("node-hue-api");
var displayBridges = function(bridge) {
console.log("Hue Bridges Found: " + JSON.stringify(bridge));
};
// --------------------------
// Using a promise
hue.locateBridges().then(displayBridges).done();
var HueApi = require("node-hue-api").HueApi;
var hostname = "192.168.1.103",
newUserName = null // You can provide your own username value, but it is normally easier to leave it to the Bridge to create it
userDescription = "device description goes here";
var displayUserResult = function(result) {
console.log("Created user: " + JSON.stringify(result));
};