Skip to content

Instantly share code, notes, and snippets.

@lpeabody
lpeabody / migrate-paragraphs.php
Created June 9, 2020 15:12
Move paragraphs from multiple limited-1 fields to a single components field with unlimited cardinality.
<?php
/** @var \Drupal\node\Entity\Node[] $landing_pages */
$landing_pages = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'type' => 'landing_page'
]);
$old_paragraph_fields = [
'field_tile_section',
@lpeabody
lpeabody / httpd_vhosts.conf
Created October 2, 2015 02:56
virtual host settings for revealjs autodeployment strategy
<VirtualHost *:80>
ServerName reveal.dev
ServerAlias *.reveal.dev
VirtualDocumentRoot /Users/les.peabody/presentations/%1
<Directory /Users/les.peabody/presentations/*>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
@lpeabody
lpeabody / php-switch.sh
Created June 24, 2015 13:46
PHP Switch
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: sphp [phpversion]"
exit 1
fi
currentversion=`php -r "echo str_replace('.', '', substr(phpversion(), 0, 3));"`
newversion="$1"
@lpeabody
lpeabody / drupal_perms.sh
Created June 8, 2015 17:14
Secure drupal file permissions
#!/bin/bash
# Help menu
print_help() {
cat <<-HELP
This script is used to fix permissions of a Drupal installation
you need to provide the following arguments:
1) Path to your Drupal installation.
2) Username of the user that you want to give files/directories ownership.
3) HTTPD group name (defaults to www-data for Apache).
Usage: (sudo) bash ${0##*/} --drupal_path=PATH --drupal_user=USER --httpd_group=GROUP
@lpeabody
lpeabody / problem5.rb
Last active August 29, 2015 14:21
Problem 5 recursive solution
# Write a program that outputs all possibilities to put + or - or nothing
# between the numbers 1, 2, ..., 9 (in this order) such that the result is
# always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
# 1 + [2..9]
# 1 - [2..9]
# 12 + [3..9]
# 12 - [3..9]
# 123 + [4..9]
# 123 - [4..9]
@lpeabody
lpeabody / problem5.rb
Last active August 29, 2015 14:20
Iterative Ruby solution to "Problem 5"
def get_operands(comma_indexes)
base = (1..9).to_a
last_index = 0
operands = []
comma_indexes.each do |comma_index|
operands.push(base[last_index..(comma_index-1)].join)
last_index = comma_index
end
operands.push(base[last_index..8].join)
get_plus_minus_combinations_100(operands)
@lpeabody
lpeabody / get_revision_list.php
Last active August 29, 2015 14:05
Sweet function for getting the revision list of an entity of a given type.
<?php
/**
* Get a revision id list for a particular entity.
*/
function _get_entity_revision_list($type, $entity) {
$info = entity_get_info($type);
if (!isset($info['revision table'])) {
// If this entity does not track revisions then return FALSE.
return FALSE;
}