Wednesday, December 16, 2015

Throwback Thursday inspired python code.

Throwback Thursday inspired code.

For anyone else out there finding this, if you take the code and modify it or put it somewhere else public, let me know. If I do such a thing, I too will let you know.

First off, all I wanted was a way to find images for Throwback Thursday and I have a very messy folder called Pictures and in there my photos go back to 2003, November.

Some are older, but their modification/creation dates on my computer will not reflect their true date/time so this tool will be useless for those. Unless I modify it later, for example, I can think of an improvement. . . if date modified content does not match date in name of file (parse the name of the file) then use the name as the date.

[update] I am not sure how to make this better. It is definitely not 100% accurate. For example, today, some of the 10 images I've pulled up were created on 9/6/2012 (Thursday) BUT they were created for a web-site by a script I used in the past.  By pure coincidence, it also happens to be originally taken on Thursday, July 19, 2012... so, here it is :).

Angel Island, Thursday, July 19, 2012


The code is currently below. I also put it on Siafoo.

================================= usage:

Mac OS X Terminal with python3 and python installed.  This python3 is 3.4.

Show in Mac Preview app 10 files of png or jpg found in /foo/bar directory:

python3 tbt.py /foo/bar/ -n 10 -m

List all files in /foo/bar directory:

python3 tbt.py -l /foo/bar

List all options with -h:

unknown68a86d404130:play michaelcase$ python3 tbt.py -h
usage: tbt.py [-h] [-d D] [-l] [-m] [-mw] [-n N] directory

Program for "Throwback Thursdays" allows users to specify day of week to find,
defaults to Thursday, and provides a list of files of jpg and png within the directory you
specify that occurred on that day of week. However, precedence goes mw, m then
l. In other words, ONLY ONE of those flags will be supported, if you specify
more than one, the precedence is enforced.

positional arguments:
  directory   Required. Directory from which to read files.

optional arguments:
  -h, --help  show this help message and exit
  -d D        Optional. Day of week. Defaults to Thursday. Can not do multiple
              days.
  -l          Optional. Reply with list of files that can be passed to
              something like xargs.
  -m          Optional. Mac OS open Preview App with resulting list of files.
              If the list of files gets too long, the command may fail.
  -mw         Optional. Mac OS open Preview App with one image per window. Can
              be torture to your screen, be careful.
  -n N        Optional. Number of files to *randomly* retreive from list.

(Revision 1.0 of 2015-12-14 14:15:28)


================================= code, cut here to end. put in file tyt.py


# use os.path.getctime to get creation date/time.
# use date.weekday() to get 0 = Monday to 6 = Sunday.
# then use present Thursdays as tbt files :)

# ctime - the last time the file's inode was changed (e.g. permissions changed, file renamed, etc..)
# mtime - last time the file's CONTENTS were changed
# atime - last time the file was accessed.
# author: Michael E. Case, mec at dcn dot davis dot ca dot us
 
import sys
import os
from datetime import *
import time
from sys import argv
#from subprocess import Popen
import argparse
import random

# 2015-12-14: 
# Given a path, search through it and all it's subdirectories for "throwback thursday" files.

# info to identify program and current revision, and some globals.
global pgm, rev, date
pgm  = (sys.argv[0]).replace('./','')
rev  = '$Revision: 1.0 $'.replace('$','')[9:].strip()
date = '$Date: 2015-12-14 14:15:28 $'.replace('$','')[5:].strip()

def isint( s ):
    try:
        int(s)
    except ValueError:
        return False
    else:
        return True

