normalize phone JPG files based on EXIF data
I recently decided to switch to Sprint (from T-Mobile, their network is awful here in San Antonio) and picked up the Motorola Photon 4G (great phone btw) which finally has a decent naming convention for mobile pics. For years I’ve been at the mercy of various HTC, Samsung and LG devices which randomly choose different conventions – in my mind, naming them by date/time is the best way to go and the Photon pleases me. Time to fix all the old (couple hundred) pics I like keeping on my phone to the Photon’s convention.
I found a script which introduced me to JHead so I built upon it – I quickly realized that all my EXIF date headers were whacked out too, all the various cameras stored them differently (using ‘:’ vs. ‘/’ vs. ‘-’ as field separators). This script fixes all that and resets the EXIF header date/time to jheads default.
MAKE A BACKUP OF YOUR PICS FIRST
#!/bin/bash
# normalizeJPEG.sh
#
# requires "jhead" (yum/apt-get install jhead)
# normalize JPG files based on their EXIF header - handy for loads of pics
# taken with different cameras (several phones, e.g.) that store the EXIF
# dates in different formats and name the files differently.
#
# Result: YYYY-MM-DD_HH-MM-SS_###.jpg (where ### is random 100-999)
#
# This script also updates date/timestamp on disk, then reverse updates the
# EXIF header from that stamp to normalize your headers DATE/TIME field
#
# Original: http://neverfear.org/blog/view/148/Rename_all_jpeg_files_by_their_exposure_date_Bash
for file in *.jpg *.jpeg *.JPG *.JPEG; do
if [ ! -e "$file" ]; then
continue
fi
echo "Inspecting $file"
JPGDT=`jhead "$file" | grep "Date/Time"`
JPGFC=`jhead "$file" | grep "Date/Time" | wc -l`
if [ $JPGFC -gt 1 ]; then
echo "Found too many results for: $file"
continue
elif [ $JPGFC -eq 0 ]; then
echo "No valid headers found."
continue
else
BASE=`echo $JPGDT | awk '{ printf("%s %s",$3,$4) }' | sed -e 's/\([0-9][0-9]\).\([0-9][0-9]\).\([0-9][0-9]\) \([0-9][0-9]\).\([0-9][0-9]\).\([0-9][0-9]\)/\1-\2-\3 \4:\5:\6/'`
BASE=`date -d "$BASE" +"%Y-%m-%d_%H-%M-%S"`
RND=$[($RANDOM%899)+100]
if [ ! -e "${BASE}_${RND}.jpg" ]; then
echo "New file: ${BASE}_${RND}.jpg"
mv "$file" "${BASE}_${RND}.jpg"
jhead -ft "${BASE}_${RND}.jpg"
jhead -dsft "${BASE}_${RND}.jpg"
fi
fi
done
thunderbird LDAP autocomplete with Active Directory
The core problem is that the autocomplete while composing emails in Thunderbird uses a different LDAP filter than when you’re just looking in the address book. Depending on how your Exchange/Active Directory admins set up the attributes – and the design of the login names, we have 3 different styles in my company – you may “miss” finding people depending on how you type parts of their name.
Once your LDAP server is set up in Thunderbird it will have preferences based on the name you gave it; I’ll use MYSERVER below, replace with your correct name.
- Open the Thunderbird Preferences, select the Advanced -> General tab
- Click Config Editor (dismiss the warning if it appears)
- Rightmouse click and chose New -> String Value to add these items (so repeat the process for each pair below):
Preference name: ldap_2.servers.MYSERVER.attrmap.DisplayName Preference value: displayName Preference name: ldap_2.servers.MYSERVER.autoComplete.commentFormat Preference value: [displayName] Preference name: ldap_2.servers.MYSERVER.autoComplete.nameFormat Preference value: [displayName] Preference name: ldap_2.servers.MYSERVER.autoComplete.filterTemplate Preference value: (|(mail=*%v*)(displayName=*%v*)(givenName=*%v*)(sn=*%v*)(cn=*%v*))
Now you know, and knowing is half the battle. (Go Joe!)
google music manager “connection to service failed”
Google has released their Linux desktop app for uploading to Google Music – unfortunately it doesn’t seem to work correctly out of the box on Fedora 13/14/15, openSUSE 11.4 and maybe others. The app is looking for a SSL cert bundle in one location only which isn’t present where it thinks:
$ strace -f -o debug.file google-musicmanager
$ cat debug.file | egrep -i "(certificate|bundle)"
22324 open("/etc/ssl/certs/ca-certificates.crt", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
To fix, symlink from the real bundle to where GMM expects it to be:
Fedora 13:
# mkdir -p /etc/ssl/certs
# ln -s /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
Fedora 14 / 15:
# ln -s /etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
openSUSE 11.4:
# ln -s /usr/share/kde4/apps/kssl/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
...or:
# ln -s /usr/share/claws-mail/tools/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
There’s a thread on the forums for people having problems on multiple platforms.
(updated with comment feedback on other releases, thanks!)
compile python bytecode at RPM build time
From the world of quick hacks – I needed to rebuild the Puppet RPM from the EPEL folks for a customer, they need it deployed at kickstart time with custom configs (hundreds of servers). Using the EPEL source RPM the “yumhelper.py” file wasn’t getting compiled into .pyc and .pyo objects on a standard RHEL 5 system (which I’ve seen before with MySQL-python RPMs).
The quick hack was to simply run Python’s compileall module on it:
%install
rm -rf %{buildroot}
ruby install.rb --destdir=%{buildroot} --quick --no-rdoc
# Precompile python modules to avoid selinux issues later
python -mcompileall %{buildroot}%{ruby_sitelibdir}/puppet/provider/package
python -O -mcompileall %{buildroot}%{ruby_sitelibdir}/puppet/provider/package
Is it ugly and dirty? Yes. Does it work? Yes. Problem solved, walk away and get other work done.
online regex testers
I finally got around to creating a site that links all the regex testers I use now and again to work with patterns while I’m doing mod_rewrite rules, (e)grep work, nginx location matches and things like that. Enjoy!
RegEx Testers – Collection of browser based RegEx testers
I claim no ownership to the code, just a handy way to find it all quickly.