Skip to content

Instantly share code, notes, and snippets.

View mortenson's full-sized avatar
💧
Did you try to clear cache?

Samuel Mortenson mortenson

💧
Did you try to clear cache?
View GitHub Profile
@mortenson
mortenson / example_alpine_autocomplete.sfc
Created July 8, 2020 14:04
Drupal single file components livewire demo
<!--
This is a complex but realistic example of how you might use frameworks like
Alpine.js and dom-diffing libraries like morphdom to create components that
are re-rendered server-side. This example is heavily influenced by Livewire.
In production, it might make more sense for just the dynamic part of the
component to be AJAX-ified, in this case that would probably mean making the
autocomplete results their own component. There are lots of ways to do this!
-->
@mortenson
mortenson / notes.md
Last active August 26, 2023 03:35
Dell XPS 13 9300 Ubuntu setup notes

Random notes from woring with a new XPS 13 9300 with Ubuntu

Notes from when I was on the default Dell OEM Ubuntu

Disable trackpad middle click:

sudo vim /usr/share/X11/xorg.conf.d/40-libinput.conf

Add Option "ButtonMapping" "1 1 3 4 5" under

@mortenson
mortenson / static.sh
Created October 31, 2019 23:10
An example script that caches Tome Static builds by copying the static directory and database to /tmp between builds. Useful on CI.
#!/bin/bash
# This directory should persist between builds.
CACHE_DIR=/tmp/tome_static
set -e
composer install
mkdir -p "$CACHE_DIR"
@mortenson
mortenson / index.js
Last active September 11, 2020 09:26
A quick CSS audit script for finding overly long/specific selectors in CSS files
#!/usr/bin/env node
// This is a quick CSS audit script I wrote for finding overly long/specific selectors in CSS files.
// Usage: Download this file, then run:
// $ npx https://gist.github.com/mortenson/628fd527a25efe4fd1a4940e14c31066 <space separated list of CSS files to audit>
const listSelectors = require('list-selectors');
const { calculate, compare } = require('specificity');
// This is useful if you want to anonymize the results to avoid blaming.
@mortenson
mortenson / DiceRoll.php
Created August 29, 2019 18:04
Thinking about how Drupal 8 single file components could abstractly provide forms and derive other plugins like blocks
<?php
namespace Drupal\sfc_example\Plugin\SingleFileComponent;
use Drupal\Core\Form\FormStateInterface;
use Drupal\sfc\ComponentBase;
/**
* Contains an example component that provides a block.
*
@mortenson
mortenson / DrupalComponents.php
Last active August 4, 2019 14:50
Thinking about single file Drupal frontend components... Edit: Now live at https://drupal.org/project/sfc !
<?php
class SayHello implements ComponentInterface {
const name = 'sayhello';
const template = <<<TWIG
{% embed "@components/bigtext" %}
{% block content Hello {{ name }}! %}
{% endembed %}
@mortenson
mortenson / EditorImageStyle.php
Last active June 26, 2019 23:10
A custom Drupal 8 filter plugin to use an image style for image embedss custom Drupal 8 filter plugin to use an image style for image embeds. A custom Drupal 8 filter plugin to use an image style for image embeds.
<?php
namespace Drupal\ppdx_editor\Plugin\Filter;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Image\ImageFactory;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\file\FileInterface;
use Drupal\filter\FilterProcessResult;
@mortenson
mortenson / Dockerfile
Created June 5, 2019 13:24
Example render.com Dockerfile for Tome
FROM php:7.2-apache
RUN apt-get update && \
apt-get install -y --no-install-recommends git zip openssh-client sqlite3 libsqlite3-dev
# This is copied from the official Docker "drupal" image's Dockerfile.
# install the PHP extensions we need
RUN set -ex; \
\
if command -v a2enmod; then \
@mortenson
mortenson / config.yml
Created April 22, 2019 14:53
Example Tugboat (tugboat.qa) configuration for Tome
services:
php:
image: tugboatqa/php:7.2-apache
default: true
depends: mysql
commands:
init:
- docker-php-ext-install opcache
- a2enmod headers rewrite
- wget -O /usr/local/bin/drush
@mortenson
mortenson / netlifybug.sh
Last active March 27, 2019 04:04
Replicate a bug with failed manual deploys and Netlify
#!/usr/bin/env bash
# Use: Create an empty directory and download this file as netlifybug.sh
# Then, run "netlify link", then ./netlifybug.sh.
# Use default deploy path (".") at prompts.
# You should see a failed deploy first, then a successful deploy after.
mkdir -p subdir
touch index.html subdir/index.html
RAND=$(openssl rand -base64 12)