Skip to content

Instantly share code, notes, and snippets.

@stefpe
stefpe / async_process.php
Last active February 15, 2021 20:33
async_process.php
<?php
class AsyncProcess
{
private int $pid;
private string $command;
/**
* AsyncProcess constructor.
* @param string $command
*/
@stefpe
stefpe / split_pdf.py
Last active December 22, 2020 16:30
Split pdf into single pages
#!/usr/bin/python
import sys
import os
from CoreGraphics import *
fileName = sys.argv[1]
inputDoc = CGPDFDocumentCreateWithProvider(CGDataProviderCreateWithFilename(fileName))
private function feedData(): void
{
$productFile = new \SplFileObject($this->productFilePath);
$productFile->fgetcsv();//ignore headline
while ($data = $productFile->fgetcsv()) {
list($rowIdx, $title, $price, $retailer, $rating, $desc) = $data;
$doc = array_merge(
$this->indexDefinition,
[
<?php
namespace App\Command;
use Elasticsearch\Client;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@stefpe
stefpe / Dockerfile
Created May 6, 2020 19:18
Simplest PHP-FPM Dockerfile
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install opcache
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
ADD ./override.ini $PHP_INI_DIR/conf.d/
@stefpe
stefpe / docker-compose.yml
Created August 8, 2019 09:08
symfony setup mac osx
version: '3'
php_api:
image: dockerwest/php-symfony:7.2
container_name: php
volumes:
- ./:/var/www
environment:
- APP_ENV=dev
- DEVELOPMENT=1
- PHP_EXTRA_MODULES=xdebug
@stefpe
stefpe / nginx_fcgi_reverse_proxy_cache.conf
Created June 7, 2019 21:01
nginx fastcgi caching reverse proxy
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=fpmcache:100m max_size=10g inactive=60m use_temp_path=off;
fastcgi_cache_key "$request_uri|$request_body";
fastcgi_cache_methods POST;
server {
server_tokens off;
listen 80 default_server;
server_name server_name _;
access_log /dev/stdout;
error_log /dev/stderr;
@stefpe
stefpe / symfony_levenshtein.php
Created April 17, 2019 09:58
Alternatives by computing the levenshtein distance in symfony
<?php
$lev = levenshtein($subname, $parts[$i]);
if ($lev <= \strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
} elseif ($exists) {
$alternatives[$collectionName] += $threshold;
}
@stefpe
stefpe / json_serializable.php
Created April 16, 2019 19:24
json serializable class
<?php
/**
* Class Person
*/
class Person implements JsonSerializable
{
/**
* @var string
*/
@stefpe
stefpe / flattened_array.php
Created April 15, 2019 19:57
flattened array with a simple value
<?php
$array = [
[
'name' => 'Misty',
'age' => 15
],
[
'name' => 'Charlie',
'age' => 40