Skip to content

Instantly share code, notes, and snippets.

View dasginganinja's full-sized avatar

Tom Donahue dasginganinja

  • Lehigh University
  • Bethlehem, PA
View GitHub Profile
@dasginganinja
dasginganinja / drupal-10-generate-url-alias-enable.sql
Created September 19, 2023 19:14
Drupal 10+ - Check the Generate URL box for all nodes. This was previously stored in pathauto_state in Drupal 7.
UPDATE `key_value` SET value = 'i:1;' WHERE `collection` LIKE 'pathauto_state.node' AND value LIKE '%:0;%';
<?php
// This code checks for largest opcache consumers
$status = opcache_get_status();
// remap
foreach ($status['scripts'] as $path => $script) {
$sizes[$path] = $script['memory_consumption'];
}
@dasginganinja
dasginganinja / unison.sh
Last active November 14, 2023 15:34
Install Unison 2.51.2 on Debian / Ubuntu - Used in Vagrant Guest Machines for compatibility with OSX Unison version
#!/bin/bash
apt-get update
apt-get install libdpkg-perl -y -f --allow-downgrades
apt-get install ocaml ocaml-native-compilers camlp4-extra opam -y -f
mkdir -p /usr/src/unison/
cd /usr/src/unison/
wget https://github.com/bcpierce00/unison/archive/refs/tags/v2.51.2.tar.gz -O unison.tar.gz
@dasginganinja
dasginganinja / template.php
Created December 6, 2018 19:47
OG Drupal 7 Get First menu in current context
<?php
// Determine appropriate menu to load
$context = og_context();
$menu_name = 'main-menu';
if ($context) {
$menus = og_menu_get_group_menus([
$context['group_type'] => [$context['gid']],
]);
$menu = array_shift($menus);
@dasginganinja
dasginganinja / Hero not working...
Last active December 3, 2018 23:27
try this to see if the variable is set. This is normally set in template_preprocess_node() in template.php. Look for mentions of this variable in your code.
<?php
/*
* @file
* Default theme implementation to display text_page nodes.
*
* @see template_preprocess()
* @see template_preprocess_node()
* @see template_process()
*/
?>
@dasginganinja
dasginganinja / hours.php
Created November 8, 2018 21:46
Use google client api library to fetch events for display on website
<?php
define("HOURS_LIBRARY", "[email protected]");
$path = '/path/to/google-api-php-client';
require_once($path . "/vendor/autoload.php");
function hours_get_data_for($calendar_id, $service, $opt_params) {
$events = $service->events->listEvents($calendar_id, $opt_params);
$todays_events = array();
@dasginganinja
dasginganinja / gist:b4e049d858339098452c0d453ce0c982
Created October 31, 2018 14:21
OG role override -- rule replacement
The rule I created to make this works is configured as follows:
-- Event: After updating an existing user account
-- Conditions: User has role(s)
-- -- Parameter: User: data selector: [account], Roles: value: story author override {this is a drupal role I created for this purpose},
-- -- -- Match Roles: "if matching against all selected roles, the user must have ALL the roles selected"
-- -- -- Negate is not checked
-- Elements:
-- -- fetch entity by id:
-- -- -- Parameter: Entity type: Node, Identifier: 1
-- -- -- Provides variables: Fetched entity (entity_fetched)
@dasginganinja
dasginganinja / gist:91f7f91c1890eee1e058dc3e2e278255
Created March 19, 2018 14:09
List all file extensions in the current directory
find . -type f | sed -n 's/..*\.//p' | sort | uniq -c
@dasginganinja
dasginganinja / findMixedModeErrors.js
Created September 28, 2017 11:37
Find mixed mode issues in content. The src attribute matches scripts, images, iframes. The link href attribute is used for css.
jQuery(document).ready(function() {
var $srcitems = jQuery("[src^='http://']");
var $hrefitems = jQuery("link[href^='http://']");
var totalitems = $srcitems.length + $hrefitems.length;
if (totalitems > 0) {
alert('Found ' + totalitems + ' items that will trigger mixed mode. Check the console for these items.');
for (var i = 0, len = $srcitems.length; i < len; i++) {
console.log($srcitems[i]);
}
for (var i = 0, len = $hrefitems.length; i < len; i++) {
@dasginganinja
dasginganinja / drupal_diff_module.sh
Created June 5, 2017 15:38
Bash Script for easily seeing differences between module versions
#!/bin/bash
MODULE=$1
VERFROM=$2
VERTO=$3
shift
shift
shift
if [ "$MODULE" == "" ] || [ "$VERFROM" == "" ] || [ "$VERTO" == "" ]