Skip to content

Instantly share code, notes, and snippets.

View RobSpectre's full-sized avatar

Rob Spectre RobSpectre

View GitHub Profile
@RobSpectre
RobSpectre / quickstart.py
Created December 2, 2024 16:46
quickstart.py
import ldclient
from ldclient.config import Config
from ldclient import Context
ldclient.set_config(Config('sdk-copy-your-key-here'))
client = ldclient.get()
if __name__ == "__main__":
if client.is_initialized():
import ldclient
from ldclient.config import Config
from ldclient import Context
ldclient.set_config(Config('sdk-copy-your-key-here'))
client = ldclient.get()
if __name__ == "__main__":
if client.is_initialized():
import ldclient
from ldclient.config import Config
from ldclient import Context
ldclient.set_config(Config('sdk-copy-your-key-here'))
client = ldclient.get()
if __name__ == "__main__":
if client.is_initialized():
@RobSpectre
RobSpectre / app.py
Created April 27, 2017 21:49
Example of using Celery for Quasar Queue
from flask import Flask
from flask import request
from tasks import store_db
app = Flask(__name__)
@app.route('/blink', methods=['GET', 'POST'])
def blink():
@RobSpectre
RobSpectre / nps.py
Created June 1, 2016 22:16
Calculate Net Promoter Score with Python lambda function
nps = lambda x: float(((len([i for i in x if i > 8]) / len(x)) * 100) - ((len([i for i in x if i < 7]) / len(x)) * 100))
@RobSpectre
RobSpectre / locustfile.py
Created May 19, 2016 22:40
Load Test Example
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
@task(5)
def positive(self):
self.client.post("/sms", {"AddOns": '{"status":"successful","message":null,"code":null,"results":{"mobilecommons_optout":{"request_sid":"XR8b9aa36363d6f4ec4fe42dade911baa6","status":"successful","message":null,"code":null,"result":{"probability":0}},"ibm_watson_insights":{"request_sid":"XR2ad003f13c531200832776b7e1df7190","status":"failed","message":"Request timed out","code":61001,"result":{}},"ibm_watson_sentiment":{"request_sid":"XRb80b1d857cffed90098863f17d040f21","status":"successful","message":null,"code":null,"result":{"status":"OK","usage":"By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html","totalTransactions":"1","language":"english","docSentiment":{"score":"0.629583","type":"positive"}}}}}'})
@task(1)
def negative(self):
var twilio = require('twilio');
// Will use TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN env vars
var twilio_client = new Twilio();
var notify = client.notifications.v1.services("ISxxxx");
// create list of installs and declare signal_peeps
signal_peeps.forEach(function(signal_peep) {
notify.bindings.create({
identity: signal_peep.email_address,
tag: "SIGNAL attendee"
}).then(function(response) {
@RobSpectre
RobSpectre / reply.php
Created April 29, 2016 20:32
Conditional logic in a Twilio SMS reply.
<?php
header('Content-type: text/xml');
$body = $_REQUEST['Body'];
if ($body == "Yes") {
$response = "You said yes.";
} else {
$response = "You didn't say yes.";
}
@RobSpectre
RobSpectre / example.rb
Created April 29, 2016 17:13
Inbound TwiML
def connect
# Our response to this request will be an XML document in the "TwiML"
# format. Our Ruby library provides a helper for generating one
# of these documents
response = Twilio::TwiML::Response.new do |r|
r.Dial '[INSERT AGENT PHONE NUMBER HERE]'
end
render text: response.text
end
<script type="text/javascript">
dataLayer = [];
</script>