Skip to content

Instantly share code, notes, and snippets.

View mortenscheel's full-sized avatar

Morten Scheel mortenscheel

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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);