Skip to content

Instantly share code, notes, and snippets.

View carestad's full-sized avatar
🤗

Alexander Karlstad carestad

🤗
View GitHub Profile
@carestad
carestad / CommandTrait.php
Created August 28, 2023 09:56
Laravel trait to get only self-defined options for command
<?php
namespace App\Console\Commands\Traits;
use Illuminate\Support\Arr;
trait CommandTrait
{
/**
* Get the self-defined options for the command, e.g. exclude Laravel/Symfony's default options
@carestad
carestad / CommandTrait.php
Created July 11, 2023 15:36
Laravel trait with method to only return options defined in command signature, e.g. exclude Laravel/Symfony's default ones like --help and etc.
<?php
namespace App\Console\Commands\Traits;
use Illuminate\Support\Arr;
trait CommandTrait
{
/**
* Get the self-defined options for the command, e.g. exclude Laravel/Symfony's default options
@carestad
carestad / display-link-manual-build-guide.md
Last active March 8, 2023 23:54
Build DisplayLink docking driver for newer kernel verions
@carestad
carestad / LogTrait.php
Created August 18, 2021 11:28
Laravel console command log trait. This adds a few logXX() methods which will append a timestamp in front of the logged text + take verbosity level into account so -vvv can log more than -v
<?php
namespace App\Console\Commands\Traits;
trait LogTrait
{
public function logDebug(string $text, ?string $dateFormat = 'Y-m-d H:i:s'): void
{
/** @var \Illuminate\Console\Command $this */
if (! $this->output->isDebug()) {
@carestad
carestad / TimedTrait.php
Created August 18, 2021 11:22
Laravel console command timed trait. This will always output how long the execution of a Laravel command takes.
<?php
namespace App\Console\Commands\Traits;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
trait TimedTrait
{
/**
@carestad
carestad / Timestamp.php
Last active May 26, 2021 08:15
Doctrine DBAL Timestamp type for use with Laravel
<?php
namespace Database\Migrations\Types;
use DateTime;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\PhpDateTimeMappingType;
use Doctrine\DBAL\Types\Type;
@carestad
carestad / FooRequest.php
Last active December 8, 2020 18:16
[Laravel] Return validation errors as proper object/arrays
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class FooRequest extends FormRequest
{
public function authorize()
{
@carestad
carestad / github-app-jwt.sh
Last active August 24, 2023 10:31
Script to generate JWT for use with Github apps
#!/usr/bin/env bash
# Generate JWT for Github App
#
# Inspired by implementation by Will Haley at:
# http://willhaley.com/blog/generate-jwt-with-bash/
# From:
# https://stackoverflow.com/questions/46657001/how-do-you-create-an-rs256-jwt-assertion-with-bash-shell-scripting
thisdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@carestad
carestad / apt-slack.sh
Last active July 17, 2019 07:59
Script to notify on Slack when updates are available in APT. Logs already reported packages on a $0.log file.
#!/bin/bash
#
# Author: Alexander Karlstad <carestad@github>
# Updated: 2019-07-17
# Configurable variables
slack_channel="@alexander"
slack_icon=":information_source:"
slack_user="apt@$(hostname -f)"
slack_webhook=""

Keybase proof

I hereby claim:

  • I am carestad on github.
  • I am karlstad (https://keybase.io/karlstad) on keybase.
  • I have a public key ASBdjb4nFyklP4MvxzxDntz8_HIN-VFz1SKRfFHtBqUJbAo

To claim this, I am signing this object: