Skip to content

Instantly share code, notes, and snippets.

@fjahn
fjahn / statamic-move-assets.sh
Created April 2, 2021 08:12
Statamic Move Assets
#!/bin/bash
set -e
ASSET_PATH='./public/assets'
UPDATE_PATHS=('./content' './resources')
# Make sure we are in project root
if ! grep --quiet 'statamic/cms' composer.json 2> /dev/null
then
@fjahn
fjahn / deletionEndpoint.mjs
Last active November 23, 2023 07:15
Facebook Data Deletion Callback
import crypto from 'crypto'
import parseSignedRequest from './parseSignedRequest.mjs'
import { instance as fileStorage } from '../ConfirmingFileStorage.mjs'
import { getLogger } from '../logger.mjs'
import { toAbsoluteUrl } from '../util.mjs'
const logger = getLogger('deletionEndpoint')
export function registerHandles (app) {
@fjahn
fjahn / UriBuilder.php
Created April 20, 2021 08:40
Builder class for building clean and simple URIs every time
<?php
namespace App\Util;
class UriBuilder
{
private string|null $protocol;
private string|null $host = null;
private array $path_segments = [];
private array $query_parameters = [];
@fjahn
fjahn / readable-text-mixin.scss
Created May 5, 2021 09:53
Readable Text Mixin
/**
Ensures that text is readable on any background.
Stolen from https://stackoverflow.com/questions/23968961/css-how-can-i-make-a-font-readable-over-any-color#43135326
*/
@mixin readable-shadow($size, $color: white) {
text-shadow:
#{0.01 * $size}em 0 $color,
0 #{0.01 * $size}em $color,
#{-0.01 * $size}em 0 $color,
0 #{-0.01 * $size}em $color,
@fjahn
fjahn / AuthorFilter.php
Created August 31, 2021 07:32
Statamic filter for authors
<?php
namespace App\Scopes;
use Illuminate\Support\Facades\Auth;
use Statamic\Query\Scopes\Filter;
class AuthorFilter extends Filter
{
public $pinned = true;
@fjahn
fjahn / readCsv.php
Last active September 1, 2021 14:54
Parse CSV file
<?php
function readCsv(string $filepath, string $separator = ';'): array
{
$csv = file_get_contents($filepath);
$lines = explode("\n", $csv);
$head = str_getcsv(array_shift($lines), $separator);
$data = [];
$lineNumber = 1;
@fjahn
fjahn / stream_download.php
Created September 9, 2021 07:21
Laravel Stream Download
<?php
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* Similar to Storage::download, but serves the file as a stream.
*
* Stolen and adapted from stackoverflow.com/questions/44965777/laravel-5-file-downloads-stream-or-download
@fjahn
fjahn / Dockerfile
Last active October 5, 2021 11:47
Dockerfile for Statamic
FROM php:8-cli
VOLUME /app
WORKDIR /app
RUN apt update && apt install -y \
tini \
libonig-dev \
&& rm -rf /var/lib/apt/lists/*
@fjahn
fjahn / Dockerfile
Created October 5, 2021 11:53
Composer Dockerfile
FROM composer:2
FROM php:8-cli
COPY --from=composer /usr/bin/composer /usr/bin/composer
VOLUME /app
WORKDIR /app
RUN apt update && apt install -y \
@fjahn
fjahn / add-cronjob.sh
Created December 15, 2021 10:53
Add Cronjob via bash
#!/bin/bash
# Idea stolen from https://stackoverflow.com/questions/610839/how-can-i-programmatically-create-a-new-cron-job#13355743
addCronjob() {
user=$(whoami)
(crontab -u "$user" -l 2>/dev/null || echo '' ; echo "$1") \
| sort - \
| uniq - \