Sunday, August 21, 2016

the ugly american

I was in Ireland last week, and noticed that FB must have fiddled with their iconography again; the globe icon was quite a bit odd looking. (An I mean, isn't a globe for "Notifications" a little odd anyway?)

Not going to mention how long it took me to figure out the problem. Forgot that i was so Americas-centric in my outlook!

Sunday, August 14, 2016

imagemagick's mogrify to fix ios exif image rotation issues

Digital Photography Circa 1996 -
cyberpunk gargoyle!
A while back I grumbled about what a hot mess EXIF handling was - how iOS photos tended to always store photos line up with the cameras lens and ignoring orientation for the raw data, but then putting in an EXIF header about how the viewer should rotate it, and some browsers did that, and others didn't and it was generally gross.

At some point in the past I found the fix, but I didn't post about it 'til now- maybe I was holding off 'til I could check it working across different browsers, but I haven't seen an issue for a long time, so-
mogrify -auto-orient imagename.jpg
does the trick.

Sometime in the last year or two I made my blogs upload system both resize the uploaded photo to the appropriate width, as well as store it at original size. Wish I had done that years ago, it really lets my blog be a better archive.

If you like seeing a subjective history of digital photography, starting July on my blog (16th or so) and ending today I've been posting a "dozen best photos of the year"... it's been satisfying kind of mentally revisiting those years, getting back some lost time.

Wednesday, August 10, 2016

convert youtube etc to mp3

I like paying for music. 99 cents to 1.29 a pop is fine, being able to pay for almost any song as a single without all the B-side ballast of a full album is a wonder of the modern age. (And then keeping access to the music, without monthly subscription fees, is also a plus, though I kind of see why some people like the selection they offer.)

Anyway, some songs I just can't find on legit pay download sites as much as I'd like to send the artists a token amount... most often stuff from other countries. (With Apple Music (or my past self hosing) my collection a bit lately, there are a few cases where I'll have to do this again) But Youtube is more international than Amazon or the Apple Music store, so when my only option is a youtube video I have had good luck with convert2mp3.net. In the past, it seemed like youtube was playing "wack-a-mole" and disabling services as they popped up, but this one has been stable and reliable for at least a few years now.

Friday, July 29, 2016

fun retrospectives?

I just heard about Fun Retrospectives - seems like a worthy goal. They offer a retrospective tool, http://funretro.github.io/distributed/, that seems like a shinier version of http://ideaboardz.com/ but a few minutes of playing with it suggested it didn't have the latter's serverside wonkiness.

Saturday, July 23, 2016

osx how to drag and drop to a php command line script (or, any script) // hack hack hack

Sorry for the clumsy blog entry title, I'm trying to up the google juice.

Digging my way out of problems with iTunes, I would like to drag a music file from my old archive to a new location; but the gotcha is I want it to copy a subset of the the path (containing the artist and album info) from the source folder to the destination folder.

Most "drag and drop" / PHP googling shows how to make an upload web application. (And obviously, it's probably weird that I've started using PHP so much for this stuff - but since I grew up with Perl as both a command line scripting tool and a cgi resource, it makes a kind of sense.)  If memory serves, on Windows I used to be able to drop a file onto a script file in Explorer, and it would run the script with the file as an argument, but that trick doesn't seem to work on OSX. Or MacOS. Whatever. (Incidentally, for the PHP upload case, I've had great luck with dropzone.js)

So, to the Terminal! (Obviously one of the big appeals of MacOS for a certain flavor of geek was a proper shell terminal vs a DOS Window.) We're going to leverage how dragging a file onto a Terminal window puts in the file path - but it would be annoying to have to type "php myscript.php" before each drag operation, so I'm going to make a convenience script, called "c", just so the name is easy to type:

#!/bin/sh
php copyIncludeSubpath.php "$@"

And then, for EXTRA typing laziness, I'm going to add the current directory to the path (not a good practice in general, but ok for a temporary Terminal window, to save typing ./ all the time)


export PATH=$PATH:.

Anyway, here's the script:
<?php
$oldroot = "/Volumes/My Book/monk/data/music/";
$newroot = "/Users/kisrael/Dropbox/dev/2016/scripting/LibraryXMLCompare/musicToAdd/";
for($i = 1; $i < count($argv);$i++){ #go over everything passed in, skipping name of php script
    $path = $argv[$i];
    copyFileFromRootToRoot($path,$oldroot,$newroot);
}
function copyFileFromRootToRoot($path, $oldroot,$newroot){
    if(substr($path,0,strlen($oldroot)) != $oldroot) { #check for oldroot at start of path
        print "$path doesn't start with $oldroot!\n";
        return;
    }
    $mainpart = substr($path, strlen($oldroot)); #get relevant part of path
    $oldloc = $oldroot.$mainpart;
    $newloc = $newroot.$mainpart;
    $path = substr($newloc,0,strrpos($newloc,DIRECTORY_SEPARATOR)); #get path minus file name
    if(! is_dir($path)) @mkdir($path, 0777, true);  #make it, eating errors
    copy($oldloc, $newloc) || print "FAIL ON $newloc\n";
}
?>
It's a little clumsy, but does the job.

Thursday, July 21, 2016

the history of the url

The History of the URL. Interesting to think about some of the "might have beens", and just to remember that the standards a coder so assumes now weren't handed down by divine mandate, or intuitive common sense...

Monday, July 18, 2016

osx command line power and sorting folders in perl

Talking with some fellow greybeard geeks, I realize I could be consider python instead of PHP as a scripting "light file management and text manipulation tasks" tool, or maybe node.js (native manipulation of JSON definitely appeals to me)

But PHP it is for me for now. I used that php recursive file iterator from the other week to do photo wrangling. I've been going through two decades of digital photos and picking out the dozen best photos from each year - it's a great way to regain a sense of time and place of those years that I might otherwise lose. I've never embraced a photo management program (I tried iPhoto for a while but it's really not geared for collections as big as mine) so my photos are in folders of the form "data/photos/YYYY/some_date_or_descriptor". When I copied each year's best into a new folder, the "metadata" of the folder descriptor was lost, so I made a kind of hacky PHP script to find files that had the matching name in the original folder (considering a matching file size a match) and renaming the chosen out file to embed a mangled form of the extra path info. (Most of the folders had some kind of sortable date at the head of the name, though the actual format varied from year to year.)

