Skip to content

Instantly share code, notes, and snippets.

@brandonmwest
brandonmwest / example.cs
Last active January 16, 2024 15:52
Generating base64-encoded Authorization headers in a variety of languages
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", username, password))));
@brandonmwest
brandonmwest / html2markdown.rb
Created July 2, 2014 17:25
convert jekyll html with custom liquid tags and codeblocks to well-structured markdown
require 'rubygems'
require 'json'
require 'nokogiri'
require 'nokogiri-pretty'
require 'iconv'
require 'pandoc-ruby'
require 'fileutils'
#convert HTML to markdown
html_files = File.join("/Users/brandonwest/SendGrid/docs/source", "**", "*.html")
@brandonmwest
brandonmwest / gist:4512396
Last active June 25, 2022 13:11
curl + PHP example of using the SendGrid web api

This example uses cURL with PHP through our web API to send an email.

<?php $url = 'http://sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD'; 
 
$params = array(
    'api_user'  => $user,
 'api_key' =&gt; $pass,
@brandonmwest
brandonmwest / gist:6262934
Last active December 22, 2020 09:02
Custom liquid block for Jekyll example
#Generates a named anchor and wrapping tag from a string.
module Jekyll
class AnchorBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
@tag = markup
super
end
def render(context)
@brandonmwest
brandonmwest / gist:5016294
Created February 22, 2013 20:22
Send email from SendGrid using Pony gem
require 'rubygems'
require 'pony'
#set the default options
Pony.options = {
:from => 'demo@sendgrid.com',
:via => :smtp,
:via_options => {
:address => 'smtp.sendgrid.net',
:port => '587',
$(function() {
//callback we must supply to the widget to interact with our server-side code
//must take 3 parameters: email, fingerprint, and app_code
//must return a jQuery POST request object
var callback = function(email, fingerprint, kickbox_app_code){
return $.post( "/authenticate", {
email: email,
fingerprint: fingerprint,
kickbox_app_code: kickbox_app_code,
@brandonmwest
brandonmwest / node+ra.md
Last active June 21, 2017 15:36
RA + Node.js tutorial draft

Introduction

Today we're going to build a node.js application to collect email addresses using Kickbox. We'll be using Express and Request on the server side, and jQuery on the client.

We'll be using Glitch during this tutorial, because it provides an environment, editor, and hosting in one convenient package. There's an example of the completed project too. If you want to follow along in your own environment, all of the code will work.

What is Recipient Authentication?

Recipient Authentication makes it easy to collect email addresses the right way. We handle account activation, double email opt-in subscriptions, and password resets. We make sure the email gets delivered, send drip reminders, expire old links, handle opt-outs, and automatically add authenticated addresses to your email service provider or marketing platform.

@brandonmwest
brandonmwest / gist:3536551
Created August 30, 2012 18:23
Hierarchical tree of pages in Jekyll
require 'digest/md5'
module Jekyll
# Add accessor for directory
class Page
attr_reader :dir
end
class NavTree < Liquid::Tag
def render(context)
{
"personalizations": [{
"to": [{
"email": "anna@example.com"
}],
"cc": [{
"email": "bill@example.com"
}, {
"email": "connie@example.com"
}, {
{
"from": {
"name": "B West",
"email": "brandon@sendgrid.com"
},
"subject": "Mail v3 test",
"personalizations": [{
"to": [{
"name": "gYDXLV jeZLCy0VdiuU",
"email": "DuxWsA@sink.sendgrid.net"