Skip to content

Instantly share code, notes, and snippets.

@xwero
xwero / column.js
Last active November 25, 2018 01:32
Sanity static generator POC
export default {
title: 'Column',
name: 'column',
type: 'object',
fieldsets: [
{name: 'content', title: 'Content', description: 'Only add content to one of the options'}
],
fields: [
{
title: 'Name',
function array_filter_by_excluded_keys(array $haysack, array $excluded) {
return array_filter($haysack, function($key) use ($excluded) {
return !in_array($key, $excluded);
}, ARRAY_FILTER_USE_KEY);
}
@xwero
xwero / FooController.php
Last active December 21, 2015 22:58
Load twig templates from the lib directory of your module
<?php
namespace Drupal\module_name\Controller;
use Drupal\Core\Controller\ControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Template\TwigEnvironment;
class FooController implements ControllerInterface {
@xwero
xwero / default.html
Created September 11, 2011 12:16
learn.knockoutjs.com pimped templates tutorial
<h2>Your seat reservations (<span data-bind="text: seats().length"></span>)</h2>
<table>
<thead><tr>
<th>Passenger name</th><th>Meal</th><th>Surcharge</th><th></th>
</tr></thead>
<tbody data-bind="template: {name:'reservationTemplate', foreach: seats}"></tbody>
</table>
<script type="text/x-jquery-tmpl" id="reservationTemplate">
@xwero
xwero / MarkdownTask.php
Created September 6, 2011 12:16
Ugling: static site generator with phing (start of the template engine)
<?php
require_once 'phing/Task.php';
require_once 'phing/util/FileUtils.php';
require_once 'System.php';
require_once "phing/tasks/ext/markdown/markdown.php";
class MarkdownTask extends Task {
/**
@xwero
xwero / MarkdownTask.php
Created September 3, 2011 08:05
Ugling: static site generator with phing (the basics)
<?php
require_once 'phing/Task.php';
require_once 'phing/util/FileUtils.php';
require_once 'System.php';
require_once "phing/tasks/ext/markdown/markdown.php";
class MarkdownTask extends Task {
/**
@xwero
xwero / gist:1189545
Created September 2, 2011 19:09
unique word count from text
<?php
/**
* transfrom text to array with unique words and their appearance count
*
* @param string text
* @param array excludes
* @param string sort prefix php sort function, by default alphabetic
* @return array the words as keys and the appearance count as value
*/
function word_count($text, $excludes=array(), $sort = 'k')
@xwero
xwero / gist:1151845
Created August 17, 2011 15:52
my first phing buildfile
<?xml version="1.0" encoding="UTF-8"?>
<project name="FooBar" default="dist">
<copy todir="c:\FooBarStage\vendor\swiftmailer">
<fileset dir=".\vendor\swiftmailer">
<exclude name=".git\**" /> <!-- exclude .git directory files because they can be locked -->
<exclude name=".gitignore" />
<exclude name="CHANGES" />
<exclude name="README" />
<exclude name="README.git" />
@xwero
xwero / gist:1022345
Created June 13, 2011 05:23
Throw Kohana exception if json function returns nothing
<?php
/**
* Throw Kohana exception if json function returns nothing
*
* @example
* $en = json_encode("\xB1\x31");
*
* check_json_error($en);
*
* $de = json_decode("{'Organization': 'Kohana'}");
@xwero
xwero / gist:896194
Created March 31, 2011 11:19
Check if one of the fields has data
function one_not_empty($array,$fields)
{
$fields = func_get_args();
array_shift($fields);
foreach($fields as $field)
{
if(Valid::not_empty($array[$field]))
{
return true;