Skip to content

Instantly share code, notes, and snippets.

View tombola's full-sized avatar

Tom Readings tombola

  • Freelance
  • Devon
View GitHub Profile
@tomdyson
tomdyson / wagtail-import-data.md
Last active May 7, 2024 12:35
Create 35k Wagtail pages of Wikipedia film plots

Create Wagtail pages programmatically

This short recipe demonstrates how to create Wagtail pages programmatically. It may also be useful for testing Wagtail development against a reasonable volume of page data (about 35,000 film plots, from English Wikipedia).

Instructions

In a virtualenv:

@zerolab
zerolab / example.module.php
Last active March 17, 2017 13:26
Drupal 8 pass data down ER fields
<?php
/**
* @file
* An example of how to pass your custom variable to the first item in a multi-value
* entityreference field.
*/
/**
* Implements hook_preprocess_field().
@zerolab
zerolab / example.md
Last active February 8, 2017 16:34
Drush database import progress
$ brew install pv

-OR-

$ apt-get install pv
@bmihelac
bmihelac / wagtail_struct_block_validation.py
Created January 5, 2017 15:28
Example validating wagtail StructBlock
from django.core.exceptions import ValidationError
from django.forms.utils import ErrorList
from wagtail.wagtailcore import blocks
class MyLinkBlock(blocks.StructBlock):
"""
Example validating StructBlock.
"""
@zerolab
zerolab / .gitconfig
Last active March 7, 2018 16:10
Git config
[core]
excludesfile = ~/.gitignore
autocrlf = input
editor = vim
quotepath = false
safecrlf = false
[color]
ui = auto
status = auto
branch = auto
@szeidler
szeidler / d8-responsive-image-programmatically.php
Created March 15, 2016 08:42
Load and render responsive image from field in Drupal 8
<?php
function _load_header_image($variables) {
if ($node = $variables['node']) {
// Load main_image
$file = $node->field_main_image->entity;
if ($file) {
$variables = array(
'responsive_image_style_id' => 'header_image',
'uri' => $file->getFileUri(),
@crittermike
crittermike / gist:618e57a41286e555dea8
Last active November 24, 2020 21:30
A list of Whens, Thens, and Givens for Drupal Behat testing
Given /^(?:|I )am on "(?P<page>[^"]+)"$/
Given /^(?:|I )am on (?:|the )homepage$/
Given :type content:
Given :vocabulary terms:
Given I am an anonymous user
Given I am at :path
Given I am logged in as :name
Given I am logged in as a user with the :permissions permission(s)
Given I am logged in as a user with the :role role(s)
Given I am logged in as a user with the :role role(s) and I have the following fields:
@Kartones
Kartones / postgres-cheatsheet.md
Last active May 7, 2024 17:48
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@purplexa
purplexa / gist:9128965
Created February 21, 2014 04:50
Reversing an EntityReference direction in Drupal Migrate
<?php
/**
* This is the content type which should have the EntityReference field in the new site.
*/
class MainContentTypeMigration extends DrupalNode6Migration {
public function __construct(array $arguments) {
parent::__contstruct($arguments);
$this->addFieldMapping('my_new_field', 'my_old_field');
@dustinfarris
dustinfarris / session_enabled_test_case.py
Last active April 18, 2024 22:17
Setting session variables whilst testing with Django's TestCase
"""
Attempting to set session variables directly from TestCases can
be error prone. Use this super-class to enable session modifications
from within your tests.
Usage
-----
class MyTest(SessionEnabledTestCase):