Skip to content

Instantly share code, notes, and snippets.

Avatar
💧
Did you try to clear cache?

Samuel Mortenson mortenson

💧
Did you try to clear cache?
View GitHub Profile
@mortenson
mortenson / secure_vendor_unserialize.php
Last active Jun 29, 2022
An idea about how to secure unserialize() calls in PHP dependencies that aren't using allowed_classes.
View secure_vendor_unserialize.php
<?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.
],
@mortenson
mortenson / drupal_autowire.php
Last active May 7, 2022
Stupid auto wiring for any function/method in Drupal
View drupal_autowire.php
<?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())) {
@mortenson
mortenson / sams_portland_stuff.md
Last active Oct 26, 2022
Sam's fun things to do in Portland
View sams_portland_stuff.md

Portland recommendations by Sam

Sorted by location-ish. I tried to reduce the list to places I think are good for visitors vs. my absolute favorites, but I put a section at the bottom for places that may not be for everyone.

Breakfast / Brunch

Toki Restaurant (Downtown)

580 SW 12th Ave

Friday -> Sunday only! Fantastic Korean restaurant run by the folks at Han Oak.

@mortenson
mortenson / assets.sh
Last active Sep 28, 2020
Watch mode for a game I'm working on
View assets.sh
#! /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 {
@mortenson
mortenson / ddrush.sh
Last active Mar 20, 2022
What I currently use for local Drupal/Tome dev
View ddrush.sh
#! /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 "$@"
@mortenson
mortenson / example_alpine_autocomplete.sfc
Created Jul 8, 2020
Drupal single file components livewire demo
View example_alpine_autocomplete.sfc
<!--
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 Oct 1, 2020
Dell XPS 13 9300 Ubuntu setup notes
View notes.md

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 Oct 31, 2019
An example script that caches Tome Static builds by copying the static directory and database to /tmp between builds. Useful on CI.
View static.sh
#!/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 Sep 11, 2020
A quick CSS audit script for finding overly long/specific selectors in CSS files
View index.js
#!/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 Aug 29, 2019
Thinking about how Drupal 8 single file components could abstractly provide forms and derive other plugins like blocks
View DiceRoll.php
<?php
namespace Drupal\sfc_example\Plugin\SingleFileComponent;
use Drupal\Core\Form\FormStateInterface;
use Drupal\sfc\ComponentBase;
/**
* Contains an example component that provides a block.
*