Skip to content

Instantly share code, notes, and snippets.

@chx
chx / test.php
Created March 26, 2012 22:56
drupal_render - twig integration
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/Twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
// Almost empty class, just swaps Twig_Node_Print objects to Drupal_Twig_Node_Print objects.
class Drupal_Twig_NodeVisitor implements Twig_NodeVisitorInterface {
function enterNode(Twig_NodeInterface $node, Twig_Environment $env) {
@chx
chx / gist:2861969
Created June 3, 2012 04:55
config presave
function presave() {
module_invoke_all('config_presave', $this);
$hook = 'config_presave';
$part = strtok($this->name, '.');
do {
$hook .= '_' . $part;
module_invoke_all($hook, $this);
} while ($part = strtok('.'));
}
@chx
chx / x.php
Created July 7, 2012 09:05
Dummy filter
<?php
class DummyFilter extends PHP_User_Filter
{
private $_data;
/* Called when the filter is initialized */
function onCreate( )
{
@chx
chx / gist:3067643
Created July 7, 2012 18:50
APC stat=0 and I mean it.
Index: apc.c
===================================================================
--- apc.c (revision 326528)
+++ apc.c (working copy)
@@ -34,6 +34,7 @@
#include "apc.h"
#include "apc_zend.h"
#include "apc_cache.h"
+#include "apc_globals.h"
#include "php.h"
@chx
chx / gist:3172060
Created July 24, 2012 19:23
nput FALSE, NULL
if (!isset($input)) {
if (!empty($element['#default_value'])) {
$element['#needs_validation'] = TRUE;
}
$element['#has_garbage_value'] = TRUE;
}
if ($input === FALSE && !isset($element['#default_value']))) {
$element['#has_garbage_value'] = TRUE;
}
@chx
chx / gist:3930812
Created October 22, 2012 10:27
Batch proof of concept
<?php
use Symfony\Component\HttpFoundation\JsonResponse;
function btest_menu() {
$items['btest'] = array(
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'btest_page',
);
@chx
chx / gist:3958575
Created October 26, 2012 12:46
Making a Debian squeeze server into running Drupal 8 tests
apt-get update
aptitude install -y apache2 libonig2 libqdbm14 libxml2 apache2-mpm-prefork ucf libicu44 mysql-server libjpeg62 libpng12-0 libt1-5 libxpm4 git-core autoconf automake libssl-dev libtool shtool make
service mysql stop
sed -i 's/\/var\/lib\/mysql/\/dev\/shm\/mysql/g' /etc/mysql/my.cnf
sed -i '/en_US/a skip_innodb' /etc/mysql/my.cnf
mysql_install_db
service mysql start
echo ServerName localhost > /etc/apache2/httpd.conf
cd /etc/apache2/mods-enabled
ln -s ../mods-available/rewrite.load
@chx
chx / gist:3959704
Created October 26, 2012 16:17
Apache configuration (slave and preferably master too)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
@chx
chx / packer.php
Created October 26, 2012 21:53
Bin packing on the master
<?php
$dir = getcwd();
foreach (file('/usr/local/etc/baseline.csv') as $row) {
list($k, $v) = explode(',', trim($row));
$a[$k] = (int)$v;
}
$a = array_reverse($a);
$bins[] = array('sum' => 0, 'data' => array());
foreach ($a as $name => $time) {
@chx
chx / .rtorrent.rc
Created October 29, 2012 23:35
rtorrent setup on slave
system.method.set_key = event.download.finished,done,"execute=/usr/local/bin/run.sh,$d.get_name=;d.set_directory=/var/www"
schedule = watch_directory,1,1,load_start=/root/torrent/watch/*.torrent