There were two small OSX tricks I used, nothing too obscure: one was leveraging how dragging files to terminal copies their full paths, which I would then use as arguments for my script. The other was using PHP's shell_exec() to call "open", which for an image file pops open preview. With those two things I was able to construct a crude UI, so for ambiguous file names (where file size didn't match, because I rotated things) it could open up the two images and say "are these the same file?" (Also, "open ." is the easiest way to pop up the current working directory in a Finder window)

Of course, folder and file name hackery is kind of an ugly way to deal with photo metadata, but over the years it's the only thing I've been able to trust. In a similar note, I've noticed a whole bunch of music missing from iTunes. Not sure what happened, but I think I may have to resort to similar easy-to-backup, possible-to-verify handling for my music and playlists, rather than relying on an endless "smart playlist" for getting back to my new music.

For my homebrew blog, I use a drag and drop photo uploader script combined with some ImageMagick resizing. I so wish I had written it many years ago; my blog is one of my most reliable archives, and my new scripts' method of generating viewable-sized versions - but with links to the fullsize originals - would have kept some big image files safe that I've since lost track of. C'est la vie.

Anyway, the wrapper script for the image processing and construction of img tags and links to fullsize versions is old Perl. Before now I didn't have much of a reason to sort file order (usually I'd upload just one or two images at once) but now I do, so I had to lookup code like the following:

$imagetempDir = ".";
opendir(DIR,$imagetempDir) or print "can't open $dirname";
my @files = sort { $a cmp $b } readdir(DIR);
while ( my $f = shift @files ) {
    if($f ne "." && $f ne ".."){
        print "look at $f<br>\n";
   }
}


I'm putting the code here on the offchance someone else finds it useful. I'm also putting it on my old Perl cheatsheet... kept in a homebrew database system I've been using for over a decade. These days, Simplenote probably does a better job for this kind of stuff, but I didn't have Simplenote and Dropbox back then - they are pretty awesome though.