Skip to content

Instantly share code, notes, and snippets.

Avatar

Craig Dennis craigsdennis

View GitHub Profile
@craigsdennis
craigsdennis / save-execution.js
Last active Dec 11, 2020
Save Twilio Studio Flow Execution Context to Airtable if Widget name and field names match
View save-execution.js
// Create an Airtable with fields that match the widget names that you want to record
// Make your primary key ExecutionSid and add a ContactChannelAddress field
// Set your environment variables AIRTABLE_*
// Run Function in Studio and pass the following params:
// Flow: {{flow | to_json }}
// Widgets: {{widgets | to_json}}
// Contact: {{contact | to_json}}
require("dotenv").config();
const Airtable = require("airtable");
@craigsdennis
craigsdennis / delete_all_calls_and_messages.py
Last active Dec 12, 2019
Delete all calls and messages from your Twilio logs
View delete_all_calls_and_messages.py
import os
import sys
# TODO: pip install twilio
from twilio.rest import Client
# TODO: Set environment variables TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN
client = Client()
# TODO: Flip this to False to turn off the safety.
@craigsdennis
craigsdennis / jupyter_javascript_snippet.js
Created Jun 12, 2018
Run Python code from JavaScript in a Jupyter notebook
View jupyter_javascript_snippet.js
// %%javascript
window.executePython = function(python) {
return new Promise((resolve, reject) => {
var callbacks = {
iopub: {
output: (data) => resolve(data.content.text.trim())
}
};
Jupyter.notebook.kernel.execute(`print(${python})`, callbacks);
});
View WittyEspruino.js
var shhh = "SECRETPASSWORD";
function hexToRgb(hex) {
// No RegEx in Espruino yet...
var R, G, B;
if (hex.length == 3) {
R = hex.substring(0, 1);
R = R + R;
G = hex.substring(1, 2);
G = G + G;
@craigsdennis
craigsdennis / Okay.scala
Last active Aug 29, 2015
Regular Expressions example in Scala
View Okay.scala
val title = "Regular Expressions in 10 different languages"
val pattern = """(\d+)""".r.unanchored
title match {
case pattern(total) => s"There are $total languages represented."
}
@craigsdennis
craigsdennis / Okay.groovy
Last active Aug 29, 2015
Regular Expression example in Groovy
View Okay.groovy
title = "Regular Expressions in 10 different languages"
matcher = title =~ /(\d+)/
matcher.find()
printf("There are %s languages represented", matcher.group(1))
@craigsdennis
craigsdennis / okay.cs
Last active Aug 29, 2015
Regular Expression example in C#
View okay.cs
string title = "Regular Expressions in 10 different languages";
string pattern = @"(\d+)";
foreach (Match match in Regex.Matches(title, pattern))
Console.WriteLine("There are {0} languages represented.",
match.Groups[1].Value);
@craigsdennis
craigsdennis / okay.php
Last active Aug 29, 2015
Regular Expressions example in PHP
View okay.php
$title = "Regular Expressions in 10 different languages";
$pattern = "~(\\d+)~";
$success = preg_match($pattern, $title, $match);
if ($success) {
echo "There are " . $match[1] . " languages represented.";
}
@craigsdennis
craigsdennis / Okay.swift
Last active Jun 8, 2016
Regular Expressions in Swift
View Okay.swift
let title = "Regular Expressions in 10 different languages"
// Match
let pattern = ".*\\d.*"
if let match = title.rangeOfString(pattern, options: .RegularExpressionSearch) {
println("We had a match!")
}
let re = NSRegularExpression(pattern: "(\\d+)", options: nil, error: nil)!
let matches = re.matchesInString(
@craigsdennis
craigsdennis / okay.js
Last active Aug 29, 2015
Regular Expression example in JavaScript
View okay.js
var title = "Regular Expressions in 10 different languages";
// This will be true or false
var result = /.*\d+.*/.test(title);
var match = /(\d+)/.exec(title);
if (match) {
console.log("There are ", match[1], " languages represented.");
}