Skip to content

Instantly share code, notes, and snippets.

def twilio_response(pokemon_name, description, type):
if type == 'voice':
# Do voice response
if type =='message':
# do message response
<Response>
<Enqueue action='action.xml' waitUrl='wait_music.xml'>my_queue</Enqueue>
</Response>
@phalt
phalt / server.py
Created September 29, 2014 11:52
Twilio App Monitor Webhooks part 1
from flask import Flask
app = Flask(__name__)
if __name__ == "__main__":
app.run(debug=True)
@phalt
phalt / server.py
Last active August 29, 2015 14:07
Twilio App Monitor Webhooks part 2
from flask import Flask
app = Flask(__name__)
@app.route('/error_trigger', methods=['POST'])
def error_triggers():
return 'Hello Twilio!'
if __name__ == "__main__":
app.run(debug=True)
@phalt
phalt / server.py
Last active August 29, 2015 14:07
Twilio App Monitor Webhooks part 3
from flask import Flask, request
app = Flask(__name__)
@app.route('/error_trigger', methods=['POST'])
def error_triggers():
error_code = request.values.get('ErrorCode', None)
return 'The error is' + error_code
if __name__ == "__main__":
@phalt
phalt / server.py
Created September 29, 2014 12:45
Twilio App Monitor Webhooks part 4
from flask import Flask, request
app = Flask(__name__)
@app.route('/error_trigger', methods=['POST'])
def error_triggers():
error_code = request.values.get('ErrorCode', None)
description = request.values.get('Description', None)
if error_code:
msg = 'An error on Twilio occurred! ' + description
@phalt
phalt / server.py
Last active August 29, 2015 14:07
Twilio App Monitor Webhooks part 5
from flask import Flask, request
app = Flask(__name__)
from twilio.rest import TwilioRestClient
client = TwilioRestClient()
@app.route('/error_trigger', methods=['POST'])
def error_triggers():
@phalt
phalt / linear.py
Created October 29, 2014 22:41
Linear / insertion sort in Python
haystack = [5,3,2,4,1]
for i in range(1, len(haystack)):
x = haystack[i]
c = i
while c > 0 and haystack[c-1] > x:
haystack[c] = haystack[c-1]
c = c - 1
haystack[c] = x
@phalt
phalt / lrucache.py
Created November 9, 2014 19:58
LRU Cache
class LRUCache(object):
""" Implements a least-recently-used cache in Python
As the cache grows it will cap at some fixed size described by the max_size
property
When you attempt to add a new object into a full cache, it will discard the
Least Recently Used cached item.
Calling set('key', ...) or get('key') constitutes a "use" of 'key'
@phalt
phalt / merge_sort.py
Last active March 8, 2017 10:50
Binary tree / merge sort example in Python
# A merge sort algorithm that is probably bigger than it needs to be.
# Uses binary trees to sort integers.
# Runtime is probably O(NlogN)
class Node(object):
def __init__(self, value):
self.value = value
self.left = None