Skip to content

Instantly share code, notes, and snippets.

@tfogo
tfogo / index.js
Last active January 23, 2017 20:48
Ask Twilio to search for numbers which contain random 2 digit integers
let twilioPromise = client.availablePhoneNumbers('US').local.list({
Contains: getRandomInt(10,99),
areaCode: '650'
});
@tfogo
tfogo / index.js
Created January 23, 2017 13:31
Random integer function
function getRandomInt(min, max) {
// max and min numst be integers
return Math.floor(Math.random() * (max - min)) + min;
}
@tfogo
tfogo / index.js
Last active January 23, 2017 20:50
Test for primality for phone numbers from all the promises
phonePromise.then(data => {
let verifiedPrimes = [];
data.forEach(twilioObject => {
twilioObject.available_phone_numbers.forEach(e => {
if (primality(e.phone_number.slice(2)) && !verifiedPrimes.includes(e.phone_number.slice(2))) {
verifiedPrimes.push(e.phone_number.slice(2));
}
});
});
@tfogo
tfogo / index.js
Last active January 23, 2017 20:50
Making several requests to the Twilio API
// An array to hold all the promises we get from Twilio API requests
let promises = [];
for (let i = 0; i < 20; i++) {
// Make a call to the available phone numbers API for the US
let twilioPromise = client.availablePhoneNumbers('US').local.list({
areaCode: '650'
});
promises.push(twilioPromise);
@tfogo
tfogo / index.js
Last active January 23, 2017 21:01
Finding prime number phone numbers
twilioPromise.then(twilioObject => {
let verifiedPrimes = [];
twilioObject.available_phone_numbers.forEach(e => {
if (primality(e.phone_number.slice(2)) && !verifiedPrimes.includes(e.phone_number.slice(2))) {
verifiedPrimes.push(e.phone_number.slice(2));
}
});
console.log(verifiedPrimes);
@tfogo
tfogo / twilioResponse.js
Last active January 23, 2017 11:32
Example of data from the available numbers resource
{ available_phone_numbers:
[ { friendly_name: '(650) 399-9040',
phone_number: '+16503999040',
lata: '722',
rate_center: 'REDWOOD CY',
latitude: '37.485200',
longitude: '-122.236400',
region: 'CA',
postal_code: '94062',
iso_country: 'US',
@tfogo
tfogo / index.js
Last active January 23, 2017 20:54
Make a call to the available phone numbers Twilio API
var twilio = require('twilio');
const accountSid = process.env.TWILIO_AC_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
var client = require('twilio')(accountSid, authToken);
// Make a call to the available phone numbers API for the US
var twilioPromise = client.availablePhoneNumbers('US').local.list({
areaCode: '650'
});
<body style="">
<div id="header">
<div id="navbar" style="
position: relative;
background-color: #f8f8f8;
">
<img id="menu" src="icons/ic_menu_black_48dp_1x.png">
<img id="settings" src="icons/ic_settings_black_48dp_1x.png">
<div style="
steps for AWS setup:
#!/bin/bash
# Simple setup.sh for configuring Ubuntu 12.04 LTS EC2 instance
# for headless setup.
# Install nvm: node-version manager
# https://github.com/creationix/nvm
sudo apt-get install -y git
# sudo apt-get install -y curl #Not needed?
@tfogo
tfogo / setup.sh
Last active August 29, 2015 14:15
#!/bin/bash
# Get your AWS EC2 instance set up quicky!
# Simple setup.sh for configuring Ubuntu 14.04 LTS EC2 instance.
# Set up locale
sudo apt-get install --reinstall language-pack-en
# Install git
sudo apt-get install -y git