Skip to content

Instantly share code, notes, and snippets.

Convert code from using array syntax to object property syntax.
Find:
\$(\w+)\['([^']+)'\]
Replace:
\$$1->$2
Modified from https://edmondscommerce.github.io/php/phpstorm-regex-convert-array-to-object-syntax.html
Patch Drupal core with https://www.drupal.org/files/issues/ignore_front_end_vendor-2329453-111.patch
drush vset features_rebuild_on_flush FALSE
drush vset entity_rebuild_on_flush FALSE
More details:
http://a-fro.com/speed-up-cache-clearing-on-drupal7
https://www.drupal.org/node/2329453
git tag -a 0.1 -m "Initial public release" master
git push --tags
@Rade333
Rade333 / Switch Vagrant machine provider from Virtualbox to VMWare Fusion
Last active April 20, 2016 12:42
Terminal commands to run in order to switch the provider of a vagrant virtual machine from Virtualbox to VMWare Fusion on Mac OS X.
# Go to the vagrant machine directory
$ cd /path/to/vagrant_machine
# Find out and make note of the IP address of the vagrant machine, you should find it in Vagrantfile
# Destroy the vagrant machine
$ vagrant destroy
# Remove the IP from ssh known hosts
$ ssh-keygen -R <IP ADDRESS>
Complete line:
cmd + shit + return
Surround with:
cmd + alt + T
Synchronize:
cmd + alt + Y
Move current line up/down:
@Rade333
Rade333 / iptc.php
Created January 25, 2016 11:27
Read IPTC data from image file.
<?php
$image_url = '/path/to/image.jpg';
getimagesize($image_url, $image_info);
if (!isset($image_info['APP13'])) {
die('No IPTC data found.');
}
<?php
function hasParent(DOMElement $element, array $parents) {
$parent = $element->parentNode;
while ($parent = $parent->parentNode) {
if (in_array($parent->tagName, $parents)) {
return TRUE;
}
}
return FALSE;
}
@Rade333
Rade333 / crawler.php
Created August 27, 2015 06:29
Reverendfun.com comic crawler
<?php
$base_url = 'http://www.reverendfun.com';
$archive = new DOMDocument();
$archive->loadHTML(file_get_contents('http://www.reverendfun.com/artchives/'));
$i = 0;
$image_urls = [];
$time = time();
foreach ($archive->getElementsByTagName('a') as $archive_a) {
@Rade333
Rade333 / Random placeholder image
Last active December 31, 2015 00:29
Generates a random placeholder images with within given size range.
<?php
$specimen = rand(1, 30);
$width = rand(640, 1600);
$height = rand(360, 1600);
$placeholders = array(
"http://place.manatee.lc/$specimen/$width/$height.jpg",
"http://placecorgi.com/$width/$height",
"http://placekitten.com/$width/$height",
);
shuffle($placeholders);