Skip to content

Instantly share code, notes, and snippets.

View plasticbrain's full-sized avatar

Mike Everhart plasticbrain

View GitHub Profile
@plasticbrain
plasticbrain / gist:3863711
Created October 10, 2012 07:24 — forked from lucasfais/gist:1207002
Sublime Text: Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@plasticbrain
plasticbrain / max_upload_size.php
Created October 12, 2012 19:25
PHP: max upload size
<?php
$max_upload_in_mb = min((int)(ini_get('upload_max_filesize')), (int)(ini_get('post_max_size')), (int)(ini_get('memory_limit')));
echo $max_upload_in_mb . 'mb';
?>
@plasticbrain
plasticbrain / gist:3883001
Created October 13, 2012 02:44
PHP: Get the full URL of the current page
function current_page($params=NULL, $no_trailing_slash=TRUE) {
// http(s)://domain.com
$url = @$_SERVER['HTTPS'] == 'on' ? 'https://'. $_SERVER['SERVER_NAME'] : 'http://'.$_SERVER['SERVER_NAME'];
// add the port number, if there is one
if( @$_SERVER['SERVER_PORT'] != "80" && @$_SERVER['SERVER_PORT'] != "443" ) $url .= ':'. @$_SERVER['SERVER_PORT'];
// Append the query string
$url .= $_SERVER['REQUEST_URI'];
@plasticbrain
plasticbrain / metrics-curl.rb
Created October 12, 2015 16:01
Sensu - Plugin for checking a page load time via curl
#! /usr/bin/env ruby
#
# metrics-curl
#
# DESCRIPTION:
# Simple wrapper around curl for getting timing stats from the various phases
# of connecting to an HTTP/HTTPS server.
#
# OUTPUT:
# metric data
@plasticbrain
plasticbrain / gist:4151298
Created November 26, 2012 23:15
HTACCESS: Force www
### Force www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301]
@plasticbrain
plasticbrain / gist:4151302
Created November 26, 2012 23:15
HTACCESS: Force https
### Force https://
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
@plasticbrain
plasticbrain / next_occurrence.php
Last active November 13, 2015 22:48
PHP - Calculate the next occurrence of a given date
<?php
// Usage
$occurrences = next_occurrence('Friday', 13);
foreach($occurrences as $day) {
echo $day->format('D M j, Y') . PHP_EOL;
}
@plasticbrain
plasticbrain / MySQL - last accessed tables
Created February 1, 2013 21:55
Get the last accessed tables from database
SELECT table_schema AS DatabaseName,
table_name AS TableName,
update_time AS LastAccessTime,
check_time AS LastCheckTime
FROM information_schema.tables
WHERE update_time < 'yyyy-mm-dd'
GROUP BY table_schema
ORDER BY update_time ASC;
@plasticbrain
plasticbrain / php-send-email.php
Created June 18, 2013 03:03
PHP - Send Email
function send_email( $to, $from, $subject, $message, $html=true ){
// Set the headers
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
if( defined('BCC_CONTACT_EMAIL') ) {
$headers .= 'Bcc: ' . BCC_CONTACT_EMAIL . "\r\n";
}
@plasticbrain
plasticbrain / php-generate-uuid.php
Created June 18, 2013 03:02
PHP - Generate UUID
function uuid() {
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0010
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}