Skip to content

Instantly share code, notes, and snippets.

@naitsirch
naitsirch / AjaxAuthenticationListener.php
Last active Aug 29, 2015 — forked from xanf/AjaxAuthenticationListener.php
How to register an Symfony event handler to prevent JSON/AJAX requests to be redirected
View AjaxAuthenticationListener.php
<?php
namespace Acme\Bundle\MyBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
class AjaxAuthenticationListener
{
@naitsirch
naitsirch / Symmetric Encryption and Decryption of large Files with OpenSSL.md
Last active Apr 12, 2019
Symmetric Encryption and Decryption of large Files with OpenSSL
View Symmetric Encryption and Decryption of large Files with OpenSSL.md

PHP lacks a build-in function to encrypt and decrypt large files. openssl_encrypt can be used to encrypt strings, but loading a huge file into memory is a bad idea.

So we have to write a userland function doing that. This example uses the symmetric AES-128-CBC algorithm to encrypt smaller chunks of a large file and writes them into another file.

Encrypt Files

@naitsirch
naitsirch / pre-commit
Last active Mar 19, 2019
Check if Git username is defined locally
View pre-commit
#!/bin/bash
# ## Description
# This pre-commit git hook makes sure that a local username is defined if there is any remote repository on github.
# This is helpful if you are working with multiple remote hosts and use different usernames. If you forget to configure
# the local username you may end up sending a wrong username to your github remote.
#
# ## Usage
# This is script is only useful if you make it available as a hook template. To achieve this, follow these steps:
#
@naitsirch
naitsirch / datensicherung.bat
Created Sep 8, 2019
Papas Datensicherungs-Script
View datensicherung.bat
@echo off
echo.
echo Hallo,
echo die Datensicherung wird gestartet. Datensicherung wird unter E: gesichert.
echo.
robocopy "C:\Users\Heinrich\Desktop" "E:\Datensicherung\Desktop" /MIR /NP
robocopy "C:\Firma" "E:\Datensicherung\Firma" /MIR /NP
robocopy "C:\Privat" "E:\Datensicherung\Privat" /MIR /NP
@naitsirch
naitsirch / README.md
Last active Apr 8, 2022
FastCGI und PHP-FPM mit Apache 2.4 und PHP 7.x unter Debian nutzen
View README.md

Apache mit FastCGI und PHP-FPM

Bei Debian sollte '''nicht''' das fastcgi sondern das proxy_fcgi Modul verwendet werden. Dafür wird die Konfiguration standardmäßig bereitgestellt.

Zunächst müssen die passenden Pakete installiert werden:

sudo apt install php-fpm

Die Konfigurationsdateien finden sich unter

@naitsirch
naitsirch / ssl-cert-generator.sh
Created Apr 8, 2022
SSL Certification Generator
View ssl-cert-generator.sh
#!/bin/sh
# References this great tutorial for creating an own CA and certificates based on it:
# https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/
#
# It is assumed that the CA cert is located at /etc/ssl/certs/root.pem and the CA key
# at /etc/ssl/private/root.key
#
if [ "$#" -ne 1 ]
then