Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
Writing code one line at a time

Ben T othyn

👻
Writing code one line at a time
View GitHub Profile
@othyn
othyn / write_win_iso.sh
Last active Aug 21, 2020
Quick script to write a bootable UEFI Windows ISO to USB in macOS
View write_win_iso.sh
#!/bin/bash
# System: Darwin x86_64 19.6.0 (macOS 10.15.6 19G2021)
# Author: Othyn (https://github.com/othyn)
# Source: https://gist.github.com/othyn/29b82e39eb8cdd98adf1be77cbb62700
# Dependencies: pv, wimlib
# Licence: MIT
DEFAULT="\x1b[0m"
RED="\x1b[31m"
@othyn
othyn / LogLevel.php
Last active Sep 15, 2020
RFC 5424 log levels for BenSampo's Laravel Enum package.
View LogLevel.php
<?php
namespace App\Enums;
use BenSampo\Enum\Enum;
/**
* @method static static Emergency()
* @method static static Alert()
* @method static static Critical()
@othyn
othyn / ChangePasswordController.php
Last active Jul 25, 2020
Laravel 6.x change password (Routes, Controller, Request & View)
View ChangePasswordController.php
<?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 / entrypoint.sh
Last active Feb 5, 2020
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.
View entrypoint.sh
#!/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 / php_cli_table.php
Created Jan 7, 2020
Quick PHP table output for console
View php_cli_table.php
<?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 / mount_pi_image.sh
Created May 14, 2019
Mount a Raspberry Pi image of your choice :)
View mount_pi_image.sh
#!/bin/bash
# Globals
TIMESTAMP=$(date +%s)
MOUNT_DIR="/mnt"
BASE_MOUNT_DIR="$MOUNT_DIR/image_$TIMESTAMP"
MOUNT_IMAGE=""
# Usage declaration
display_usage() {
@othyn
othyn / extract_table_from_mysql_dump.sh
Created May 14, 2019
Short bash script to extract a table from a MySQL dump, designed to perform well on large files! :)
View extract_table_from_mysql_dump.sh
#!/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 / laravel-production-permissions.md
Created Jan 1, 2019 — forked from barbietunnie/laravel-production-permissions.md
MySQL Database User GRANT permissions for Laravel
View laravel-production-permissions.md

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 / factorio_headless_guide.md
Last active Sep 9, 2020
How to setup a Factorio Headless Server
View factorio_headless_guide.md

[LINUX] Factorio Headless Server Guide

So, with credit to the Factorio wiki and cbednarski's helpful gist, I managed to eventually setup a Factorio headless server. Although, I thought the process could be nailed down/simplified to be a bit more 'tutorialised' and also to document how I got it all working for my future records.

The specific distro/version I'm using for this guide being Ubuntu Server 16.04.1 LTS. Although, that shouldn't matter, as long as your distro supports systemd (just for this guide, not a Factorio headless requirement, although most distros use it as standard now). The version of Factorio I shall be using is 0.14.20, although should work for any version of Factorio 0.14.12 and higher.

Alternate

If you prefer a simple, automated setup, [Bisa has a really handy init script that will do most of the work for

You can’t perform that action at this time.