Skip to content

Instantly share code, notes, and snippets.

View martyndavies's full-sized avatar

Martyn Davies martyndavies

View GitHub Profile
var http = require('http');
var qs = require('querystring');
var TempoDBClient = require('tempodb').TempoDBClient;
// Settings for TempoDB as ENV VARS
var tempodb = new TempoDBClient(process.env.tempodb_api_key, process.env.tempodb_api_secret);
var now = new Date();
// Create a series based on the event type
var http = require('http');
var qs = require('querystring');
var request = require('request'),
var decodedRequestBody;
function classifyEmail(text){
request('https://www.googleapis.com/prediction/v1.6/projects/{YOUR_PROJECT_ID}/trainedmodels/{YOUR_MODEL_ID}/predict?key={YOUR_API_KEY}', {"input":{"csvInstance":[text]}}, function(err, result){
// Log the best guess coming back from Google
var dns = require('dns');
module.exports = function(emailAddress, cb) {
'use strict';
var splitEmail = emailAddress.split('@');
dns.resolveMx(splitEmail[1], function(err, addresses){
if (addresses) {
cb(true, addresses);
} else {
cb(false, null);
@martyndavies
martyndavies / batched-events.json
Created January 9, 2014 11:49
An example of a batched request from the SendGrid event notification webhook
[{"email":"john.doe@sendgrid.com","sg_event_id":"VzcPxPv7SdWvUugt-xKymw","sg_message_id":"142d9f3f351.7618.254f56.filter-147.22649.52A663508.0","timestamp":1386636112,"smtp-id":"<142d9f3f351.7618.254f56@sendgrid.com>","event":"processed","category":["category1","category2","category3"],"id":"001","purchase":"PO1452297845","uid":"123456"},{"email":"not an email address","smtp-id":"<4FB29F5D.5080404@sendgrid.com>","timestamp":1386636115,"reason":"Invalid","event":"dropped","category":["category1","category2","category3"],"id":"001","purchase":"PO1452297845","uid":"123456"},{"email":"john.doe@sendgrid.com","sg_event_id":"vZL1Dhx34srS-HkO-gTXBLg","sg_message_id":"142d9f3f351.7618.254f56.filter-147.22649.52A663508.0","timestamp":1386636113,"smtp-id":"<142d9f3f351.7618.254f56@sendgrid.com>","event":"delivered","category":["category1","category2","category3"],"id":"001","purchase":"PO1452297845","uid":"123456"},{"email":"john.smith@sendgrid.com","timestamp":1386636127,"uid":"123456","ip":"174.127.33.234","purchase":
Parse.Cloud.define("sendEmail", function(request, response) {
var sendgrid = require("sendgrid");
sendgrid.initialize("your_sendgrid_username", "your_sendgrid_password");
var name = request.params.name;
var email = request.params.email;
var message = request.params.message;
sendgrid.sendEmail({
to: "youremail@yourdomain.com",
<html>
<head>
<title>Contact Form</title>
<!-- We need the hosted versions of jQuery and the Parse library -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.2.16.min.js"></script>
<script src="/js/emailer.js"></script>
<style type="text/css">
$(document).ready(function(){
// Initialize Parse with your Parse application & javascript keys
Parse.initialize("your_parse_app_key", "your_parse_javascript_key");
// Setup the form to watch for the submit event
$('#myForm').submit(function(e){
e.preventDefault();
// Grab the elements from the form to make up
var params = {
smtpapi: new sengrid.SmtpapiHeaders(),
... //some vars removed here!
files: [
{
filename: 'image.jpg',
contentType: 'image/jpeg',
cid: 'myimagecid',
content: ('yourbase64encodedimageasastringcangohere' | Buffer)
}
<html>
<body>
<img src="cid:myimagecid"/>
</body>
</html>