Skip to content

Instantly share code, notes, and snippets.

@benrolfe
benrolfe / gist:2035324
Created March 14, 2012 09:20
Make jQuery Cycle fluid width
$('#slideshow').cycle({
containerResize: false,
slideResize: false,
fit: 1
});
@benrolfe
benrolfe / gist:2035335
Created March 14, 2012 09:22
Smooth Scrolling to anchor tag
$('document').ready(function(){
$('a.link').click(function(e) {
$('html, body').stop().animate({
scrollTop: $($(this).attr('href')).offset().top
}, 1300, 'easeInOutExpo');
@benrolfe
benrolfe / geocode
Created July 19, 2012 15:36
Geocode location using Open Street Map
$params = array(
'q' => $location . ',UK',
'format' => 'json',
'countrycodes' => 'gb',
'limit' => '1',
'viewbox' => '-10.94,59.42,2.61,49.92',
'bounded' => '1',
'addressdetails' => '1',
);
@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" );
@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 / 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 / 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 / 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