Skip to content

Instantly share code, notes, and snippets.

View dccampbell's full-sized avatar

David C. Campbell dccampbell

View GitHub Profile
@dccampbell
dccampbell / setupEnv.sh
Last active December 27, 2022 14:18
Linux Environment - Initial Setup Script
#!/usr/bin/env bash
echo "=== System Install Starting! ==="
# Variables
DL_DIR="$HOME/Downloads/EnvSetup" && mkdir -p "$DL_DIR"
BIN_DIR="$HOME/bin" && mkdir -p "$BIN_DIR"
source /etc/os-release #loads $UBUNTU_CODENAME
export DEBIAN_FRONTEND=noninteractive
@dccampbell
dccampbell / PrintToPDF.php
Created October 1, 2018 07:08
Minimal PHP example of printing HTML to PDF using Headless Chrome
<?php
$chromeExec = 'google-chrome';
$inputFile = __DIR__.'/input.html';
$outputFile = __DIR__.'/output.pdf';
$version = shell_exec($chromeExec . ' --version 2>&1');
if(!strpos($version, 'Google Chrome') === 0) {
throw new Exception('Google Chrome not found at: '.$chromeExec);
@dccampbell
dccampbell / GoogleOauthWalkthrough.sh
Last active July 11, 2021 23:58
Google OAuth 2.0 Walkthrough Script - script to help step through getting an access token for Google API calls (w/o needing a domain/server)
#!/bin/bash
# Variables
client_id=""
client_secret=""
scopes=""
auth_code=""
access_token=""
@dccampbell
dccampbell / UpdateWebflowRedirects.js
Created March 6, 2021 00:50
Webflow 301 Redirects Batch Updater
/**
* Console-friendly function to batch update 301 redirects in Webflow.
* Existing redirects will be replaced when source matches but target doesn't.
* A rule w/ an empty target will remove existing matches but not replace them.
* Small wait time between each add/remove to allow ajax calls time to finish.
* Intended for use here: https://webflow.com/dashboard/sites/YOURSITE/hosting
* @example updateWebflowRedirects( [{ source: "/old", target: "/new" }] );
*/
async function updateWebflowRedirects(rules) {
# Variables
COMPOSER_HOME="$HOME/.composer"
HOSTS='/etc/hosts'
VHOST='/etc/apache2/sites-available/localdev.conf'
ERRLOG='/var/log/apache2/error.log'
# Fix SSH xterm-256color issue
alias ssh='TERM=xterm-color ssh'
# File Shortcuts
@dccampbell
dccampbell / .env.example
Created February 28, 2020 16:19
Local Dev Environments for PHP Projects w/ Homestead
APP_URL=http://www.myproject.test
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=myprojectdb
DB_USERNAME=homestead
DB_PASSWORD=secret
MAIL_DRIVER=smtp
@dccampbell
dccampbell / webpack.mix.extractjs.js
Last active February 10, 2020 19:03
ExtractJS for Laravel Mix - Extension for code splitting custom JS modules similar to extract() for vendor ones.
let glob = require('glob');
let mix = require('laravel-mix');
let webpackMerge = require('webpack-merge');
/**
* Laravel Mix extension for code splitting custom JS similar to extract() for vendor modules.
* @author @dccampbell
* @example mix.extractJs('/resources/js/api.js', 'public/js')
* @example mix.extractJs('/resources/js/store/*', 'public/js/store.js')
* @example mix.extractJs(['/js/lib.js', '/js/lib.*.js'], 'public/js/lib.js')
@dccampbell
dccampbell / osx_setup_homebrew.sh
Last active January 24, 2020 07:08 — forked from iainconnor/setup.sh
Mac OSX Setup
#!/usr/bin/env bash
# Ask for the administrator password upfront
sudo -v
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || exit 1
# Configure Homebrew
brew doctor
[core]
autocrlf = input
eol = lf
[push]
default = current
[pull]
ff = only
[merge]
ff = false
[diff]
@dccampbell
dccampbell / setupApache.sh
Last active January 14, 2020 03:10
Install Apache, change user to current, enable macro and rewrite modules, set default server name, add a vhost macro, create a localdev site, add commands for easy add/removal of vhost
#!/usr/bin/env bash
## Apache Setup
# Variables
BIN_DIR="/usr/local/bin"
# Install Apache
#sudo apt install -y apache2
# Change Apache User/Group