Skip to content

Instantly share code, notes, and snippets.

View dborsatto's full-sized avatar

Davide Borsatto dborsatto

View GitHub Profile
@dborsatto
dborsatto / gulpfile.babel.js
Last active August 1, 2016 15:25
Gulp configuration with Symfony (with Sass, Babel and Webpack)
import gulp from 'gulp';
import webpack from 'webpack';
import loader from 'gulp-load-plugins';
const plugins = loader();
// Basic path and environment configuration
const config = {
dirs: {
assets: './app/Resources/assets',
build: './web/build',
@dborsatto
dborsatto / index.html
Created August 10, 2016 09:23
Center position an image without altering its form factor
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.image-container {
/**
* For this trick to work, you need to have some sort
* of size set to the container element.
*/
var http = require('http');
var app = function (req, res) {
res.writeHead(200, {
'Content-Type': 'application/text'
});
res.end('Hello World');
};
var server = http.createServer(app);
@dborsatto
dborsatto / php-cs-fixer-pre-commit-hook.sh
Last active March 8, 2019 13:56
Execute php-cs-fixer as a Git pre-commit hook
git diff --name-only --cached --diff-filter=ACMRTUXB | while read filename; do
php-cs-fixer fix $filename
git add $filename
done
export MYSQL_ROOT_PASSWORD="root-password"
export MYSQL_DATABASE="database-name"
export MYSQL_USER="username"
export MYSQL_PASSWORD="user-password"
docker run --name mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
-e MYSQL_DATABASE=$MYSQL_DATABASE \
-e MYSQL_USER=$MYSQL_USERNAME \
<?php
try {
$result = $service->getVerificationResult($value);
} catch (VerificationException $exception) {
// ...
return;
}
if (!$result->isVerified()) {
foreach ($result->getErrors() as $error) {
<?php
/**
* @throws VerificationException
*/
function getVerificationResult($value): VerificationResult
{
// ...
}
<?php
/**
* @throws UserNotFoundException
* @throws InsufficientPermissionsException
* @throws ConnectionFailedException
*/
function publish(Post $post): void
{
// This may throw a UserNotFoundException
<?php
interface UserExceptionInterface extends Throwable
{
}
class UserCannotPublishPostException extends Exception implements UserExceptionInterface
{
}
<?php
class VerificationService
{
/**
* @throw VerificationException
*/
public function getVerificationResult($value): VerificationResult
{
try {