I use php to convert pdf to jpeg but sometimes it’s very slow. So, the solution is to use poppler and use pdftoppm directly to shell.
Author Archives: admin
exec and exec_shell in php
If you are using blanks in filenames or any other special character then you need to use escapeshellarg.
https://stackoverflow.com/questions/43513228/php-shell-exec-failed-due-to-some-specific-character
Also, exec and exec_shell are returning status and string of the last command executed (read docs) but it’s somewhat hard to understand when it’s true or false. I didn’t manage to use === operator to check logical expressions returned from the ran command.
https://stackoverflow.com/questions/41212053/php-shell-exec-and-exec-returning-false-when-ran
Also,for pdf merging use:
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
Rsync exclude include
rsync -av --include '*.md' --include '*/' --exclude '*' --prune-empty-dirs src/ dst/
https://unix.stackexchange.com/questions/741904/rsync-to-exclude-everything-except-specific-files
PDF to JPEG
If you need to convert pdf to jpg I was working with php but it might be slow, obviously. But if you are using linux shell then it’s easier and faster.
72 dpi (web) = 595 X 842 pixels
300 dpi (print) = 2480 X 3508 pixels
600 dpi (print) = 4960 X 7016 pixels
Mysql radnom update number
Cool stuff
UPDATE tableName SET columnName = FLOOR( 1 + RAND( ) *3 );
https://stackoverflow.com/questions/14865632/update-all-records-with-a-random-number-from-a-range
Merge pdf with single command in linux
Poppler has one command to merge all pdfs from folder:
pdfunite *.pdf out.pdf
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
MySQL export from command line with query
Very simple.
Always check here:
mysql -u root -p -e "SELECT * FROM employees" my_database > employees.csv
mysql -u posao_statistike -p -e "SELECT d.*, s.grad FROM daljincinecitani d LEFT JOIN sap_maticna_nis_copy_nova_copy s ON d.SER_BR like concat('%',s.fab_broj)" posao_statistike > ~/rezultat.csv
https://www.geeksforgeeks.org/how-to-export-query-result-in-mysql/
SELECT ShortURL, l.LongURL, tag
FROM Links l LEFT JOIN
Domain d
ON l.LongURL LIKE concat('%', d.url, '%');
https://stackoverflow.com/questions/42026673/join-mysql-tables-based-on-partial-match-of-strings
Mysql export db and time zone
When exporting mysql db to different server and have datetime or timestamp fields then it is very important what the time zone is the other server is.
Check mysql for time zone. For phpmyadmin go to variables and there check time zone variable and then go to the server where you need to import db and check time zone on the linux server itself.
You need to make sure both time zones are the same.
https://linuxize.com/post/how-to-set-or-change-timezone-on-ubuntu-20-04
Or just add --skip-tz-utc
to mysqldump. But this is ok for one db but most likely with backup/restore and tar it’s going to be problem. So just use time zone on linux server and restart mysql/mariadb.
https://stackoverflow.com/questions/14886427/mysql-data-export-changes-times
Mysql get names of columns
SHOW COLUMNS FROM tablename
https://stackoverflow.com/questions/4165195/mysql-query-to-get-column-names
S3 copy
You cannot copy from remote to remote. You need to first copy locally and then copy to remote, or vice versa.
If you need to copy from local to s3 you need to setup public ACL then or add policy to allow public access to uploaded files.
https://s3tools.org/s3cmd-sync
## You may choose to remove --recursive if is required only for the bucket or folder and not for objects within.
s3cmd setacl --acl-private --recursive s3://mybucket-name
s3cmd setacl --acl-private --recursive s3://mybucket-name/folder-name
s3cmd setacl --acl-private --recursive s3://mybucket-name/folder-name/object-name
s3cmd setacl --acl-public --recursive s3://mybucket-name
s3cmd setacl --acl-public --recursive s3://mybucket-name/folder-name
s3cmd setacl --acl-public --recursive s3://mybucket-name/folder-name/object-name
For example:
s3cmd sync --skip-existing . s3://sonic/rs/ -c ~/.s3cfg-digitalocean
s3cmd info s3://sonic/ -c ~/.s3cfg-digitalocean
s3cmd setpolicy ~/polisa.json s3://sonic/ -c ~/.s3cfg-digitalocean
s3cmd setpolicy ~/polisa.json s3://sonic/ -c ~/.s3cfg-digitalocean
s3cmd sync --skip-existing s3://leaflets/rs/ ./
cat ~/polisa.json
{"Id":"PublicSharePolicy","Version":"2012-10-17","Statement":[{"Action":["s3:*"],"Effect":"Allow","Resource":["arn:aws:s3:::sonic","arn:aws:s3:::sonic/*"],"Principal":"*"}]}