Skip to content

Instantly share code, notes, and snippets.

View magickatt's full-sized avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / gist:9078526
Created February 18, 2014 19:47
Delete only directories (not files) in a directory
#!/bin/bash
# Make a directory with some test directories and files inside
mkdir test
cd test
mkdir test1
mkdir test2
mkdir test3
touch hello.txt
touch goodbye.txt
@magickatt
magickatt / gist:e93a3c84ac5fd041b6d0
Created May 2, 2014 10:34
Unserialize PHP data
<?php
/*
* Yes this isn't sanitised, in case there are
* special characters in the serialized data
*
* ... therefore no this isn't safe to put on a
* public web server!
*/
@magickatt
magickatt / gist:bb7108d276bce430cf35
Created August 15, 2014 09:50
Example of how to use the Symfony Config component
<?php
// Load application-specific configuration
try {
$basepath = __DIR__ . '/config';
$configuration = Yaml::parse($basepath . '/config.yml');
} catch (\InvalidArgumentException $exception) {
exit("Are you sure the configuration files exist?");
}
@magickatt
magickatt / mysql_general_query_log_enable
Created April 29, 2015 15:11
Quick way to enable MySQL General Query Log
SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/var/log/mysql/all.log';
<!DOCTYPE html>
<html ng-app='something'>
<head>
<meta charset='utf-8'>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script
src="//cdn.rawgit.com/jpillora/xdomain/0.7.3/dist/xdomain.min.js"
slave="//api.yourdomain.ca/proxy.html">
<!DOCTYPE HTML>
<script
src="//cdn.rawgit.com/jpillora/xdomain/0.7.3/dist/xdomain.min.js"
master="https://www.yourdomain.ca">
</script>
@magickatt
magickatt / queryparam_replace.js
Created November 4, 2015 21:09
Replace value of URL query parameter in a string with another value
var url = 'https://www.example.com/mortgages?province_id=4';
var provinceId = 7;
var regularExpression = new RegExp("[\\?&]" + 'province_id' + "=([^&#]*)"),
delimeter = regularExpression.exec(url)[0].charAt(0),
newUrl = url.replace(regularExpression, delimeter + 'province_id' + "=" + provinceId);
alert(url);
alert(newUrl);
@magickatt
magickatt / behat.yml
Last active November 11, 2015 18:27
Fix SSL certificate problem with Behat, Guzzle and Goutte
default:
suites:
web:
paths: [ %paths.base%/features ]
contexts: [ WebContext ]
extensions:
Behat\MinkExtension:
base_url: 'https://localhost'
goutte:
@magickatt
magickatt / SomethingContext.php
Last active July 10, 2019 13:15
Upload a screenshot of a failed Behat step to Imgur
<?php
/**
* @AfterStep
*/
public function takeScreenshotAfterFailedStep($event)
{
if ($event->getTestResult()->getResultCode() === \Behat\Testwork\Tester\Result\TestResult::FAILED) {
$driver = $this->getSession()->getDriver();
if ($driver instanceof \Behat\Mink\Driver\Selenium2Driver) {
@magickatt
magickatt / SomethingContext.php
Last active October 25, 2016 15:39
Save screenshot of a failed Behat step
<?php
/**
* @AfterStep
*/
public function takeScreenshotAfterFailedStep($event)
{
if ($event->getTestResult()->getResultCode() === \Behat\Testwork\Tester\Result\TestResult::FAILED) {
$driver = $this->getSession()->getDriver();
if ($driver instanceof \Behat\Mink\Driver\Selenium2Driver) {