Skip to content

Instantly share code, notes, and snippets.

David Santucci dsantuc

  • Bindable, Inc
  • Boston, MA
Block or report user

Report or block dsantuc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dsantuc
dsantuc / ds_array_merge_recursive.php
Created Mar 6, 2020
A more intuitive implementation of PHP's array_merge_recursive()
View ds_array_merge_recursive.php
<?php
function ds_array_merge_recursive () {
$args = func_get_args();
$numArgs = count($args);
if ($numArgs < 1) {
trigger_error(__FUNCTION__ . "() expects at least one parameter, $numArgs given", E_USER_WARNING);
return null;
}
View sqs-async.php
<?php
require_once("vendor/autoload.php");
use Aws\Sqs\SqsClient,
GuzzleHttp\Promise;
class AsyncQueueMonitor {
protected $sqsClient;
@dsantuc
dsantuc / word-number.php
Created Nov 10, 2018
Computing the "number" of a word.
View word-number.php
<?php
/*
Given a word between 1 and 20 characters in length, write a command-line script that outputs its "number".
A word's "number" is its alphabetical ordinal position in the set of permutations of its letters.
Examples:
ABAB = 2
@dsantuc
dsantuc / ipconv.js
Last active Jun 14, 2018
JavaScript to convert IPv4 addresses from dotted-decimal notation to integers and back.
View ipconv.js
function ip2int (ip) {
var ipVal = 0;
ip.split(".").forEach(function (octet, i, arr) {
var exp = 8 * (arr.length - i - 1);
ipVal += octet * Math.pow(2, exp);
});
return ipVal;
}
View behat-ajax.php
// Behat code to wait for ajax calls to complete
public function waitForAjax ($seconds=5) {
if(!$this->getSession()->wait((1000 * $seconds), "jQuery.active == 0")) {
throw new Exception("Ajax calls still pending after $seconds seconds.");
}
}
@dsantuc
dsantuc / invert-tree.php
Last active Mar 14, 2018
Inverting a binary tree
View invert-tree.php
// invert a binary tree with root node $rootNode
function isLeafNode ($node) {
return is_null($node->left) && is_null($node->right);
}
function invert (&$node) {
if (isLeafNode($node)) {
return;
@dsantuc
dsantuc / behat-auth.php
Last active Mar 14, 2018
Pattern for reusing cookie-based authentication tokens in BeHat
View behat-auth.php
// in FeatureContext.php
// Store session tokens for reauthentication
private static $credentialStore = array();
// ... other code ...
/**
* Authenticates a user with password from configuration.
*
@dsantuc
dsantuc / behat-cookies.php
Last active Mar 31, 2020
Getting all cookies from various BeHat/Mink browser drivers
View behat-cookies.php
public function getAllCookies ($driver) {
$cookies = array();
if ($driver instanceof Behat\Mink\Driver\BrowserKitDriver) {
$cookies = $this->getBrowserKitCookies($driver);
}
else if ($driver instanceof Behat\Mink\Driver\Selenium2Driver) {
$cookies = $this->getSeleniumCookies($driver);
}
else if ($driver instanceof Behat\Mink\Driver\ZombieDriver) {
@dsantuc
dsantuc / ses-smtp-credentials.php
Last active Feb 14, 2018
Deriving Amazon SES SMTP credentials from IAM credentials in PHP.
View ses-smtp-credentials.php
function getSMTPPassword ($key) {
$message = "SendRawEmail";
$hexVersion = "02";
$hexSignature = hash_hmac("sha256", $message, $key);
return base64_encode(hex2bin($hexVersion . $hexSignature));
}
You can’t perform that action at this time.