Skip to content

Instantly share code, notes, and snippets.

View arpitr's full-sized avatar

Arpit arpitr

  • Srijan Aravali Technologies
  • Goa
View GitHub Profile
@arpitr
arpitr / gist:ac637bf2d530fbb77b9b72772f05d03c
Created December 31, 2020 05:19
Delete merged branches from remote
// will skip deleting branches master|dev|stage
// replace origin with remote name
git branch -r --merged| egrep -v "(^\*|master|dev|stage)" | sed 's/origin\///' | xargs -n 1 git push --delete origin
@arpitr
arpitr / gist:f61623f35527d8e8f3712d9e73a358ae
Created December 31, 2020 05:16
Delete Media Entities of certain type
// Change the bundle that needs to be deleted.
drush php-eval '$ids = \Drupal::entityQuery("media")->condition("bundle", "image")->execute();$storageHandler = \Drupal::entityTypeManager()->getStorage('media');$entities = $storageHandler->loadMultiple($ids);foreach ($entities as $entity) {$entity->delete();}'
@arpitr
arpitr / media_attach.php
Created December 31, 2020 05:14
Attach media to all article nodes
// replace 119751 with media entity ID
drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type","article")->execute();$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);$media = \Drupal\media\Entity\Media::load(119751);foreach($nodes as $node) {$node->field_hero_media->entity = $media;$node->save();}'
@arpitr
arpitr / gist:30953aadfb8d7fdc2ad2feb6bc1ed55b
Created August 6, 2018 08:04
Acquia Varnish Purge Single Page
# Check Varnish Header
# Use following if no CDN(cloudflare/cloudfront) is used.
curl -sLIXGET http://<domain>/page-to-purge
# Use following to by-pass CDN
curl -sLIXGET -H "Host: <domain>" http://<acquia server ip>/path-to-purge
# Example
curl -sLIXGET -H "Host: www.test.com" http://12.602.711.xxx/test-page
public function image_upload($image_path, $filename, $is_image_name_set = FALSE) {
$output = [];
$fid = ParagraphImportProcessParagraph::getFidFromHashing($image_path, $this->configuration);
if (!$fid) {
$fid = ParagraphImportProcessParagraph::create_image($filename, $image_path, $this->configuration);
}
if ($fid) {
$output = ParagraphImportProcessParagraph::attach_image_info($fid, '', '');
<?php
/**
* Perform: Create URL Alias for articles and Delete duplicate aliases;
*
* Code with in Migrate Plugin
* Run it year wise
* Get <url> from xml
* Can we get <nid>? use #1 : #2
*/
@arpitr
arpitr / field_config_import.yml
Created January 4, 2018 08:11
Drupal 8 Firld config import via install hooks
use Drupal\Core\Serialization\Yaml;
use \Drupal\field\Entity\FieldConfig;
use \Drupal\field\Entity\FieldStorageConfig;
function moudlename_config_updates_update_8103() {
//Code for importing field storage.
$storage = 'field.storage.paragraph.field_related_media';
$config_path = file_get_contents(DRUPAL_ROOT . '/profiles/custom/profile_name/modules/custom/
@arpitr
arpitr / .gitconfig
Created August 9, 2017 03:16 — forked from rab/.gitconfig
A good starting point for ~/.gitconfig
# -*- Conf -*-
[color]
branch = auto
diff = auto
status = auto
showbranch = auto
ui = true
# color.branch
# A boolean to enable/disable color in the output of git-branch(1). May be set to always, false (or
<?php
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
header('Content-Type: text/plain');
function _get_module_count() {
$modules = system_list('module_enabled');
foreach ($modules as $module) {
if (strpos($module->filename, 'sites/all/modules/contrib') === 0) {
@arpitr
arpitr / iterm2.md
Created August 21, 2016 21:04 — forked from arpitra/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
Previous Tab + Left Arrow
Next Tab + Right Arrow
Go to Tab + Number
Go to Window + Option + Number
Go to Split Pane by Direction + Option + Arrow
Go to Split Pane by Order of Use + ] , + [