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
html,
body {
height: 100%; }
@mortenson
mortenson / fixregion.php
Created May 12, 2017 21:40
Have some 8.2 module/distro config for form or view displays? Use this to add a region to all your fields. Buyer beware!
<?php
# Run this with drush scr, silly!
use Drupal\Core\Serialization\Yaml;
foreach (file_scan_directory('.', '/core\.entity_.*display.*\.yml/') as $file) {
$filepath = realpath($file->uri);
$yml = Yaml::decode(file_get_contents($filepath));
if (isset($yml['content'])) {
@mortenson
mortenson / docker-drush
Last active January 7, 2020 11:53
Quick way to proxy Drush commands to your Docker container
#!/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 $@
@mortenson
mortenson / ssr.js
Last active October 8, 2017 15:17
Flexible server side rendering script for Stencil when used in other platforms
// Put this file in a directory where @stencil/core exists in node_modules, then run: +var stencil = require('@stencil/core/server');
// $ echo $HTML | node ssr.js [root] [build-dir] [namespace]
// Full example from my use case:
// $ echo '<sam-text text="Hello, world"></sam-text>' | node ssr.js /var/www/stencil/sams-components/ ../dist sam
// Pipes are used because HTML strings can be really long, and bash has limits on how large argument lists can get (~256k usually).
var stencil = require('@stencil/core/server');
var args = process.argv.slice(2);
if (args.length < 3) {
console.error('Not enough args');
}
@mortenson
mortenson / access.php
Created October 11, 2017 17:06
See what operations are available for all entities on a Drupal site for common Users
<?php
// Run this with drush, like "drush scr access.php"
use Drupal\user\Entity\User;
// You should delete this user after you're done testing.
if (!($auth = user_load_by_name('tmp_access_script'))) {
$auth = User::create(['name' => 'tmp_access_script']);
$auth->save();
@mortenson
mortenson / ghpages.js
Last active January 22, 2021 19:56
Publish a sub-directory in your repository as the contents of your gh-pages branch
/**
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"
@mortenson
mortenson / composelist.sh
Last active March 21, 2025 05:46
List all Docker Compose projects currently running
#!/bin/bash
docker ps --filter "label=com.docker.compose.project" -q | xargs docker inspect --format='{{index .Config.Labels "com.docker.compose.project"}}'| sort | uniq
@mortenson
mortenson / Gruntfile.js
Created March 19, 2018 15:27
#2952390 off-canvas css renamer - download to docroot/renamer, run npm install, then "grunt"
const glob = require('glob');
let files = {};
glob.sync('../core/**/off-canvas*.css').forEach((file) => {
files[file] = file;
});
module.exports = (grunt) => {
grunt.loadNpmTasks('grunt-css-selectors');
@mortenson
mortenson / library_renderer.php
Last active March 27, 2018 06:31
Get the HTML of arbitrary Drupal libraries
<?php
$libraries = ['core/jquery'];
// In this example I'm just concerned about JS assets, but you can use other
// services to render other assets.
/** @var \Drupal\Core\Asset\AssetResolver $asset_resolver */
$asset_resolver = \Drupal::service('asset.resolver');
/** @var \Drupal\Core\Asset\JsCollectionRenderer $js_renderer */