This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Some\Namespace\I\Dont\Trust; | |
function unserialize($data, array $options = []) { | |
if (empty($options)) { | |
$options = [ | |
'allowed_classes' => [ | |
\DateTime::class, // Set to classes used in namespace. | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// You shouldn't call this at runtime - do it when something builds (ex: plugins) and store the args somewhere. | |
function get_autowire_args(callable $callback, \Drupal\Component\DependencyInjection\Container $container) { | |
$cache = &drupal_static(__FUNCTION__); | |
$args = []; | |
$reflection = new \ReflectionFunction($callback); | |
foreach ($reflection->getParameters() as $i => $param) { | |
$type_obj = $param->getType(); | |
if (!$type_obj || ($type_obj instanceof \ReflectionNamedType && $type_obj->isBuiltin())) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# This runs a new Docker container, mounts the current directory (Drupal root), | |
# and runs an arbitrary drush command, in case you don't want to run it in dsession. | |
sudo docker run --rm -it --init -v "$(pwd)":/var/www/tome mortenson/tome drush "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This script takes a sub-directory of your repository, renames relative links | |
in HTML files to point to a Github Pages subdirectory, and publishes to your | |
gh-pages branch. | |
Use: | |
1. Download this script into the root of your project. | |
2. Run npm install --save-dev fs-extra rebase gh-pages | |
3. Rename "your-project" to the name of your Github project | |
4. If you have more than one HTML file, add it to the "files" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
function processSprite { | |
file=$1 | |
echo "Creating sprite sheet for $file..." | |
filename=$(basename $file .aseprite) | |
aseprite -b "$file" --sheet "assets/$filename-Sheet.png" > /dev/null | |
} | |
function processTilemap { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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! | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save this to a file named "drush" (not "drush.sh") and put it in the same | |
# directory as your docker-compose file. Replace "SERVICE" with your docker | |
# container's name. | |
# Now every time you run "drush" from this directory, it runs drush inside | |
# your container instead. Cool! | |
docker-compose exec SERVICE drush $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This directory should persist between builds. | |
CACHE_DIR=/tmp/tome_static | |
set -e | |
composer install | |
mkdir -p "$CACHE_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\sfc_example\Plugin\SingleFileComponent; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\sfc\ComponentBase; | |
/** | |
* Contains an example component that provides a block. | |
* |