Skip to content

Instantly share code, notes, and snippets.

View chrisblackwell's full-sized avatar

Chris Blackwell chrisblackwell

View GitHub Profile
@chrisblackwell
chrisblackwell / route53-create.php
Created April 4, 2017 18:33
Create a Route53 domain entry using the AWS SDK
<?php
$s3 = Route53Client::factory(array(
'credentials' => [
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
],
'region' => env('AWS_REGION'),
'version' => 'latest',
));
@chrisblackwell
chrisblackwell / StringCalc.php
Created April 4, 2017 18:31
Calculate the next increment value of a string of numbers and letters
<?php
$testCases[] = '123'; // Should be 124
$testCases[] = '123=RH'; // Should be 124=RH
$testCases[] = '123RH'; // Should be 124RH
$testCases[] = '123R4'; // Should be 124R4
$testCases[] = 'RH123'; // Should be RH124
$testCases[] = 'RH-123'; // Should be RH-124
foreach($testCases as $testCase) {
@chrisblackwell
chrisblackwell / deploy.php
Created April 4, 2017 18:25
Laravel Deployer settings
<?php
namespace Deployer;
require 'recipe/laravel.php';
// Configuration
set('repository', '-- put Git Repo URL here --');
set('ssh_type', 'native');
set('shared_files', ['.env']);
set('shared_dirs', [
'storage/app',
@chrisblackwell
chrisblackwell / dependency-injection.php
Created April 3, 2017 18:48
Dependency Injection Example
<?php
class App
{
/**
* Application Registry
*
* @var array
*/
protected $registry = [];
@chrisblackwell
chrisblackwell / required-params.js
Created November 21, 2016 13:31
JavaScript required parameters
const isRequired = () => { throw new Error('param is required'); };
const hello = (name = isRequired()) => { console.log(`hello ${name}`) };
// This will throw an error because no name is provided
hello();
// This will also throw an error
hello(undefined);
@chrisblackwell
chrisblackwell / VagrantFile
Created December 7, 2015 16:31
Base VagrantFile
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
# Don't check for updates. We'll handle this through Ansible
config.vm.box_check_update = false
config.vm.network :private_network, ip: "192.168.10.10"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 8443
@chrisblackwell
chrisblackwell / wordpress-paths.php
Created November 18, 2015 18:04
Define Absolute Paths in WordPress
if (!defined('MYPLUGIN_THEME_DIR'))
define('MYPLUGIN_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
if (!defined('MYPLUGIN_PLUGIN_NAME'))
define('MYPLUGIN_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
if (!defined('MYPLUGIN_PLUGIN_DIR'))
define('MYPLUGIN_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . MYPLUGIN_PLUGIN_NAME);
if (!defined('MYPLUGIN_PLUGIN_URL'))
@chrisblackwell
chrisblackwell / wordpress-debug-log.php
Created November 18, 2015 17:56
Log WordPress errors instead of showing them on screen
// Turns WordPress debugging on
define('WP_DEBUG', true);
// Tells WordPress to log everything to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
// Doesn't force the PHP 'display_errors' variable to be on
define('WP_DEBUG_DISPLAY', false);
// Hides errors from being displayed on-screen
@chrisblackwell
chrisblackwell / getUserIP.php
Created November 9, 2015 03:56
Get the IP address of the current user
private function getUserIP()
{
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP)) {
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP)) {
@chrisblackwell
chrisblackwell / catch-all-route.php
Created September 6, 2015 01:38
Laravel Catch-All Route
Route::group(['middleware' => 'auth'], function () {
Route::get('{view}', function ($view) {
try {
return view($view);
} catch (\Exception $e) {
abort(404);
}
})->where('view', '.*');
});