Skip to content

Instantly share code, notes, and snippets.

View jdc-cunningham's full-sized avatar

Jacob David C Cunningham jdc-cunningham

View GitHub Profile
@jdc-cunningham
jdc-cunningham / gist:bfef0e3824c2bc132ebc2032e0c1437e
Created October 4, 2017 12:53
PHP Slack Webhook Function Using CURL
function sendWebhook($message) {
$webhook_url = "";
// slack webhook test
$data = "payload=" . json_encode(array(
"text" => $message
));
$ch = curl_init($webhook_url);
@jdc-cunningham
jdc-cunningham / grab-solar-data-send.py
Last active March 9, 2018 11:20
Example analog data grab from a solar panel with Adafruit's library on the MCP3008 with a POST request to a posttestserver endpoint
# this code is based on the Adafruit MCP3008 library being installed and the ADC being properly wired to your Raspberry Pi
# and source of analog data
# for math division
from __future__ import division
# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
@jdc-cunningham
jdc-cunningham / sample.sql
Created April 16, 2018 21:24
example-sql
SELECT fruit_name FROM fruits WHERE fruit_name = :fruit_name
@jdc-cunningham
jdc-cunningham / example-decrypt-select.php
Last active April 16, 2018 21:40
example pre-decrypt sql search with php-defuse
<?php
$fruit_names = [];
$stmt = $dbh->prepare('SELECT id, fruit_name FROM fruits');
if ($stmt->execute()) {
$result = $stmt->fetchAll();
$result_count = count($result);
if ($result_count > 0) {
foreach($result as $row) {
@jdc-cunningham
jdc-cunningham / memcache-test.php
Created April 16, 2018 23:04
example memcache test
<?php
// memcache test
$server = 'localhost';
if (!empty($_REQUEST['server'])) {
$server = $_REQUEST['server'];
}
$memcache = new Memcache;
$isMemcacheAvailable = @$memcache->connect($server);
<?php
// memcache test
$server = 'localhost';
if (!empty($_REQUEST['server'])) {
$server = $_REQUEST['server'];
}
$memcache = new Memcache;
$isMemcacheAvailable = @$memcache->connect($server);
// check memcache
@jdc-cunningham
jdc-cunningham / memcache-retrieve-key.php
Created April 16, 2018 23:11
retrieve key from memcache
<?php
// memcache test
$server = 'localhost';
if (!empty($_REQUEST['server'])) {
$server = $_REQUEST['server'];
}
$memcache = new Memcache;
$isMemcacheAvailable = @$memcache->connect($server);
// check memcache
@jdc-cunningham
jdc-cunningham / encrypt-decrypt-php-defuse.php
Created April 16, 2018 23:26
encrypt decrypt example using php-defuse
<?php
// error checking
ini_set('display_errors', 1);
// require php-defuse.phar
require_once('defuse-crypto.phar');
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;
@jdc-cunningham
jdc-cunningham / msg.xml
Created May 15, 2018 05:47
Sample Twilio XML read by phone call
<!-- this is based on Twilio's example https://demo.twilio.com/docs/voice.xml -->
<Response>
<Say voice="alice">
Your message
</Say>
</Response>
@jdc-cunningham
jdc-cunningham / make-call.php
Created May 15, 2018 05:50
Make a call through Twilio using PHP and read XML file contents
/*
The URL is an XML file telling Twilio's phone call "bot?" what to do
View an example here https://gist.github.com/jdc-cunningham/af131c042309d1ccd8acd5bcc626b0de
The code below is from Twilio's example
https://www.twilio.com/docs/voice/make-calls
*/
<?php