Skip to content

Instantly share code, notes, and snippets.

View RobSpectre's full-sized avatar

Rob Spectre RobSpectre

View GitHub Profile
@RobSpectre
RobSpectre / proxy.js
Created April 14, 2012 17:28
Simple reverse proxy of Facebook API
var http = require('http'),
https = require('https'),
httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
console.log("Received request.");
proxy.proxyRequest(req, res, {
host: 'graph.facebook.com',
port: '443',
https: true
@RobSpectre
RobSpectre / proxy.js
Created April 14, 2012 19:47
Proxy with explicit buffering
var http = require('http'),
https = require('https'),
httpProxy = require('http-proxy');
var server = httpProxy.createServer({
target: { host: 'graph.facebook.com', port: 443, https: true },
changeOrigin: true },
function (req, res, proxy) {
console.log("Received request.");
server.proxy.response_buffer = new Buffer('', 'utf8');
@RobSpectre
RobSpectre / error.log
Created April 14, 2012 21:20
Manifest file
npm http GET https://registry.npmjs.org/colors
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/pkginfo
npm http GET https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/async
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/colors
npm http 304 https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/request
@RobSpectre
RobSpectre / test.py
Created April 20, 2012 21:34
Failure to patch accurately
import unittest
from mock import patch
class Class:
def __init__(self):
self.foo = 'bar'
class TestClass(unittest.TestCase):
@patch('__main__.Class')
def test_class(self, MockClass):
@RobSpectre
RobSpectre / zenofon.php
Created April 24, 2012 23:09
Easy example of SMS tree
<?php
header('Content-type: text/xml');
$message = $_REQUEST['Body'];
?>
<Response>
<Sms><?php
if ($message == "CHANNEL") {
echo "1) ROCK 102 2) Ethnic Channel #2 3) Another Station";
} else if ($message == "COUNTRY") {
echo "1) United States 2) Israel 3) Ireland";
@RobSpectre
RobSpectre / example.php
Created May 21, 2012 16:15
Callback folks who texted a number
<?php
require_once('Services/Twilio.php');
require_once('auth.php');
$client = new Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
foreach($client->account->sms_messages->getIterator(0, 50, array("To"=>"+15556667777")) as $msg) {
print_r($msg);
@RobSpectre
RobSpectre / app.py
Created May 21, 2012 23:19
Example of Plays and Redirects together
from flask import Flask
from twilio import twiml
# Declare and configure application
app = Flask(__name__, static_url_path='/static')
# Voice Request URL
@app.route('/voice', methods=['GET', 'POST'])
@RobSpectre
RobSpectre / weather.php
Created May 22, 2012 16:25
Example of a Twilio SMS weather app in PHP
<?php
// Set Weather Underground API key
$WUNDERGROUND_API_KEY = "xxxxxxxxx";
// Include Twilio helper library
require_once('Services/Twilio.php');
// Fetch latest weather for zipcode
$zip = $_REQUEST['FromZip'];
$ch = curl_init();
@RobSpectre
RobSpectre / caller_id.php
Created May 23, 2012 21:08
Display Number Called Instead Of Number Calling
<?php
header('Content-type: text/xml');
$twilio_number = $_REQUEST['To'];
?>
<Response>
<Dial callerId="<?php echo $twilio_number; ?>">
<Number>+15558675309</Number>
</Dial>
</Response>
@RobSpectre
RobSpectre / fifty_bones_to_win.py
Created May 24, 2012 18:34
$50 SMS poll winner
# A SMS Ballot Stuffer
# Warning: this code will cost you fifty dollars.
from twilio.rest import TwilioRestClient
client = TwilioRestClient("ACxxxxxxxxxxx", "yyyyyyyyyyyyyy")
target_number = "+15558675309"
confirm = raw_input("Are you seriously going to pay $50 to win a SMS poll? [y/n]")