Skip to content

Instantly share code, notes, and snippets.

View bevenky's full-sized avatar

Venky B bevenky

View GitHub Profile
@bevenky
bevenky / redis_leaky_bucket.py
Created December 29, 2017 20:54 — forked from jdunck/redis_leaky_bucket.py
leaky bucket queue - redis 2.6 + lua + python
#cribbed from http://vimeo.com/52569901 (Twilio carrier call origination moderation)
# The idea is that many fan-in queues can enqueue at any rate, but
# dequeue needs to happen in a rate-controlled manner without allowing
# any individual input queue to starve other queues.
# http://en.wikipedia.org/wiki/Leaky_bucket (second sense, "This version is referred to here as the leaky bucket as a queue.")
#
# requires:
# redis 2.6+
# redis-py>=2.7.0
# anyjson
<Response>
<Dial>
<Number>14157583659</Number>
</Dial>
</Response>
<Response>
<GetDigits action="https://gist.githubusercontent.com/bevenky/a44bb9e215c9e8c5264d290ac0bafe22/raw/64fd641d2300364905ce2bcf0277aa3a40ee237b/forward.xml" method="GET">
<Speak>Thank you for calling Envioni foods. You call may be monitored and recorded for quality and training purposes.</Speak>
<Speak>Please press 1 to cancel or change your membership plan</Speak>
<Speak>Please press 2 to order new products</Speak>
<Speak>Please press 3 for partnership inquiries</Speak>
<Speak>Please press 4 for media and pr relations</Speak>
</GetDigits>
</Response>
curl -X POST -H "Content-Type: application/json" -d '{"src":"XXXXXXXXX","dst":"YYYYYYYYY","text":"こんにちはお元気ですか"}' -L -u <AUTHID>:<AUTHTOKEN> https://api.plivo.com/v1/Account/<AUTHID>/Message/
where:
XXXXXXXXX = source Plivo number (it must be a Phone Number in your Plivo account)
YYYYYYYYY = destination mobile number
<AUTHID> = Plivo AUTHID
<AUTHTOKEN> = Plivo AUTHTOKEN
import plivo
auth_id = ""
auth_token = ""
p = plivo.RestAPI(auth_id, auth_token)
# Make Calls
params = {
@bevenky
bevenky / trial_lua
Created August 18, 2012 11:46
Trial lua
pin = argv[1];
app_uri = [email protected]
api = freeswitch.API();
-- Call conference bridge
call_session = freeswitch.Session("sofia/external/" .. app_uri);
-- Get session UUID
@bevenky
bevenky / gist:1213838
Created September 13, 2011 13:44
Export json admin action with inlines
def export_related_as_json(modeladmin, request, queryset):
opts = modeladmin.model._meta
for parent in queryset:
for inline in modeladmin.inlines:
related_params = inline.model.objects.filter(**{inline.fk_name: parent})
from itertools import chain
result_list = list(chain(queryset, related_params))
data = serializers.serialize("json", result_list, indent=4)
response = HttpResponse(data, mimetype="text/javascript")
response['Content-Disposition'] = 'attachment; filename=%s.json' \
@bevenky
bevenky / redis_example.py
Created August 17, 2011 20:37
Redis Cache
import redis
class ResourceCache(object):
"""Uses a local directory as a store for cached files.
"""
def __init__(self, redis_host='localhost', redis_port=6379, redis_db=0):
self.cache = redis.Redis(host=redis_host, port=redis_port, db=redis_db)
def get_resource_params(self, resource_key):
if self.cache.sismember("resource_key", resource_key):
#!/usr/bin/env python
import helpers
#Sid and AuthToken
SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
AUTH_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
originate_dial_string = "bridge_early_media=true,hangup_after_bridge=true"