Skip to content

Instantly share code, notes, and snippets.

Avatar

Yusuf Hasan Miyan yusufhm

View GitHub Profile
@yusufhm
yusufhm / drupal-entity-updates.php
Last active Oct 2, 2020
Drupal entity updates
View drupal-entity-updates.php
<?php
/**
* Update an entity type's storage definition.
*
* An example is when the cardinality of a field is updated in config; since
* `drush updatedb` no longer performs entity updates, this has to be done
* manually now.
*/
function _MODULE_NAME_update_field_definition($entity_type_id, $field_name) {
@yusufhm
yusufhm / backup-bucket.json
Created May 20, 2020
s3 bucket policy for uploads
View backup-bucket.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListMultipartUploadParts"
],
"Resource": "arn:aws:s3:::*"
},
View keybase.md

Keybase proof

I hereby claim:

  • I am yusufhm on github.
  • I am yusufhm (https://keybase.io/yusufhm) on keybase.
  • I have a public key ASApjd3pUzWFOGkOKWHV1Q34v6hxiWFba7sCKt1lBegO0wo

To claim this, I am signing this object:

@yusufhm
yusufhm / drupal-di-setter-pattern.php
Last active Apr 9, 2020
drupal dependency inject setter pattern
View drupal-di-setter-pattern.php
<?php
public static function create(...) {
/* @see https://www.drupal.org/project/drupal/issues/2947796#comment-13389874 */
/* @see https://www.previousnext.com.au/blog/safely-extending-drupal-8-plugin-classes-without-fear-of-constructor-changes */
$instance = parent::create(...);
$instance->setRenderer(...);
$instance->setResponsiveImageStorage(...);
$instance->setLinkGenerator(...);
}
@yusufhm
yusufhm / test-output.php
Created Jan 28, 2020
phpunit screenshot & html output
View test-output.php
<?php
file_put_contents('public://screenshot.jpg', $this->getSession()->getScreenshot());
file_put_contents('public://' . drupal_basename($this->getSession()->getCurrentUrl()) . '.html', $this->getCurrentPageContent());
@yusufhm
yusufhm / homebrew-passwordless-services.md
Last active Sep 23, 2019
Homebrew passwordless services start stop
View homebrew-passwordless-services.md

Type sudo visudo -f /etc/sudoers.d/30-brew and enter the following content:

%admin ALL = (ALL) NOPASSWD: /usr/local/bin/brew
@yusufhm
yusufhm / get-list-of-file-dir-sizes.sh
Created Aug 28, 2019
List biggest files & directories
View get-list-of-file-dir-sizes.sh
#/bin/bash
du -cks * | sort -rn | head
@yusufhm
yusufhm / set-config.sh
Last active Aug 2, 2019
Set config via drush
View set-config.sh
# Get the config as yaml first.
drush config:get search_api.index.acquia_search_index datasource_settings.entity:node.bundles.selected > config-overrides.yml
# Make modifications to config-overrides.yml.
cat config-overrides.yml | drush config:set search_api.index.acquia_search_index datasource_settings.entity:node.bundles.selected - --input-format=yaml
@yusufhm
yusufhm / wp-commands.sh
Last active Sep 10, 2020
wp-cli commands
View wp-commands.sh
#!/usr/bin/env bash
# Create an admin user.
wp user create username user@example.com --role=administrator
# Reset user password.
wp user update user --user_pass=password --skip-email
# Create a database backup.
wp db export - | gzip -9 > db.sql.gz
View drupal-testing.sh
# PHPUnit testing.
# Set `BROWSERTEST_OUTPUT_DIRECTORY` so we get the browser output.
(export BROWSERTEST_OUTPUT_DIRECTORY=$(pwd)/docroot/sites/simpletest/browser_output; blt tests:phpunit:run -vvv)
# Behat testing.
(export BUILDKITE_BUILD_CHECKOUT_PATH=$(pwd); blt tests:behat:run --environment=ci --no-interaction --yes --ansi --define drush.alias='${drush.aliases.ci}')
You can’t perform that action at this time.