Skip to content

Instantly share code, notes, and snippets.

@benrolfe
benrolfe / featured-events.twig
Created December 17, 2021 15:09
Display featured events
@benrolfe
benrolfe / functions.php
Last active December 10, 2021 13:26
Create / Delete / Check cookies
add_action( 'wp', 'action_cookies' );
function action_cookies() {
global $post;
// abort if not a page/post
if(! $post)
{
return;
@benrolfe
benrolfe / backup.sh
Created February 10, 2020 10:45
Backup script for MySQL on Ubuntu
#!/bin/bash
#----------------------------------------
# OPTIONS
#----------------------------------------
USER='XXXXXX'
PASSWORD='XXXXXX'
DAYS_TO_KEEP=7
GZIP=0
BACKUP_PATH='backups/mysql'
#----------------------------------------
@benrolfe
benrolfe / Dockerfile
Last active May 18, 2022 12:30
Docker: PHP 7.1 with Apache and MSSQL
FROM php:7.1-apache
# Get repository and install wget and vim
RUN apt-get update && apt-get install --no-install-recommends -y \
wget \
gnupg \
git \
unzip
# Install PHP extensions deps
@benrolfe
benrolfe / docusign-multiple-templates.txt
Created November 15, 2016 10:00
docusign-multiple-templates
X-DocuSign-Authentication: {"Username":"YOUR_USER_NAME","Password":"YOUR_PASSWORD","IntegratorKey":"YOUR_INTEGRATOR_KEY"}
Content-Type: multipart/form-data; boundary=5cd3320a-5aac-4453-b3a4-cbb52a4cba5d
Accept: application/json
--5cd3320a-5aac-4453-b3a4-cbb52a4cba5d
Content-Type: application/json
Content-Disposition: form-data
{
"status": "sent",
@benrolfe
benrolfe / ghosttest.sh
Last active August 29, 2015 14:14
Protect your Linux Server Against the GHOST Vulnerability (CVE-2015-0235)
#!/bin/sh
apt-get -qq update
apt-get install -yy gcc
cat <<EOF > ghosttest.c
/* ghosttest.c: GHOST vulnerability tester */
/* Credit: http://www.openwall.com/lists/oss-security/2015/01/27/9 */
#include <netdb.h>
@benrolfe
benrolfe / run-background-process.php
Last active December 16, 2015 20:48
We've been working on a project recently where we wanted to run a background CLI script that gets fired from PHP. For example, a user presses a button on your frontend interface that fires off a PHP script that runs in the background for a while. The user can then continue using the site, rather than waiting for the script to finish. You’ll need…
function run_background_process( $file )
{
if ( is_windows() )
{
// create command object
$objShell = new COM( 'WScript.Shell' );
// run windows command
$objShell->Run(
$strCommand = sprintf( 'php %s.php', $file ),
@benrolfe
benrolfe / itunes-byte-request.php
Last active July 10, 2018 21:40
iTunes have recently requested that podcast downloads accept "byte range requests". This PHP code below will set the correct headers and serve up the MP3 file. Set $file_path to the path of the MP3 file. See http://blog.unit6websites.com/post/48778214025/byte-range-requests
<?php
$fp = @fopen( $file_path, 'rb' );
$size = filesize( $file_path );
$length = $size;
$start = 0;
$end = $size - 1;
header( "Accept-Ranges: 0-$length" );