Skip to content

Instantly share code, notes, and snippets.

View tonydub's full-sized avatar
💭
Day-job is very demanding at present. I have limited time for my repositories.

Tony Dubreil tonydub

💭
Day-job is very demanding at present. I have limited time for my repositories.
  • Klaxoon
  • France
View GitHub Profile
#!/usr/bin/env bash
swapsize=2048
grep -q "swapfile" /etc/fstab
if [ $? -ne 0 ]; then
echo 'swapfile not found. Adding swapfile.'
fallocate -l ${swapsize}M /swapfile
chmod 600 /swapfile
<?php
interface ClockInterface
{
public function currentTime(): DateTimeImmutable;
}
<?php
class Repository
{
public function findAll(): array
{
return $this->connection->project(
sprintf('SELECT * FROM %s', self::TABLE_NAME),
[],
function(array $row): Domain\MyObject {
return Domain\MyObject::fromState($row);
@tonydub
tonydub / compress-pdf-with-gs.md
Created October 17, 2017 21:47 — forked from drawveloper/compress-pdf-with-gs.md
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
@tonydub
tonydub / Greatest.php
Created January 12, 2017 15:49 — forked from instabledesign/Greatest.php
Doctrine ORM Function GREATEST
#src/AppBundle/Doctrine/ORM/Functions/Greatest.php
<?php
namespace AppBundle\Doctrine\ORM\Functions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
@tonydub
tonydub / DeletedFilter.php
Created May 30, 2016 07:26 — forked from baptistedonaux/DeletedFilter.php
Soft Delete Symfony/Doctrine
<?php
namespace Namespace\MyBundle\Repository\Filters;
use Doctrine\ORM\Mapping\ClassMetaData;
use Doctrine\ORM\Query\Filter\SQLFilter;
class DeletedFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
@tonydub
tonydub / 0_reuse_code.js
Last active August 29, 2015 14:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tonydub
tonydub / display_sql_with_monolog_and_channel_doctrine.php
Created January 24, 2014 09:28
How to display sql queries with monolog and doctrine channel
<?php
$logger = $this->getContainer()->get('monolog.logger.doctrine');
foreach ($logger->getLogs() as $log) {
$output->writeln(sprintf('<info>Query:</info> %s (%s)', $log['message'], json_encode($log['context'])));
$output->writeln('');
}
var mediator = (function(){
// Storage for topics that can be broadcast or listened to
var topics = {};
// Subscribe to a topic, supply a callback to be executed
// when that topic is broadcast to
var subscribe = function( topic, fn ){
if ( !topics[topic] ){
// Ben Alman's Pub/Sub implementation
var pubsub = {};
(function(q) {
var topics = {},
subUid = -1;
// Publish or broadcast events of interest