Skip to content

Instantly share code, notes, and snippets.

View othyn's full-sized avatar
🏳️‍🌈
Be kind, and have an adventure.

Ben othyn

🏳️‍🌈
Be kind, and have an adventure.
View GitHub Profile
@othyn
othyn / laravel-production-permissions.md
Created January 1, 2019 10:45 — forked from barbietunnie/laravel-production-permissions.md
MySQL Database User GRANT permissions for Laravel

MySQL Database User GRANT permissions for Laravel

For security reasons, you should probably grant select, delete, update and insert to your app user in production.

Have another user who can do alter, create, drop and index when running migrations.

If you run seeders in production, also grant select, insert and references to the migration user.

Yeah, 2 users, migrations are not always run in production everyday and this keeps more secure your database.

@othyn
othyn / extract_table_from_mysql_dump.sh
Created May 14, 2019 10:37
Short bash script to extract a table from a MySQL dump, designed to perform well on large files! :)
#!/bin/bash
USAGE="\n\x1b[31mUsage:\x1b[0m extract_table_from_mysql_dump.sh my_table /path/to/dump.sql\n\x1b[32mOptional 3rd parameter:\x1b[0m /path/to/export/to\nThe export filename will default to extracted_{my_table}.sql\n"
if [[ -z "$1" ]] ; then
printf "$USAGE"
exit 1
fi
# Check the table name was provided
if [[ -z "$2" ]] ; then
@othyn
othyn / mount_pi_image.sh
Created May 14, 2019 11:08
Mount a Raspberry Pi image of your choice :)
#!/bin/bash
# Globals
TIMESTAMP=$(date +%s)
MOUNT_DIR="/mnt"
BASE_MOUNT_DIR="$MOUNT_DIR/image_$TIMESTAMP"
MOUNT_IMAGE=""
# Usage declaration
display_usage() {
@othyn
othyn / php_cli_table.php
Created January 7, 2020 14:24
Quick PHP table output for console
<?php
/**
* A quick way, with a bit of overhead, to get nice tabular output
* from a PHP CLI app.
*
* Sometimes I find myself just requiring very quick and dirty
* tabular output and find this to be the path of least resistance.
*
* This method utilises Symfony's Console's Table and BufferedOutput
@othyn
othyn / entrypoint.sh
Last active February 5, 2020 16:40
Docker entrypoint.sh to launch either sh/bash or node depending on the script shebang executable type. This came from a personal circumstance where to save resources, one node image could be used to run shell scripts and node scripts that both performed actions against the same resource. This condensed 4 containers into 1, giving the same result.
#!/bin/sh
set -e
FIRST_LINE=$(head -n 1 "${1}")
# As the scripts can be either JS or shell, determine how to exec!
if [ "${FIRST_LINE}" = "#!/bin/sh" ] || [ "${FIRST_LINE}" = "#!/bin/bash" ]; then
eval "./$@"
else
# https://github.com/nodejs/docker-node/blob/master/docker-entrypoint.sh
@othyn
othyn / ChangePasswordController.php
Last active July 25, 2020 04:46
Laravel 6.x change password (Routes, Controller, Request & View)
<?php
/*
* app/Http/Controllers/Auth/ChangePasswordController.php
*
* Made via the command:
* $ php artisan make:controller Auth/ChangePasswordController -r
*
* This is the custom controller that will do all the heavy lifting for
* changing the users password.
@othyn
othyn / laravel_package_recommendations.md
Last active October 20, 2021 09:41
My top recommended Laravel packages
Package (in Alphabetical Order) Description
@othyn
othyn / switch-brew-node.sh
Created December 4, 2021 13:11
Easy ZSH/Bash alias for swapping Node versions on the fly
# Switch Node version in brew
# Place this in your ~/.bashrc or similar for autoload into your shell
function nodesw() {
if [ -z "$1" ]; then
logInfo "You need to provide a Node formulae version to switch to in format:"
logInfo "$ nodesw 16"
if command -v jq >/dev/null 2>&1; then
logInfo "Installed Node versions via Brew:"
brew info --json node | jq -r '.[].versioned_formulae[]'
@othyn
othyn / switch-brew-php.sh
Last active December 4, 2021 13:11
Easy ZSH/Bash alias for swapping PHP versions on the fly
# Switch PHP version in brew
# Place this in your ~/.bashrc or similar for autoload into your shell
function phpsw() {
if [ -z "$1" ]; then
logInfo "You need to provide a PHP formulae version to switch to in format:"
logInfo "$ phpsw 8.1"
if command -v jq >/dev/null 2>&1; then
logInfo "Installed PHP versions via Brew:"
brew info --json php | jq -r '.[].versioned_formulae[]'
@othyn
othyn / switch-kubectl-context.sh
Last active December 4, 2021 13:18
Easy ZSH/Bash alias for swapping kubectl contexts on the fly
# List available kubectl contexts
# Based on the below command context storage mechanism
function kswl() {
echo "Listing available kubectl contexts:"
ls -lah ~/.kube/*-config.yaml
}
# Switch kubectl context
# Context files should be stored in the format: ~/.kube/{context_name}-config.yaml
function ksw() {