def tbt_main():

    #read command arguments
    global pgm, rev, date

    ap = argparse.ArgumentParser(prog=pgm, epilog="(Revision "+rev+" of "+date+")", description="""Program for \"Throwback Thursdays\"
allows users to specify day of week to find, defaults to Thursday, and provides a list of files of jpg and png within the directory 
you specify that occurred on that day of week. However, precedence goes mw, m then l. In other words, ONLY ONE of 
those flags will be supported, if you specify more than one, the precedence is enforced.""")    
    ap.add_argument("directory", help="Required. Directory from which to read files.")
    ap.add_argument("-d", help="Optional. Day of week. Defaults to Thursday. Can not do multiple days.", default="3")
    ap.add_argument("-l", help="Optional. Reply with list of files that can be passed to something like xargs.", action="store_true", default=False)
    ap.add_argument("-m", help="Optional. Mac OS open Preview App with resulting list of files. If the list of files gets too long, the command may fail.", action="store_true", default=False)
    ap.add_argument("-mw", help="Optional. Mac OS open Preview App with one image per window. Can be torture to your screen, be careful.", action="store_true", default=False)
    ap.add_argument("-n", help="Optional. Number of files to *randomly* retreive from list.", default=-1, type=int)
    newargs = ap.parse_args() 
    #print(newargs)
    #if ()
    listfiles = newargs.l
    indir = newargs.directory
    nf = newargs.n
    macprev = newargs.m
    macprevwin = newargs.mw
    dow = 3
    if isint(newargs.d) == False:
        lcd = newargs.d.lower()
        if "monday" in lcd:
            dow = 0
        elif "tuesday" in lcd:
            dow = 1
        elif "wednesday" in lcd:
            dow = 2
        elif "thursday" in lcd:
            dow = 3
        elif "friday" in lcd:
            dow = 4
        elif "saturday" in lcd:
            dow = 5
        elif "sunday" in lcd:
            dow = 6
        else:
            print(newargs.d+" not found in day of week. Day of week will default to Thursday (3).")
            dow = 3
    else:
        if dow > 6:
            print(newargs.d+" is greater than 6. Day of week will default to Thursday (3).")
            dow = 3


    if macprev == True and macprevwin == True and listfiles == True:
        macprev = False
        listfiles = False
        print("Found -mw, -w and -l, precedence dictates using mw.")
    if macprev == True and listfiles == True:
        listfiles = False
        print("Found -w and -l, precedence ditates using -m.")
    if macprevwin == True and listfiles == True:
        listfiles = False
        print("Found -mw and -l, precedence dictates using -mw.")

    # print(macprev, str(nf), indir, listfiles)

    # print(indir)
    fs = ""
    fsofar = 0
    randomfs = False
    if nf != -1:
        randomfs = True
    nfilestot = 0
    # probtofind = 0
    rindstosave = []

    # can't figure out how to do this using "probability of this picture being one of the n you requested."
    # or rather, that solution did not always give me n. So the new solution is come up with n integers between
    # one and nfilestot. Those will be the ones we get. No repeats, of course.
    if randomfs == True:
        for root, dirs, files in os.walk(indir, topdown=True):
            #print("in first for")
            for name in files:
                tm = os.path.getmtime(os.path.join(root,name))
                dt = datetime.fromtimestamp(tm)
                if dt.weekday() == dow:
                    if len(name.split(".")) > 1:
                        spl = name.split(".")
                        last = spl[len(spl)-1]
                        if last.lower() == "jpg" or last.lower() == "png":
                            nfilestot +=1
        #print("total number of all jpg and png = "+str(nfilestot))
        if nfilestot > 0:
            nsel = 0
            while nsel < nf and nf > 0:
                rn = random.randint(1, nfilestot) # [1, nfilestot]
                if rn not in rindstosave:
                    rindstosave.append(rn)
                    nsel += 1
                
            # print ("nsel = "+str(nsel))
            # print (rindstosave)
            rindstosave.sort()
            # print (rindstosave)
            # probtofind = nf / nfilestot
    fc = 0
    for root, dirs, files in os.walk(indir, topdown=True):
        #print("in first for")
        for name in files:
            #print("in second for")
            tm = os.path.getmtime(os.path.join(root,name))
            dt = datetime.fromtimestamp(tm)
            if dt.weekday() == dow:
                if len(name.split(".")) > 1:
                    spl = name.split(".")
                    last = spl[len(spl)-1]
                    if last.lower() == "jpg" or last.lower() == "png":
                        fc += 1
                        #print("found jpg")
                        #os.system
                        #Popen
                        if macprev == True:
                            #print (fs)
                            if randomfs == False:
                                fs += "\""+os.path.join(root,name)+"\" "
                            else:
                                if fc in rindstosave:
                                    fs += "\""+os.path.join(root,name)+"\" "
                                    rindstosave = rindstosave[1:]
                        if macprevwin == True:
                            if randomfs == False:
                                os.system("open -a /Applications/Preview.app "+"\""+os.path.join(root,name)+"\"")
                            else:
                                if fc in rindstosave:
                                    os.system("open -a /Applications/Preview.app "+"\""+os.path.join(root,name)+"\"")
                                    rindstosave = rindstosave[1:]
                        if listfiles == True:
                            if randomfs == False:
                                print("\""+os.path.join(root,name)+"\"")
                            else:
                                if fc in rindstosave:
                                    print("\""+os.path.join(root,name)+"\"")
                                    rindstosave = rindstosave[1:]
                        #
#                print(os.path.join(root,name)) 
                # call("open -f -a /Applications/Preview.app", os.path.join(root,name))
    if macprev == True:
        #print ("open -a /Applications/Preview.app "+fs)
        os.system("open -a /Applications/Preview.app "+fs)

if __name__ == "__main__":
    tbt_main()

Tuesday, October 20, 2015

