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 / 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 / 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 / laravel-superglobals-cheat-sheet.php
Last active February 21, 2023 20:49
Laravel superglobals cheat sheet
<?php
$_SERVER['HTTP_HOST'] = Request::getHttpHost();
$_SERVER['HTTP_HOST'] = request()->getHttpHost();
// Alternative could be to use URL::previous(), but this will always return current URL if no referer is present.
// @see https://github.com/laravel/framework/blob/5.7/src/Illuminate/Routing/UrlGenerator.php#L154
$_SERVER['HTTP_REFERER'] = Request::header('referer', 'default');
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = Request::getPreferredLanguage();
@carestad
carestad / README.md
Last active January 13, 2023 16:24
TTML to SRT conversion. Written in PHP.

ttml2srt.php

This is a simple script for converting TTML subtitle files to SRT ones. Tested with TTML files on tv.nrk.no.

It assumes the data is structured like this:

<tt>
 <body>
  <div>
   <p>(...)</p>
@carestad
carestad / vuejs.amsterdam.2019.slides.md
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 =
@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;