Skip to content

Instantly share code, notes, and snippets.

View wowo's full-sized avatar

Wojciech Sznapka wowo

View GitHub Profile
@wowo
wowo / api.php
Created August 28, 2015 12:52
Simple api to capture and test API callbacks
<?php
$log = __DIR__ . '/api.log';
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$payload = json_decode(file_get_contents('php://input'), true) ?: $_POST;
file_put_contents(
$log,
sprintf(
"[%s] (%s - %s) %s\n",
(new \DateTime())->format('Y-m-d H:i:s'),
@wowo
wowo / pre-commit
Last active August 29, 2015 14:24
Basic pre-commit git hook
#!/bin/bash
exec < /dev/tty
phpunit
rc=$?
if [[ $rc != 0 ]] ; then
echo -n "It looks like some of your tests failed. "
exit $rc;
fi
<?php
final class EmailValueObject
{
private $mailbox;
private $host;
public function __construct($email)
{
if (false === strpos($email, '@')) {
<?php
/* $Id$ */
set_include_path(get_include_path() . ':' . __DIR__ . '/../lib');
include 'SabreAMF/Client.php'; //Include the client scripts
spl_autoload_register(function($classname) {
$filename = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $classname) . '.php';
include $filename;
});
@wowo
wowo / IsolatedTestsTrait.php
Last active September 11, 2020 08:05
IsolatedTestsTrait helps with running functional/integration tests in isolation, with same start state for each test. It's also optimized, keeping in mind performance concerns.
<?php
namespace Acme\Example\Tests;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver;
require_once(__DIR__ . IsolatedTestsTrait::$kernelRootDir . '/AppKernel.php');
@wowo
wowo / api.php
Created September 6, 2013 12:41
That's why I like FOS REST in #Symfony
/**
* @View()
* @Get("/leads/{id}")
* @ParamConverter("offer", class="SomeBundle:Offer\OfferLead")
*/
public function getLeadAction(OfferLead $lead)
{
return array('lead' => $lead);
}
@wowo
wowo / gender-module-installation.sh
Last active May 5, 2021 23:01
Guesing gender based on name in PHP
# install gender http://www.php.net/manual/en/book.gender.php
sudo apt-get install libpcre3-dev
sudo pecl install gender
# generate data
mkdir ~/gender
sudo pear run-scripts pecl/gender
# eneble module
echo 'extension=gender.so' >> /etc/php5/cli/php.ini
@wowo
wowo / post-update.sh
Created October 23, 2012 07:45
Post-update script to update other repo
#!/bin/sh
GIT_DIR=/home/wojciech.sznapka/htdocs/real.arch.sznapka.xsdev.pl/
echo "*** Running $0"
echo "*** Resetting working copy of real.arch.sznapka.xsdev.pl"
(cd $GIT_DIR
git --git-dir=.git/ reset --hard HEAD > /dev/null)
echo "*** Updating real.arch.sznapka.xsdev.pl"
(cd $GIT_DIR
<?php
use Symfony\Component\Validator\Constraints as Assert
class ObjectRecievingMultiplieFilesFromForm
{
/**
* @Assert\All({
* @Assert\File(mimeTypes={"application/vnd.ms-excel", "application/vnd.ms-office"})
* })
@wowo
wowo / build.xml
Last active October 3, 2015 08:58
<?xml version="1.0" encoding="UTF-8"?>
<project name="Symfony2 project" default="build">
<target name="build" depends="pull, vendors, cache, assetic, assets">
<echo message="Symfony2 project"/>
</target>
<macrodef name="git">
<attribute name="command" />
<attribute name="dir" default="" />
<element name="args" optional="true" />