Skip to content

Instantly share code, notes, and snippets.


Alexander Karlstad carestad

View GitHub Profile
carestad /
Last active December 16, 2021 05:58
Build DisplayLink docking driver for newer kernel verions
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
View LogTrait.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 / 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.
View TimedTrait.php
namespace App\Console\Commands\Traits;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
trait TimedTrait
carestad / Timestamp.php
Last active May 26, 2021 08:15
Doctrine DBAL Timestamp type for use with Laravel
View Timestamp.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 / FooRequest.php
Last active December 8, 2020 18:16
[Laravel] Return validation errors as proper object/arrays
View FooRequest.php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class FooRequest extends FormRequest
public function authorize()
carestad /
Last active January 25, 2023 16:00
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:
# From:
thisdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
carestad /
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.
# Author: Alexander Karlstad <carestad@github>
# Updated: 2019-07-17
# Configurable variables
slack_user="apt@$(hostname -f)"

Keybase proof

I hereby claim:

  • I am carestad on github.
  • I am karlstad ( on keybase.
  • I have a public key ASBdjb4nFyklP4MvxzxDntz8_HIN-VFz1SKRfFHtBqUJbAo

To claim this, I am signing this object:

carestad / convert-first-page-pdf-to-jpg.php
Created February 22, 2019 11:54
Convert first page of PDF to JPG thumbnail in PHP
View convert-first-page-pdf-to-jpg.php
$file = '/foo/bar/document.pdf';
$im = new \Imagick($file);
$im->setIteratorIndex(0); // just use first page
$im->setImageAlphaChannel(\Imagick::VIRTUALPIXELMETHOD_WHITE); // Other alpha options are available, see Imagick PHP documentation
$im->setImageColorspace(\Imagick::COLORSPACE_SRGB); // Other colorspaces are available, see Imagick PHP documentation
$im->setImageBackgroundColor('white'); // Set transparent background elements to this color
$im->setFormat('JPG'); // Format, a wide variety is supported
carestad /
Last active March 3, 2022 19:07
Collection of slides from #vuejsamsterdam 2019

Day 1

Time Speaker(s) Title
08:45 Evan You State of the Vuenion (Founder of Vue.js)
09:00 Sarah Drasner
Guillaume Chau
Advanced Animations with Vue.JS (Vue.js Core Team)
SSR revolution with Vue 2.6
09:35 Tim Benniks Vue.js for L'oreal, a case study (Director of Frontend @Valtech Paris)
10:45 Jen Looper NativeScript-Vue + ML = The Great MiniBar Challenge: MixoLogy (Developer Advocate at Progress)
11:15 Filip Rakowski Modern Web Apps Performance Tricks with PWA and Vue.js (Founder Vue Storefront)
11:50 Sara Vieira [GraphQL + Apollo + Vue.js =