unlimited data plans going.. going... gone... and less memory on phones. Result? lots of uploads and data use.

I guess this isn't going to be a long blog entry. I just find it very irritating that I am once again being phased out of an unlimited data plan by the company I currently use (Credo Mobile).  If I upgrade a phone with them, I have to leave the unlimited plan behind.

I also find that when looking for a new and faster phone, that some of the leaders have eliminated my ability to insert a microSD card.  So I can't move my microSD from my Samsung Galaxy S4 to some new devices.

It seems like the whole cloud thing is interfering with common sense... need faster uploads to REALLY make the cloud work... upload speeds from home are slow and data plans on phones/portable hardware no longer have unlimited data upload/download... so we need larger memory on smart phones in order not to pay too much for cloud access and data transport... stupid companies...

I do not believe that ubiquitous data access will ever be truly available in a free-for-all like true capitalism even with government and industry standards trying to keep up with the changes. And also, competition pushes change forward... but some parts of a system always lag behind...

We will always need local storage and in sufficient quantity for the specs of the video and still shots of our smart devices. I personally get sick of carrying my "good" camera around when really my phone is sufficient for "snapshots" which exceed my old 35 mm snapshots (as opposed to "photography").  But I'll carry it with me, or my laptop, if I think the phone's memory will run out on a trip...

Maybe I take and keep too many photos and videos on my phone.

Meanwhile, I have mirrored my backups (2 single terrabyte drives) and they are running out of space... I need to de-duplicate and clean up my backups...

What was I saying? Oh, either give me unlimited data upload capability with a ubiquitous (truly, like in Yellowstone) data access or give me more memory on my phone please!

Tuesday, August 5, 2014

Windows XP, VMware Fusion 4.1.4, Mavericks, Microsoft Security Essentials pain?

I'm currently frustrated with my machine. I've been e-mailing back and forth with VMware.  I know that Windows XP is not supported anymore.  I also know that VMware Fusion has a version 6 but I'm having to move to Parallels for work. 

The application that I mess with for work that runs on Windows XP may be migrated to Windows 7. I've not done much programming on Windows in the past 14 years, so I'm leaving it up to the owner of the application to decide about the upgrade path.

I wish I had the time(to learn), existing expertise, and energy to think of porting this somewhere else but I've not written drivers for cards before, and I'm responsible for other parts of the platform which also need work.

I'm just writing this up because I installed Microsoft Security Essentials sometime just before Windows XP became unsupported.  After that everything seemed fine though I can't recall testing if my network (mac to VMware) was working.

THEN I installed Mavericks, and THEN VMware has not been able to get to the network.

So I reinstalled VMware Fusion and I still couldn't get to the world from VMware Fusion (Windows XP). 

I also could not see a settings screen in VMware Fusion.  When I went to settings, the main window of Windows XP would grey out (suspended or live) and yet no other window would appear.

I reinstalled the VMware Tools.  Still no joy.

Finally I did get through the internet just by using the "quick" buttons for settings to go between NAT and Bridged, which I had been doing before but to no avail. At this point the network was excruciatingly slow. 

I still could not get to a settings screen so I've given up on that.

Ok, long story... Basically now that I've uninstalled Microsoft Security Essentials the network runs much faster.  I'm going to try to get AVG for XP and hope that will be protection enough for long enough that I don't compromise my Windows XP.

For anyone who cares, when I test with this software, I run the user interface side on Mac OS (Java based), similar to as we do with the real hardware, and run the C/C++ part on Windows XP (again, as with the real hardware). 

The GUI commands the C/C++ on some ports and the C/C++ additionally can initiate connections to another system on other ports.  We issue commands to that third system via the C/C++ system.  For pure simulation that 3rd system is s dumb echo on my mac side.  For testing with a more authentic simulator, that 3rd system is remote, so the Windows XP needs to get out to the rest of the world for that kind of testing.




Monday, August 4, 2014

Woke up, saw a bulging iPhone 3GS. Wow!

I hadn't looked at my iPhone 3GS 32G in a while.  I was thinking of updating my music then using it at the gym so there'd be no phone interruptions.  Instead, I found this!



I have other cell phones, much older, that we occasionally power up and try to charge for a visiting friend and get a SIM card for them to use while in the US.  These phones are not kept charged either and they don't do this.

Anyway, here is a long bunch of commentary on the Apple web site.  I'm thinking of walking in to an Apple Store as some people mention, to see if I can at least get them to dispose of the device properly.

If I dispose of it I want to make sure my data is deleted. I can't recall what all I have on it, but I'd just rather not have anything out there.

Friday, August 1, 2014

Post upgrade summary

