Skip to content

Instantly share code, notes, and snippets.

View trovster's full-sized avatar

Trevor Morris trovster

View GitHub Profile
@trovster
trovster / software.sh
Last active January 8, 2020 12:27
Install software via CLI
#!/bin/sh
# chmod a+x software.sh
# Install Brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap homebrew/core
brew tap homebrew/cask
brew tap homebrew/cask-drivers
@trovster
trovster / middlware.php
Created November 9, 2015 16:33
Laravel 5 Middlewere, using AuthorizesRequests trait but adding a custom message based on action (index, show, destroy etc)
<?php
namespace App\Http\Middleware\Admin;
use Closure;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Models\Site as Model;
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\AdminController as Controller;
use App\Models\User\User;
use App\Models\User\Role as UserRole;
use App\Http\Requests\UserRequest;
@trovster
trovster / Controllers-Deposit.php
Created October 29, 2015 10:49
Deposit controller, model and request using Laravel 5.1
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\AdminController as Controller;
use App\Models\Deposit;
use App\Http\Requests\DepositRequest;
@trovster
trovster / AuthController.php
Created October 28, 2015 17:31
Laravel 5.1 Auth functionality.
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use App\Http\Controllers\Controller;
@trovster
trovster / inline_js.html
Created August 26, 2015 10:31
How can I get dynamic variable without eval?
<script type="text/javascript" id="bowling--js">
var bowling_options = [1,2,3,4,5];
</script>
<script type="text/javascript" id="restaurant--js">
var restaurant_options = ['a','b','c'];
</script>
@trovster
trovster / Gruntfile.js
Last active August 29, 2015 14:27
Grunt, Live/Dev WordPress script includes.
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
default: {
// not concatenating jQuery here, production could use CDN
src: [
'wp-content/themes/<%= pkg.theme %>/js/app/app.js',
'wp-content/themes/<%= pkg.theme %>/js/app/options.js',
@trovster
trovster / Migrate.php
Created June 19, 2015 09:29
Ability to migrate database in CodeIgniter, restricted to command line. Also features environment switching using --env
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Migrate extends CI_Controller {
public function __construct() {
parent::__construct();
if (!$this->input->is_cli_request()) {
echo $this->error();
exit;
@trovster
trovster / model.php
Created May 20, 2015 11:58
Laravel Relationship switch?
<?php
/**
* Return the Survey model related to a Project.
* The survey model is based on the projec type.
*
* @return \Survey\Survey|\Survey\FireRisk\Survey
*/
public function survey()
{
return $this->type && $this->type->name === 'Fire Risk' ? $this->fireRiskSurvey() : $this->asbestosSurvey();
@trovster
trovster / wordpress.php
Created April 2, 2015 10:40
CSV Import in WordPress
<?php
/**
* _import_csv
* @desc Import the CSV in to the ACF field.
* @param string $file
* @param int $post_id
* @return boolean
*/
function _import_csv($file, $post_id) {
if(!function_exists('get_field') || !function_exists('update_field') && file_exists($file)) {