Skip to content

Instantly share code, notes, and snippets.

View mortenscheel's full-sized avatar

Morten Scheel mortenscheel

View GitHub Profile
@mortenscheel
mortenscheel / laravel-monolog-permissions
Last active April 5, 2017 13:52
Laravel Monolog configuration to avoid permission problems when daily log files are created by artisan
// Add to bootstrap/app.php
/**
* Configure Monolog.
*/
$app->configureMonologUsing(function(Monolog\Logger $monolog) {
// Make different log files for web and cli to avoid permission problems
$filename = storage_path('logs/laravel-'.php_sapi_name().'.log');
$handler = new Monolog\Handler\RotatingFileHandler($filename);
$monolog->pushHandler($handler);
@mortenscheel
mortenscheel / Danish addresses parser
Last active April 5, 2017 13:56
Regex to extract components of Danish street addresses
/^([^0-9]*)([0-9]*)\s*([A-Z]?)[,\s]*([0-9]*)?(st|kl)?[\.,\s]*([a-zæøå]*)?(\d{0,4})?.*$/mi
@mortenscheel
mortenscheel / entrust-user-permission.md
Last active February 16, 2019 16:55 — forked from uzegonemad/entrust-user-permission.md
Entrust Laravel 5.3+ User Permissions

Edits

All credit goes to uzegonemad. I've only added the following.

  1. Now supports Laravel 5.3+ (using pluck() method in stead of lists())
  2. The methods attachPermission() and detachPermission() now accept strings (name of the permission)
  3. Permissions are reloaded before can() checks to ensure they are up to date.

What is this?

Entrust is a fantastic role-based permission library for Laravel. However, by design, it only supports attaching permissions to roles, not to users.

@mortenscheel
mortenscheel / DefaultStrategyButKeepOnlyOneLocalBackup.php
Created July 2, 2019 07:38
Extension to spatie/laravel-backup DefaultStrategy
<?php
namespace App\Helpers;
use Illuminate\Filesystem\Filesystem;
use Spatie\Backup\BackupDestination\Backup;
use Spatie\Backup\BackupDestination\BackupCollection;
use Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy;
class DefaultStrategyButKeepOnlyOneLocalBackup extends DefaultStrategy
@mortenscheel
mortenscheel / Readme.md
Created June 30, 2020 19:58
WIndows 10 Chocolatey and Scoop install snippets

Install Windows dependencies

  1. Install Chocolatey and Scoop in PowerShell (admin rights)
    Set-ExecutionPolicy Bypass -Scope Process -Force
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
    iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
    iwr -useb get.scoop.sh | iex
  2. Install apps and tools from normal terminal
@mortenscheel
mortenscheel / QTableOptimizerMixin.js
Last active August 8, 2020 12:43
Quasar mixin to automatically set QTable rowsPerPage to fit container height
/**
* The host component/page must have a QTable with ref="table" and :pagination.sync="pagination"
* The optimal row count is calculated in relation to the height of the element wrapping the <q-table>
*/
const getElementHeight = (el, selector) => {
const target = selector ? el.querySelector(selector) : el;
return target ? parseFloat(getComputedStyle(target).height) : 0;
};
@mortenscheel
mortenscheel / DSP seeds.txt
Last active June 2, 2021 16:46
Dyson Sphere Program seeds
18097783
GG fire ice
Lava Ti and Si <1
Ir 2.7
Cu 1.1
Starter base nah
29679915
GG and outer fire ice
Lava ti + Si <1
@mortenscheel
mortenscheel / functions.sh
Last active September 10, 2022 14:31
Laravel specific git hooks for post-checkout and post-merge
#!/usr/bin/env bash
NC='\033[0m' # No Color
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
MAGENTA='\033[0;35m'
notify_about_actions_required() {
changed_files="$(git diff-tree -r --name-status --no-commit-id $1 $2)"
@mortenscheel
mortenscheel / detect_horizontal_overflow.js
Last active August 17, 2022 08:13
Find and highlight DOM elements overflowing the viewport width, causing the horizontal scrollbar to appear.
const detectHorizontalOverflow = (root) => {
root = root || document;
const { offsetWidth } = document.documentElement;
let previousOverflowing = null;
let overflowingCount = 0;
root.querySelectorAll('*').forEach((el) => {
const { right } = el.getBoundingClientRect();
if (right > offsetWidth) {
// Ignore the children of overflowing elements. The issue is probably their parents.
if (previousOverflowing === null || !previousOverflowing.contains(el)) {
@mortenscheel
mortenscheel / php-run-as-sail.sh
Created September 30, 2022 10:52
PHP wrapper script for Laravel Sail and PhpStorm
#!/usr/bin/env sh
runuser -u sail -- php "$@"
# 1. Copy or mount this script into the laravel.test container.
# 2. Setup your remote PHP interpreter in PhpStorm to use the script as "PHP Executable"