Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Whinnery kwhinnery

  • Twilio
  • Saint Paul / Minneapolis
View GitHub Profile
@kwhinnery
kwhinnery / app.js
Created May 26, 2014
HTTP Basic Authentication with Express 4 using the http-auth module
View app.js
var express = require('express'),
auth = require('http-auth');
// Configure basic auth
var basic = auth.basic({
realm: 'SUPER SECRET STUFF'
}, function(username, password, callback) {
callback(username == 'admin' && password == 'f00lpr00f');
});
View ti.js
/*
* Mixin properties of n objects into the given object - pass in as many objects to mix in as you like.
* Can perform a shallow or deep copy (shallow is default for performance reasons).
*
* Usage:
* mixin([Boolean deepCopy,] objectToExtend, objectToMixIn [, as many other objects as needed])
*
* Examples:
*
* var o1 = {
View index.js
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const app = express();
app.use(bodyParser.urlencoded({ extended: false });
app.post('/sms', (req, res) => {
const twiml = new MessagingResponse();
View minecraft.js
// CONFIGURE THESE VALUES FIRST
// ----------------------------
// Your secure auth token, found at https://www.twilio.com/user/account
var TWILIO_AUTH_TOKEN = 'wwwxxxyyyzzz';
// An administrator's phone number
var ADMIN_PHONE = '+16518675309';
// Your server's public IP address
View package.json
{
"name": "Kevin's Mod",
"version": "0.1.x",
"dependencies": {
"twilio": "4.x"
},
"engines": {
"twilioquest": "3.1.x"
},
"twilioquest": {
View app.js
app.post('/message', function(req, res, next) {
// Use the REST client to send a text message
client.messages.create({
to: req.body.to,
from: TWILIO_PHONE_NUMBER,
body: 'Good luck on your Twilio quest!'
}).then(function(message) {
// When we get a response from Twilio, respond to the HTTP POST request
res.send('Message is inbound!');
}).catch(function(error) {
View queries.js
const pool = require('./config');
require('dotenv').config()
const getUsers = (request, response) => {
pool.connect().then(client => {
client.query('SELECT * FROM users ORDER BY id ASC', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
View GAEClientConnection.java
package com.twilio;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;
import org.apache.http.Header;
View airtable_update.js
/* global module, exports, require, process, console */
'use strict'
const Airtable = require('airtable')
// Configure Airtable database
const base = new Airtable({
apiKey: process.env.AIRTABLE_API_KEY}
).base(process.env.AIRTABLE_DATABASE)
View index.js
const express = require('express')
const app = express()
app.post('/sms', (request, response) => {
let twiml = `
<Response>
<Message>hey there, thanks for checking out my demo!</Message>
</Response>
`;