Skip to content

Instantly share code, notes, and snippets.

@megclaypool
megclaypool / drupal.md
Last active November 22, 2024 23:08
[Oh Fuck, I forgot my Password: Command Line Tools to the Rescue!] Note that these commands can also come in handy if your front-end is so messed up that you can't access the login screen...

Drush one-time login link for Drupal accounts

Holy crap, I never knew about this before, but this is awesome.

The command is drush uli

It's got options,

  • name for the username
  • uri to specify the url of the site (our weird setup requires us to specify the url of our site)
@socketwench
socketwench / yourtheme.theme
Created November 9, 2020 04:37
Drupal 8: Add view_mode to block templates, add view mode to template suggestions.
/**
* Implements hook_preprocess_HOOK().
*/
function yourtheme_preprocess_block(&$variables) {
$content = $variables['elements']['content'];
if (isset($content['#block_content']) && $content['#block_content'] instanceof BlockContentInterface) {
$variables['view_mode'] = $content['#view_mode'];
}
}
@scottjehl
scottjehl / whichones.js
Created August 21, 2020 15:40
which elements are wider than the viewport?
var list = [];
document.querySelectorAll("body *")
.forEach(function(elem){
if(elem.getBoundingClientRect().width > document.body.getBoundingClientRect().width){
list.push(elem.outerHTML.split('>')[0] + '>');
}
});
confirm( "these elements are wider than the viewport:\n\n " + list.join("\n") )
@thetwopct
thetwopct / bash.sh
Last active July 20, 2021 19:06
Fix Safari "Can't establish a secure connection to the server" with self-signed certificates (Lando, Vagrant, Docker etc)
# Stop the HTTP storage manager (since it has an in-memory cache of the HSTS hosts).
killall nsurlstoraged
# Delete the HSTS cache file.
rm -f ~/Library/Cookies/HSTS.plist
# This may not work if Terminal is not configured for "Full Disk Access", so instead:
# Open Finder, Shift+Apple+G, paste in ~/Library/Cookies/ and manually delete HSTS.plist
# Start up nsurlstoraged again
launchctl start /System/Library/LaunchAgents/com.apple.nsurlstoraged.plist
@dsantuc
dsantuc / behat-cookies.php
Last active March 31, 2020 02:37
Getting all cookies from various BeHat/Mink browser drivers
public function getAllCookies ($driver) {
$cookies = array();
if ($driver instanceof Behat\Mink\Driver\BrowserKitDriver) {
$cookies = $this->getBrowserKitCookies($driver);
}
else if ($driver instanceof Behat\Mink\Driver\Selenium2Driver) {
$cookies = $this->getSeleniumCookies($driver);
}
else if ($driver instanceof Behat\Mink\Driver\ZombieDriver) {
@grasmash
grasmash / mymodule.module.php
Created February 3, 2017 19:26
Dynamically swaps Drupal 8 menu item with a user's profile image.
<?php
// If you create a menu link titled "User Profile Image" with URL "/user",
// it will be dynamically swapped with the user's profile image.
/**
* Implements hook_link_alter().
*/
function mymodule_user_link_alter(&$variables) {
/**
* @var \Drupal\Core\Url
// Download the twitter4j jar:
// wget http://twitter4j.org/maven2/org/twitter4j/twitter4j-core/4.0.4/twitter4j-core-4.0.4.jar
// Fill out the key/token/secrets
// Run the script
// kotlinc -script -classpath ./twitter4j-core-4.0.4.jar who_posts_the_most.kts|sort -n
import twitter4j.Status
import twitter4j.Twitter
import twitter4j.TwitterException
import twitter4j.TwitterFactory
[
{
"name": "JD40"
},
[
{
"c": "#dd1126"
},
"Esc",
{
(function ($, Drupal, window, document) {
'use strict';
// Example of Drupal behavior loaded.
Drupal.behaviors.exampleJS = {
attach: function (context, settings) {
if (typeof context['location'] !== 'undefined') { // Only fire on document load.
console.log('This is loaded');
@davebarnwell
davebarnwell / PHP composer tools.md
Last active March 9, 2026 14:18
Global installation of PHP tools with Composer

Global installation of PHP tools with Composer

To install a composer package globally, you run the usual require command, but with the addition of the global modifier. So to install PHPUnit, you would run:

$ composer global require phpunit/phpunit
$ composer global require phpunit/dbunit
$ composer global require phing/phing
$ composer global require phpdocumentor/phpdocumentor
$ composer global require sebastian/phpcpd