Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
ivanhoe011 / clean_pdf.sh
Created January 29, 2022 00:55 — forked from sneakers-the-rat/clean_pdf.sh
Strip PDF Metadata
# --------------------------------------------------------------------
# Recursively find pdfs from the directory given as the first argument,
# otherwise search the current directory.
# Use exiftool and qpdf (both must be installed and locatable on $PATH)
# to strip all top-level metadata from PDFs.
#
# Note - This only removes file-level metadata, not any metadata
# in embedded images, etc.
#
# Code is provided as-is, I take no responsibility for its use,
@ivanhoe011
ivanhoe011 / find-deleted.sh
Created July 21, 2021 05:13
Find when was a file deleted from the git
# show the last entry in the git log for any file that ever existed in the repo (use -2 for the last 2 entries, and etc.)
git log --full-history -1 -- <deleted/file>
@ivanhoe011
ivanhoe011 / example.php
Created February 8, 2021 05:19
Set relationship data on Eloquent model manually
$model->setRelation('foo', $foo);
@ivanhoe011
ivanhoe011 / proxy.php
Created December 23, 2020 13:25
Proxy stream a file using cURL
<?php
// Source: https://github.com/alexandra-default/cURL-proxy-video
/**
* Created by Alexandra.Default.
* Date: 09.06.2018
* Time: 15:31
*/
class VideoStream
{
@ivanhoe011
ivanhoe011 / composer_no_limit.sh
Last active July 17, 2020 21:56
Disable COMPOSER_MEMORY_LIMIT temporarily
####
# If you're getting this error in composer:
# "PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted ..."
# and changing php.ini doesn't help that's because composer has it's own
# memory limit settings. To disable it on a single run, call composer this way:
#
COMPOSER_MEMORY_LIMIT=-1 composer require phpoffice/phpword
@ivanhoe011
ivanhoe011 / preview.php
Last active April 30, 2020 19:15
Create a preview of the pdf document
<?php
$im = new Imagick();
$im->setResolution(300, 300); //set the resolution
$im->readImage('document.pdf[0]'); //[0] for the first page
$im->setImageFormat('jpg');
$im->writeImage('preview.jpg');
// or to output it:
// header('Content-Type: image/jpeg');
@ivanhoe011
ivanhoe011 / run_once.sh
Last active October 23, 2019 22:28
Add global .gitignore to your home to exclude across all repos (without creating noise for others in your team in a local .gitignore)
# add file to use as a global .gitignore
touch $HOME/.gitignore;
# set it as a global excludefile in git
git config --global core.excludesfile $HOME/.gitignore;
# LATER: just edit entries like in a normal .gitignore
vim $HOME/.gitignore;
@ivanhoe011
ivanhoe011 / untested.php
Last active May 12, 2019 17:11
Simple idea how to batch resize images on S3
<?php
// this code is not tested, sorry if there are errors, but it should do the job with a little tweaking here and there...
foreach($images as $file) {
$img = Image::make($file);
$img->resize(null, 1000, function ($constraint) {
$constraint->aspectRatio();
});