Skip to content

Instantly share code, notes, and snippets.

View sun's full-sized avatar
👌
Happy

Daniel Kudwien sun

👌
Happy
View GitHub Profile
@sun
sun / cc.php
Created March 16, 2014 22:45
D8 cc.php
<?php
/**
* @file
* Script to flush all caches in Drupal 8.
*
* Place this script into your Drupal document root; i.e., /cc.php
* and request it in your browser.
*/
@sun
sun / config-dev.patch
Last active August 29, 2015 13:59
D8 config in files for development
diff --git a/sites/default/settings.php b/sites/default/settings.php
index b2ce930..9d0514e 100644
--- a/sites/default/settings.php
+++ b/sites/default/settings.php
@@ -611,7 +611,8 @@
* The 'bootstrap_config_storage' setting needs to be a callable that returns
* core.services.yml.
*/
- # $settings['bootstrap_config_storage'] = array('Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage');
+$settings['bootstrap_config_storage'] = 'Drupal\Core\Config\BootstrapConfigStorageFactory::getFileStorage';
@sun
sun / bench.basename.php
Created June 22, 2014 15:41
Bench basename() for namespaced class names
<?php
# Simple PHP 5.4+ bench script for CLI.
const ITERATIONS = 10000;
error_reporting(E_ALL | E_STRICT);
setlocale(LC_ALL, 'C');
register_shutdown_function(function () {
echo PHP_EOL;
$memory_peak_end = memory_get_peak_usage();
@sun
sun / rewrite-tests.php
Created July 2, 2014 12:59
Rewrite D8 tests to convert getInfo() into PHPDoc
<?php
use Drupal\Core\DrupalKernel;
use Drupal\simpletest\TestDiscovery;
use Sun\StaticReflection\ReflectionClass;
use Sun\StaticReflection\ReflectionDocComment;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require __DIR__ . '/../vendor/autoload.php';
@sun
sun / php-file.sh
Created July 21, 2014 23:02
PHP CLI vs. STDIN / STDOUT / STDERR — https://bugs.php.net/bug.php?id=43283
$ echo "<?php var_dump(STDOUT);" > y.stdout
$ php y.stdout
resource(2) of type (stream)
@sun
sun / child-result-tranfer.patch
Created July 28, 2014 20:52
PHPUnit: Use php://fd/3 (custom file descriptor) to transfer child process results — FAILS on Windows
diff --git a/src/Util/PHP.php b/src/Util/PHP.php
index d3d36a0..e173775 100644
--- a/src/Util/PHP.php
+++ b/src/Util/PHP.php
@@ -84,7 +84,7 @@ public function runTestJob($job, PHPUnit_Framework_Test $test, PHPUnit_Framework
$_result = $this->runJob($job);
$this->processChildResult(
- $test, $result, $_result['stdout'], $_result['stderr']
+ $test, $result, $_result['result'], $_result['stdout'], $_result['stderr']
@sun
sun / bench.loop.php
Last active August 29, 2015 14:04
Bench various ways of natively looping over PHP arrays
<?php
# Simple PHP 5.4+ bench script for CLI.
const ITERATIONS = 1000;
const ARRAY_SIZE = 1000;
define('CONDITION', 'item' . (ARRAY_SIZE - 1));
error_reporting(E_ALL | E_STRICT);
setlocale(LC_ALL, 'C');
register_shutdown_function(function () {
@sun
sun / bug.php
Last active August 29, 2015 14:04
SplDoublyLinkedList::IT_MODE_LIFO unsets wrong key
<?php
$list = new SplDoublyLinkedList();
// Comment this out to make it behave.
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
$list->push('one');
$list->push('two');
foreach ($list as $key => $value) {
### Keybase proof
I hereby claim:
* I am sun on github.
* I am sun (https://keybase.io/sun) on keybase.
* I have a public key whose fingerprint is 1292 4213 3E34 D0B0 68A6 DE4D 0AA6 11AF B3CA F936
To claim this, I am signing this object:
@sun
sun / vim-cheatsheet.py
Last active January 30, 2020 13:53
vim
# Replace `define('...', '...');` with `const ... = ...;`
:%s/define( *'\(\w*\)',\( *\)'\([^']*\)' *);/const \1 =\2'\3';/
# Replace `isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] :` with `$_SERVER['SERVER_NAME'] ??`
# Using different delimiters to match an underscore literally.
:%s!isset.*SERVER_NAME.*:!$_SERVER['SERVER_NAME'] ??!
# Convert line endings to Linux/Unix
:set ff=unix