A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label conversion. Show all posts
Showing posts with label conversion. Show all posts

MySQL date display format conversion

MySQL date time conversion functions: 

  • UNIX_TIMESTAMP(date) docs
  • FROM_UNIXTIME(epoch) docs

Examples:

select name, from_unixtime(time_added, '%Y-%m-%d %h:%i')

from company

order by date_added desc

limit 10; -- list the most recently added companies

You may also omit the '%Y-%m-%d %h:%i' format string, to get the default format YYYY-MM-DD HH:MM:SS, e.g. `2023-09-07 09:43:51`


Working with PDFs on Linux

Combine several PDFs into one:

pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf

Convert image to PDF:

convert page1.png page2.png mydoc.pdf

Convert PDF to image:

convert foo.pdf foo.png

(source, source, source)

Reduce size of a PDF by converting to high quality images reducing size and rebuilding PDF:

convert -density 150 foo.pdf -quality 100 foo.png
for k in 0 1 2 3 4; do convert "foo-"$k".jpg" -resize '75%' "foo_smaller"$k".jpg"; done
convert foo_smaller* foo_smaller.pdf

(source, source, source)

Make all the pages of the PDF the same size:

mogrify -resize x1000 *.jpg
for i in *.jpg; do convert -density x1000 -units PixelsPerInch ${i} ${i}; done
convert *.jpg result.pdf


More tricks:

convert -background white -page a4 -density 150 -quality 80 -compress jpeg *.jpg result.pdf

How to view .msg files on Ubuntu

wget http://www.matijs.net/software/msgconv/msgconvert.pl
sudo apt-get install libemail-outlook-message-perl
sudo apt-get install libemail-localdelivery-perl
perl msgconvert.pl YourMessage.msg

Thanks to this software

Easy way to convert epoch seconds to human readable date in Perl

Easiest way:
print scalar localtime(946684800);
Prints:
Sat Jan  1 00:00:00 2000

Next easiest, more flexible:
require POSIX; print POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime((946684800)));
Prints:
2000-01-01 00:00:00

See hex dump of file on Linux or Mac

hexdump -C [file]

or

cat [file] | xxd