Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
😁
Having fun

Jose Robinson jrobinsonc

😁
Having fun
View GitHub Profile
@jrobinsonc
jrobinsonc / README.md
Last active October 15, 2018 12:33 — forked from Greg-Boggs/README.md
Drupal Site Building Best Practices

Better Drupal Building

  • Custom glue should be accomplished with configuration first and PHP code second.

Configuration Management and Dependencies

  • Use Composer (or Drush Make) to build your project and it's depencies.
  • Store your work in files.
  • Set your config directory above the webroot.
  • Sync UUIDs across all developers.

Theming

@jrobinsonc
jrobinsonc / PHP composer tools.md
Created September 8, 2017 03:03 — forked from davebarnwell/PHP composer tools.md
Global installation of PHP tools with Composer

Global installation of PHP tools with Composer

To install a composer package globally, you run the usual require command, but with the addition of the global modifier. So to install PHPUnit, you would run:

$ composer global require phpunit/phpunit
$ composer global require phpunit/dbunit
$ composer global require phing/phing
$ composer global require phpdocumentor/phpdocumentor
$ composer global require sebastian/phpcpd
@jrobinsonc
jrobinsonc / browserSync.js
Created September 3, 2017 03:02
BrowserSync using a middleware
browserSync.init({
middleware: [
// Displaying views
function (req, res, next) {
if (req.url === '/') {
req.url = '/views/index.html';
} else if (/^\/[^\/]+$/.test(req.url)) {
const file = `${__dirname}/dist/views${req.url}.html`;
if (fs.existsSync(file)) {
@jrobinsonc
jrobinsonc / on-error.js
Last active August 30, 2017 19:21
Handling JavaScript errors with Google Analytics
// https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions
window.onerror = function(errorMsg, url, line, lineColumn, errorObj) {
ga('send', 'exception', {
'errorMsg': errorMsg,
'url': url,
'line': line,
'lineColumn': lineColumn,
'errorObj': JSON.stringify(errorObj)
});
};
_
@jrobinsonc
jrobinsonc / wordpress-https-redirect.md
Last active January 29, 2020 14:26
WordPress - Redirect to HTTPS (SSL)
if (!is_ssl()) {
    wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301);
    exit;
}
function addJS(id, url) {
if (document.getElementById(id)) {
return;
}
const fjs = document.getElementsByTagName('script')[0];
const js = document.createElement('script');
js.id = id;
js.src = url;
@jrobinsonc
jrobinsonc / php-auth.php
Last active October 25, 2018 09:52
PHP Basic Authentication
<?php
$auth_users = [
'sysadmin' => 'kjhgkjhgkjhg'
];
if (!isset($_SERVER['PHP_AUTH_USER']) || !array_key_exists($_SERVER['PHP_AUTH_USER'], $auth_users)
|| !isset($_SERVER['PHP_AUTH_PW']) || ($_SERVER['PHP_AUTH_PW']) !== ($auth_users[$_SERVER['PHP_AUTH_USER']])) {
header('WWW-Authenticate: Basic realm="Admin"');
header('HTTP/1.1 401 Access Denied');
@jrobinsonc
jrobinsonc / sourcetree.md
Last active June 29, 2017 17:46
SourceTree custom actions

Cherry pick - no commit

Script: git
Parameters: cherry-pick -n $SHA

Merge - fast-forward

Script: git
Parameters: merge --ff $SHA

@jrobinsonc
jrobinsonc / send-request.php
Last active June 26, 2017 18:04
Send GET and POST requests with file_get_contents.
<?php
function sendRequest($method, $url, $content = '', $headers = []) {
$opts = [
'http' => [
'method' => $method,
'header' => implode("\r\n", $headers),
'content' => $content
]
];