Skip to content

Instantly share code, notes, and snippets.

View nathanbarrett's full-sized avatar

Nathan Barrett nathanbarrett

View GitHub Profile
@nathanbarrett
nathanbarrett / GuessesMimeTypesAndExtentions.php
Created January 17, 2018 16:44
Trait for guessing mime types and extensions of files
<?php
namespace App\Traits;
// composer require ralouphie/mimey
use Mimey;
trait GuessesMimeTypesAndExtentions
{
/**
* Guesses the mime type of a file based off of the extension in the file name
@nathanbarrett
nathanbarrett / Dropzone.vue
Last active December 1, 2018 14:40
A Vue component wrapper for dropzone.js that emits all events
<template>
<div :id="id" class="uploader dropzone"></div>
</template>
<script>
import Dropzone from 'dropzone';
Dropzone.autoDiscover = false;
export default {
@nathanbarrett
nathanbarrett / GoogleRecaptchaToken.php
Created February 17, 2019 17:35
Laravel rule for implementing Google's recaptcha V3
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
class GoogleRecaptchaToken implements Rule
@nathanbarrett
nathanbarrett / create_mcc_codes_table.php
Last active April 14, 2019 16:09
Laravel migration for creating a table with Merchant Category Codes
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\MccCode;
class CreateMccCodesTable extends Migration
{
/**
@nathanbarrett
nathanbarrett / google-places-directive.js
Created April 14, 2019 19:02
Vue JS directive for mounting Google's Places Autocomplete on an input
"use strict";
export const addressAutocomplete = {
bind(el, binding) {
const callback = binding.value;
if(callback && typeof callback !== "function") {
console.error("Value for google places directive must be a function");
return;
}
const autocomplete = new google.maps.places.Autocomplete(el, {
@nathanbarrett
nathanbarrett / Modal.vue
Created May 23, 2019 19:25
A Simple Vue JS Modal
<template>
<div class="modal" :class="{show: show}">
<div class="modal-box">
<slot></slot>
</div>
</div>
</template>
<script lang="ts">
import Vue from "vue";
@nathanbarrett
nathanbarrett / s3.js
Created September 14, 2019 14:31
An easy wrapper for browser S3 uploads
import S3 from "aws-sdk/clients/s3";
const s3 = new S3({
apiVersion: '2006-03-01',
accessKeyId: process.env.AWS_S3_BROWSER_KEY_ID,
secretAccessKey: process.env.AWS_S3_BROWSER_SECRET,
region: 'us-east-1',
params: { Bucket: 'your-default-bucket' }
});
@nathanbarrett
nathanbarrett / solar-system.json
Created January 25, 2020 18:45
Solar system information in json format. Distances and speeds are in km and km/hour.
{
"scale": 0.00000000938,
"speedOfLight": 299792458,
"sun": {
"name": "The Sun",
"mapData": {
"iconUrl": "/assets/map/map-icon-sun-new.png",
"infoWindowContent": "It is now about the size of a hot air balloon. Use the address input above to move it all to a location you are more familiar with. You can also drag around the Sun's map icon.<br /> <a href=\"https://free3d.com/3d-model/hot-air-balloon-54348.html\" style=\"font-size: 10px\" target=\"_blank\">Hot Air Balloon Courtesy Of Iridesium</a>",
"infoWindowImageUrl": "/assets/images/comparisons/thesun.png",
"didYouKnow": "The color of the Sun in space is actually mostly white, not yellow or orange. The reason it appears yellow or orange on Earth is due to atmospheric scattering, especially when it is low in the sky."
#!/bin/bash
# This installs all of the necessary base level services
# required for Laravel on a fresh instance of Ubuntu 20.04
# To download and run this script click on the "Raw" button and copy the url for the contents of this gist
# then run the following two commands:
# apt-get update && apt-get install -y curl
# curl -sS {paste gist url} | bash
export DEBIAN_FRONTEND=noninteractive
@nathanbarrett
nathanbarrett / Command.php
Created August 7, 2023 21:59
Laravel command template with extra helpers
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use Illuminate\Console\Command as ConsoleCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Helper\ProgressBar;