Skip to content

Instantly share code, notes, and snippets.

View johndwells's full-sized avatar

John D Wells Jr johndwells

View GitHub Profile
@johndwells
johndwells / .htaccess
Last active August 26, 2019 16:36
Directive to block WP bots
<IfModule mod_alias.c>
# Wordpress bots
RedirectMatch 404 (wp-login|wp-admin|wp-config|wp-content|wp-includes|xmlrpc)
</IfModule>
@johndwells
johndwells / cachebust.conf
Created August 10, 2019 23:13
NGINX - Cachebust static JS and CSS assets that contain a version segment
# Cachebust static JS and CSS assets that contain a version segment, e.g.
# /css/app.purged.min.v0.1.45.css ==> /css/app.purged.min.css
location ~* (.+)\.v(?:[\d\.]+)\.(js|css)$ {
try_files $uri $1.$2;
}
@johndwells
johndwells / rename.sh
Created July 18, 2019 16:52
Recursively rename *.html file extensions to *.twig
find . -name '*.html' -exec sh -c 'mv "$0" "${0%.html}.twig"' {} \;
@johndwells
johndwells / craft.php
Created June 25, 2019 10:51
Spin up Craft from external file
<?php
namespace Craft;
// Initialize Craft without letting it take over the whole request
$app = require '../craft/app/bootstrap.php';
// Load plugins
$app->plugins->loadPlugins();
@johndwells
johndwells / .env-REMOTE.sh
Last active May 27, 2020 14:56
Starter craft-scripts file for Craft3 development running on DDEV
source "/var/www/html/scripts/.env-local.sh"
# -- REMOTE settings --
# Remote ssh credentials, user@domain.com and Remote SSH Port
REMOTE_SSH_LOGIN="REPLACE_ME"
REMOTE_SSH_PORT="22"
# Should we connect to the remote database server via ssh?
REMOTE_DB_USING_SSH="yes"
@johndwells
johndwells / search.json
Created September 19, 2018 16:29
Modify Craft3 Element Query to select only specific columns, and return as JSON response
{% set results = craft.entries
.search({
query: craft.request.getQuery('q'),
subLeft: true,
subRight: true
})
.select('content.title,elements_sites.uri')
.createCommand()
.queryAll() %}
@johndwells
johndwells / BasePlugin.php
Created August 21, 2018 15:44
A base plugin to extend Craft3's base plugin. Adds static logging interface and self::$plugin reference to instance.
<?php
namespace namesplace\pluginhandle\base;
use Craft;
use craft\base\Plugin as CraftPlugin;
use craft\log\FileTarget;
class Plugin extends CraftPlugin
{
@johndwells
johndwells / cefc7b7506f9810b5f97a031ef771cf9fe5941dd.css
Last active April 20, 2018 15:53
CSS & JS for GT Concep Survey
@charset "UTF-8";/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inh
@johndwells
johndwells / gulpfile.js
Created May 13, 2016 08:56
A gulp task for syncing remote files to local, specifically with CraftCMS in mind.
/*
* Load plugins
*/
var gulp = require('gulp'),
rsync = require('rsyncwrapper').rsync;
// https://www.npmjs.com/package/rsyncwrapper
// http://craftcms.stackexchange.com/questions/1415/is-there-an-easy-way-to-download-the-assets-directory-to-a-local-install
// http://unix.stackexchange.com/questions/2161/rsync-filter-copying-one-pattern-only
@johndwells
johndwells / SassMeister-input-HTML.html
Last active August 29, 2015 14:27
Generated by SassMeister.com.
<div class="widget">
<div class="widget__cog">Cog</div>
</div>