Skip to content

Instantly share code, notes, and snippets.

@joachim-n
joachim-n / new.sh
Created October 19, 2011 21:58
Shell script to open new terminal windows in OS X
# Don't remember where I originally got this.
# I've expanded the original one liner script to allow a parameter which opens the new window in a specified subfolder (or any folder, just type a relative path if you can be bothered with the fiddly bits).
# open a new Terminal window in either the current folder, or a subfolder
# if given.
if [ -z "$1" ] # No argument passed?
then
osascript -e "tell application \"Terminal\" to do script \"cd `pwd`\""
else
echo $1
@joachim-n
joachim-n / gist:6570433
Created September 15, 2013 12:35
For places where you can't output to browser, and debug() will choke on a full backtrace.
$trace = debug_backtrace();
foreach ($trace as $trace_item) {
$debug[] = $trace_item['function'];
}
debug($debug);
@joachim-n
joachim-n / d8_reset.sh
Last active August 29, 2015 13:57 — forked from cam8001/d8_reset.sh
#!/bin/sh
# Removes an existing Drupal 8 install, then install again.
# Requires Drush 7 - https://github.com/drush-ops/drush
#
# Run this script from the docroot of a Drupal 8 checkout.
# Installs to mysql://localhost/drupal, user 1 user/pass is admin/admin.
# Variables.
# These should be customized to your setup.
@joachim-n
joachim-n / gist:9562940
Created March 15, 2014 07:15
Drupal cd
# go to a drupal module folder, from anywhere in the site hierarchy,
# with autocompletion
function dm {
drroot;
cd sites/all/modules;
#echo contrib/$1;
if [ -d "contrib/$1" ]
then
cd "contrib/$1";
elif [ -d "custom/$1" ]
@joachim-n
joachim-n / gist:9626938
Created March 18, 2014 18:56
validation handler
$selected_sessions = array();
foreach (array_keys($form_state['values']['timeslots']) as $timeslot_id) {
foreach (array_keys($form_state['values']['timeslots'][$timeslot_id]['rooms']) as $room_id) {
$cell_form_state_value = $form_state['values']['timeslots'][$timeslot_id]['rooms'][$room_id]['session'];
if (!empty($cell_form_state_value)) {
$selected_sessions[$cell_form_state_value][] = array($timeslot_id, $room_id);
}
}
}
@joachim-n
joachim-n / gist:989eb0d1ca54ce756350
Created February 3, 2015 13:08
Drush shell script to diff and write a patch file.
#!/usr/bin/env drush
<?php
/**
* @file
* Drush shell script for creating a patch.
* Requires the following setup:
* - You are on a git feature branch for your issue.
* - The branch name is of the format '1234-description-of-feature' where 1234
* is the drupal.org issue number.
* - The feature branch is rebased to the major development branch you want to
#!/usr/bin/perl -p
# show what the hell is happening with line endings
s[ (?<! \r ) \n ]
[UNIX\n]x;
s[ \r\n]
[WIN\n]x;
@joachim-n
joachim-n / dashcam-blank.js
Created July 10, 2022 20:51
Bookmarklet for filling in Dashcam submission form
// Fill in the details with your own.
// Paste this as the URL of a new Firefox bookmark.
// Use the bookmark when on https://secureform.nextbase.co.uk/
javascript: {
document.getElementById('signature').value = '';
document.getElementById('name').value = '';
// Doesn't work yet.
// document.getElementById('preferredContact').value = '0';
document.getElementById('email').value = '';
document.getElementById('phone').value = '';
public static function check($checking_key, $data) {
try {
serialize($data);
}
catch (\Throwable $e) {
// The data fucked up. Go into it to see where.
ddm("CATCH $checking_key");
if (is_array($data)) {
foreach ($data as $key => $val) {
static::check($key, $val);
@joachim-n
joachim-n / kernel test form submission
Created April 7, 2023 12:33
Make a POST request to a form
/**
* Make a POST request to a form.
*
* @param string $url
* @param array $data
*/
protected function doPostForm(string $url, array $data = []) {
$request = Request::create($url);
$response = $this->doRequest($request);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());