Skip to content

Instantly share code, notes, and snippets.

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@stevenmc
stevenmc / mysql_field_default_as_function.sql
Created October 30, 2015 14:44
Set default value of mysql field to function.
CREATE TRIGGER before_insert_news_item
BEFORE INSERT ON news
FOR EACH ROW
SET new.created = now();
@stevenmc
stevenmc / mailgun.php
Created September 29, 2015 14:35
Send email with Mailgun via cURL
function mailgun($message = null, $to = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:key-abc');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$plain = strip_tags($message);
#!/bin/bash
#
# Presume suspicious_euclid is the id of the Docker container, from docker ps
# Requirements: nsenter - https://blog.codecentric.de/en/2014/07/enter-docker-container/
# Suggestion: move to /usr/local/bin and remove the sh extension, then you just run dockerssh suspicious_euclid
# Usage: sudo ./dockerssh.sh suspicious_euclid
if [ -z "$1" ]; then
echo "Please pass a docker container id or name to this script."
exit;
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@stevenmc
stevenmc / NGinxConnectionThrottling
Created May 9, 2014 19:27
How to limit/throttle site speeds to test performance on Nginx servers
location / {
if ( $remote_addr ~* 192.133.125.0/24 ) {
limit_rate 3k;
}
if ( $remote_addr ~* 165.135.0.0/16 ) {
limit_rate 3k;
}
@stevenmc
stevenmc / UK Phone number lookup
Created August 22, 2013 16:24
Basic implementation of https://github.com/giggsey/libphonenumber-for-php or https://github.com/practo/libphonenumber-for-php within CakePHP Model for phone number validation.
<?php
/**
* Presumes you've installed Composer in the directory according to http://getcomposer.org/doc/01-basic-usage.md
*/
require_once(APP . 'Vendor' . DS. 'LibPhoneNumber' . DS . 'src' . DS . 'libphonenumber'. DS ."PhoneNumberUtil.php");
require_once(APP . 'Vendor' . DS. 'LibPhoneNumber' . DS . 'src' . DS . 'libphonenumber'. DS ."CountryCodeToRegionCodeMap.php");
require_once(APP . 'Vendor' . DS. 'LibPhoneNumber' . DS . 'src' . DS . 'libphonenumber'. DS ."PhoneNumber.php");
require_once(APP . 'Vendor' . DS. 'LibPhoneNumber' . DS . 'src' . DS . 'libphonenumber'. DS ."data" . DS . "PhoneNumberMetadata_GB.php");
require_once(APP . 'Vendor' . DS. 'LibPhoneNumber' . DS . 'src' . DS . 'libphonenumber'. DS ."PhoneMetadata.php");
require_once(APP . 'Vendor' . DS. 'LibPhoneNumber' . DS . 'src' . DS . 'libphonenumber'. DS ."PhoneNumberDesc.php");
@stevenmc
stevenmc / aws.class.php
Created January 24, 2013 16:12
CakePHP implementation of Amazon AWS SDK For PHP 2 to implement uploading a file to S3 bucket, listing the content, and deleting items.
<?php
/*
This is a fully working Class to upload, list and delete items from an Amazon S3 bucket.
Add your Config::write/Config::read variables as appropriate. Presumed region: US_EAST_1
Download the most recent cacert.pem from http://curl.haxx.se/docs/caextract.html
To install on a new machine, create a file called composer.json and add this:
{
"require": {
"aws/aws-sdk-php": "*"
}