Progress in the New Year

Welcome to the New Year! A lot has happened already, between Google changing their page rank, Apple’s numerous announcements and tons of other cool stuff. I’ve been getting back into the swing of things and mostly trying to figure out how to start off the new year right, i.e. if there was some great “first post” for the year I could conceive.

As can be the case, my desire to make an amazing impression has resulted in me making none, until now.

I graduated from college with a B.S. in Computer Engineering and for anyone not familiar with a Comp.E. degree I tell people I’m a cross between an Electrical Engineer and a Computer Scientist.

Truly, I’m more of a Scientist then an Engineer and probably should have gone the C.S. route based on my job history through the years. However, I like being able to call myself an Engineer and it fits with who I am and how I approach problems.

I tend to act as a “translation layer” and like to approach problems with tangible exploration. I’m more of a system programmer (i.e. C and perl) then a “pomp and circumstance” application architect (e.g. java and relational DB’s).

However, as the “active complexity” (or perceived complexity) of development and IT moves “up the stack” I’ve felt my programming skills start to slip. It’s not theory and design failing but that the barrier of taking ideas to fruition has becomes steeper.

Intending to rectify that situation, and loving the compartmentalized development approach that web services brings, I’ve begun learning python and intend to practice the application and not just theory of programming.

My first “new year need” has been to “spring clean” my data files, I have around 20,000 pictures with many dups (the result of recovering a HD). So coupling intent with need I’ve written my first real python program.

It’s not fancy, and only serves to break out a large directory of files into a smaller (3rds) subset. However, it was a great exercise for me so far. Transitioning to Python isn’t really a syntactical problem but an exercise in realizing that things which were once hard are now easy!

It’s an exercise in mind-shift that we should all try to initiate this year, try it early and start your year out right!

So in case it helps anyone here’s my “code”. I’m sure there are some more “python-esque” ways to do it so if you’ve got any insights please leave a comment!


from glob import glob
from os import stat,mkdir
from shutil import move


def size_cmp(x, y):
if stat(x).st_size > stat(y).st_size:
return 1
elif stat(x).st_size == stat(y).st_size:
return 0
else: # x<y
return -1

files = glob(“*.JPG”)
num_files = len(files)

for f in files[0: num_files/3]: #slice 1
move(f, “1”)
for f in files[num_files/3+1 : num_files*2/3]: #slice 2
move(f, “2”)
for f in files[num_files*2/3+1 : num_files]: #slice 3
move(f, “3”)

About jay

I'm trying to build something interactive where I can learn from others and hopefully share useful knowledge too.
This entry was posted in code, opensource, python. Bookmark the permalink.

2 Responses to Progress in the New Year

  1. jay says:

    Here’s a better bit of code for the last part:

    slice_1 = int(floor(num_files/3)) #1st 3rd
    slice_2 = int(floor(num_files/3)*2) #2nd 3rd
    print “slice 1: %s and slice_2 %s” % (slice_1, slice_2)

    for f in files[: slice_1]: #slice 1
    move(f, “1”)
    for f in files[slice_1 : slice_2]: #slice 2
    move(f, “2”)
    for f in files[slice_2:]: #slice 3
    move(f, “3”)

  2. jay says:

    I already know I have an off by 1 bug…

Comments are closed.