Work ordered me a new drive (512 GB SSD) and 16 GB RAM kit to upgrade my 13-inch, Late 2011 Macbook Pro from 256 GB/8GB.  I have too much that I keep running at the same time, such as, migrating from VMWare Fusion (Windows XP) to Parallels (Windows 7) on the C/C++ side and  Netbeans 8.1 for the Java development.  When I want to run both applications (which talk to each other and accomplish one task) I'll have a lot of memory in use at one time... although, right now, I'm only running at 4.something GB real memory used.  So here is the upgrade summary. Pretty easy ... after all my worry.

I put the new drive


In a case I got cheap (like $6 for 5) on Amazon ,



and slid it into the Seagate tray.  Actually, I had to trim part of the opening using an box-cutter (do this at your own risk) as I mentioned here before.  I trimmed the top (thicker, nearer the lid of the box) this time.  These trays were meant for a different drive tray but they work, so I'm happy.



Then I used Carbon Copy Cloner to clone the existing 256GB SSD internal to the new drive.  It allowed me to also copy the hidden volume on the original Apple drive, which was important.  I will buy this product although just the try-me version was great, I really liked it, so I'm paying for it.

The clone didn't take that long, then I cracked the case carefully following these instructions at Apple. I also had peeked at these at iFixit earlier so knew about the drive removal and necessary tools.  I put in my 16 GB RAM and the new 512 GB SSD and it worked!

I am happy I also cloned the hidden partition.  Prior to the install, I booted holding down the D key and ran diagnostics on the hardware to find no problems.  This was when trouble-shooting with Apple about why the machine was re-booting for no apparent reason. The current suspected reason is a bad USB cable. More on that later, maybe.

In any case, after the upgrade I again booted holding down the D key and ran diagnostics with the new drive and RAM in and once again, no errors.  So I'm pretty confident right now.

Well, that's it.








Friday, July 25, 2014

Internet service provider rant.

Could someone PLEASE help me!  Is there any way to get good customer support either online or on the phone anymore? and both had people on the other end who have really bad head-sets or phone systems. I swear the voices were worse than a tin-can-string phone from childhood!

Furthermore, online I find NO WAY to initiate service and request a static IP.

I'm thinking of leaving AT&T because they are VERY VERY slow to correct billing changes and my monthly cost has gone up to $122/month for 20 Mbps down/1.8 Mbps up speeds. $15 of which is for static IP.

Comcast technical support says over the phone that they can do the static IP for free.

They offer 50 down/ 15 up for 12 months at $53 (includes 3.95 in-home cable maintenance) at my address but I only have the word of the tech person that static IP is available and free.

I wish I could find ANY provider not Hughs, not frontier, not AT&T and not Comcast!

If I want to start an ISP, I have to pay one of them for the connection to a major hub in Atlanta (I believe) and what incentive do they have to give me a fair deal since I would be a competitor?

I love OmNetworks back in Davis, California.  I wish I could do something like that here in Atlanta.

Thursday, July 24, 2014

Using Thunderbolt Seagate "tray" for any drive.

I just got the new drive!

I used the Cable Matters 2.5" SATA Hard Drive case to enclose my HGST Travelstar.  It did not work "out of the box" because the opening of the Cable Matters box was slightly too small. I whittled away at the bottom, then at the top. In hindsight I think whittling all the change at the top would have been better.  I used a box cutter. Do that at your own risk. I have cut myself badly in the past trying to whittle plastic, so don't use the drive cover if you don't want to.  It just supports the drive better than sliding the bare drive onto the connector and letting it dangle.

After the adjustments I slid the drive into the the Seagate Thuderbolt "tray" adapter and hooked it up to the Thunderbolt on my MacBook.

I formatted the drive as indicated by Apple, and am proceeding to copy from the  old Time Machine Backup from my WD My Passport drive to the new drive following these instructions also at Apple.

I'm not sure what I will do with the My Passport... keep it as a spare "archive" of Time Machine?  The "genius" at the Apple Store said I can use many drives for Time Machine.  I'll have to look into what he meant by that, other than "use the new drive for new Time Machine backups and forget about the old ones unless you need them" but I can't trust a dieing drive, so I've chosen to copy the files (more than a million so far) from the old drive to the new drive.

This will take a while... more later...

Later:  hahahahahahaha!  No wonder he gave me that advice!


I am underwhelmed.

Update:  I calculated the estimate based on the 35 MB/s USB 2.0 bottleneck of the process and came up with 7 hours.  When I went to bed, the dialog said 3 days.  Got up the next morning it was done.  Relieved to know I was right in my instinct, no way 881GB took 3 days...

Update 2: I did NOT know that you could tell Time Machine to use more than one drive and it decides which backup goes where...  Also been reading about it's limitations.