Skip to content

Instantly share code, notes, and snippets.

View tombola's full-sized avatar

Tom Readings tombola

  • Freelance
  • Devon
View GitHub Profile
@jrivero
jrivero / csv_splitter.py
Created July 15, 2011 20:33 — forked from palewire/csv_splitter.py
A Python CSV splitter
import os
def split(filehandler, delimiter=',', row_limit=10000,
output_name_template='output_%s.csv', output_path='.', keep_headers=True):
"""
Splits a CSV file into multiple pieces.
A quick bastardization of the Python CSV library.
Arguments:
@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):
@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');
@Kartones
Kartones / postgres-cheatsheet.md
Last active August 17, 2025 10:54
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)
@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:
@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(),
@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
@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 / example.md
Last active February 8, 2017 16:34
Drush database import progress
$ brew install pv

-OR-

$ apt-get install pv
@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().