Skip to content

Instantly share code, notes, and snippets.

View webmozart's full-sized avatar

Bernhard Schussek webmozart

View GitHub Profile
@webmozart
webmozart / array-validation-error-mapping.php
Last active November 9, 2024 19:58
A little experiment: Validating (potentially multi-leveled) arrays with the Symfony2 Validator component and returning the errors in the same data structure as the validated array by using the Symfony2 PropertyAccess component.
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Constraints\Required;
{% extends '::base.html.twig' %}
{% set active_section = 'goods' %}
{% use 'bootstrap_3_layout.html.twig' %}
{% block body -%}
<div class="page-header">
<h1>Edit Good</h1>
</div>
@webmozart
webmozart / Xerox-WorkCentre-6605DN.ppd
Created May 1, 2021 16:56
A Linux driver (PPD) for Xerox WorkCentre 6605DN that actually works
*PPD-Adobe: "4.3"
*% Adobe Systems PostScript(R) Printer Description File
*% Copyright 2009-2010 Xerox Corporation.
*FileVersion: "1.0"
*FormatVersion: "4.3"
*LanguageEncoding: ISOLatin1
*LanguageVersion: English
@webmozart
webmozart / .gitattributes
Last active July 22, 2018 13:39
Automatically replacing variables in PHP files when doing "git add"
*.php filter=subvars
@webmozart
webmozart / README.md
Last active July 22, 2018 13:38
Composer Resource Integration
// Doctrine.Tests.ORM.Mapping.User.dcm.xml
<?xml version="1.0" encoding="UTF-8"?>
<map:class-mapping xmlns="http://doctrine-project.org/schemas/orm"
xmlns:map="http://doctrine-project.org/schemas/annotations/class-mapping">
<map:class name="Doctrine\Tests\ORM\Mapping\User">
<entity table="cms_users" />
<indexes>
<index name="name_idx" columns="name"/>
@webmozart
webmozart / git-find-merge
Created November 15, 2012 14:32
Script to find the merge and PR a commit occurred in
#!/bin/bash
COMMIT=$1
BRANCH=$2
if [ -z $BRANCH ]; then
BRANCH="master"
fi
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' \
<(git rev-list --ancestry-path --oneline $COMMIT..$BRANCH) \
class MoneyType extends AbstractType implements DataMapperInterface
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('amount', 'integer')
->add('currency', 'string')
->setDataMapper($this)
;
}
<?php
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ApplicationFormType extends AbstractType
@webmozart
webmozart / algorithm.js
Last active December 18, 2015 16:10
Puli JSON parsing algorithm
function get(path)
{
if ('undefined' != typeof cache[path]) {
return cache[path]
}
cache[path] = new Resource(getTarget(path))
return cache[path]
}