Skip to content

Instantly share code, notes, and snippets.

View laradevitt's full-sized avatar

laradevitt laradevitt

  • Othermachines
  • Alberta, Canada
View GitHub Profile
@laradevitt
laradevitt / cc-extend.js
Last active July 28, 2021 23:03
Custom events to dispatch the various states of the Civic Cookie Control UI (https://www.civicuk.com/cookie-control). I use it to prevent interference with pop-up modals.
(function(CookieControl) {
/**
* Creating custom events to dispatch the various states of Cookie Control UI.
*/
CookieControl.loadedEvent = new Event('cc.loaded');
CookieControl.openedEvent = new Event('cc.open');
CookieControl.closedEvent = new Event('cc.closed');
/**
@laradevitt
laradevitt / mytheme.theme
Created May 1, 2021 01:05
(Drupal 8) Add attribute aria-describedby to responsive image in Twig template.
<?php
/**
* Implements hook_preprocess_node__HOOK().
*
* (a11y) Pass the media target_id to the template so we can use it to form
* a unique id to target from aria-describedby attribute.
*/
function MYTHEME_preprocess_node__slide(array &$variables) {
$node = $variables['node'];
@laradevitt
laradevitt / mytheme.theme
Created May 1, 2021 00:50
(Drupal 8) Resolves 'missing required attribute' validation errors when using Lazy-load (lazy) module. Versions: lazy 3.6.0, lazysizes 5.3.1
<?php
/**
* Implements hook_preprocess_image().
*
* Adding src here fixes validation error 'Element img is missing required
* attribute src' when using the lazysizes library.
* https://github.com/aFarkas/lazysizes/issues/500#issuecomment-616115829
*/
function MYTHEME_preprocess_image(array &$variables) {
@laradevitt
laradevitt / random-from-sitemap.sh
Last active January 7, 2021 18:20
Randomly selected sample - get a specified number of random entries from a website XML sitemap. Usage: ./random-from-sitemap.sh http://domain.com/sitemap.xml 10
#!/bin/sh
SITEMAP=$1
COUNT=$2
if [ "$SITEMAP" = "" ] || [ "$COUNT" = "" ]; then
echo "Usage: $0 https://example.com/sitemap.xml 1"
exit 1
fi
@laradevitt
laradevitt / convert_file_to_media.install
Created March 30, 2020 23:10
(Drupal 8) Convert file entities to media entities with batch update script
<?php
use Drupal\media\Entity\Media;
/**
* @file
*/
/**
* Convert transient file entities that weren't processed during migration.
@laradevitt
laradevitt / Code.gs
Created February 29, 2020 18:08
Managing RSVPs with Google Apps Script
var SHEET_MAIN = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1');
var SHEET_RSVP = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RSVPs');
var SHEET_EMAIL = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Invitees');
function onFormSubmit(e) {
var range = e.range;
var values = range.getValues();
var row = values[0];
var email = row[1];

Keybase proof

I hereby claim:

  • I am laradevitt on github.
  • I am laradevitt (https://keybase.io/laradevitt) on keybase.
  • I have a public key ASDKJvteLEdz_lFzXDKqrVX8-HmK4l2624uDjuYqBQnQuAo

To claim this, I am signing this object:

@laradevitt
laradevitt / react-structured-data.md
Created August 20, 2019 19:17
react-structured-data example - Google Structured Data 'Event'

Example generic type when using React Structured Data

<JSONLD dangerouslyExposeHtml={true}>
  <Generic
    type="Event"
    jsonldtype="Event"
    schema={{
      name: `Somebody at ${content.venue}`,
      startDate: content.date,
@laradevitt
laradevitt / google_sheet_permissions.md
Created June 15, 2019 14:06
(Steps) Google API Console: Access Google Sheet data from your app

Set up

To access data from a Google Sheet with your app, you will need to create a service account and download a credentials file from the Google API Console.

  1. Create a Google spreadsheet.
  2. Go to the Google APIs Console.
  3. Create a new project and navigate to it.
  4. Click Enable APIs and Services. Enable the Google Drive API.
  5. In the Create credentials options, select Help me choose. You are using "Google Drive API" from a "Web server" to access "Application data".
  6. Add credentials to your project. Name the service account and grant it a Role of "Project" > "Editor".
@laradevitt
laradevitt / template.php
Created September 19, 2018 16:16
(Drupal 7) Programmatically add <meta name="robots" content="noindex, nofollow"> to certain pages.
<?php
// I was getting a lot of "Indexed, though blocked by robots.txt" coverage
// errors on search/ pages from Google. Since robots.txt only prevents
// crawling, not indexing, I will allow crawling and prohibit indexing via
// the "robots" meta tag instead.
function MYTHEME_preprocess_html(&$variables) {
MYTHEME_add_meta_robots_noindex();
}