Sunday, August 7, 2011

Efficiency in Photo Blogging

I recently started taking a lot of photos, with the idea that I would post them to my new photo blog. This has worked out well so far, except for the manual process of stripping out the uploaded image URLs and manually placing them into my template.

After a handful of day-long marathon copy-paste sessions, I've rescued myself from this heavily manual process using Python. Now I only need to paste a couple of links into a data file, and the script builds the rest.

'''
Language: Python

Run this script in the same folder as a source file "links.txt".
    Odd lines contain the picture's href link
    Even lines contain the picture's image src

Similar to:
    http://picasaweb.google.com/000000000000000000000/AlbumName
    http://lh6.googleusercontent.com/-XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXX/XXXX/YYYY_MM_DD-XX_SIZE.JPG
'''
import glob, re

filename = "links.txt"
f = open(filename, "r")
flines = f.readlines()
f.close()

count = 0
blogText = ""

blogPost1 = '<div class="separator '
blogPost2 = '" style="clear: both; text-align: center;">\n'
blogPost2 = blogPost2 + '<a href="'
blogPost3 = '" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="300" width="450" src="'
blogPost4 = '" /></a></div>\n'
blogPost4 = blogPost4 + '<h2 class="'
blogPost5 = '">Photo title</h2>'

sectionBreak = "<!-- More -->"

# Regular Expressions to pattern match the file name
# ex. 2011_06_13-B.jpg or 2011-07-23-A3.jpg
findB = r"[0-9]{4}[\-_][0-9]{2}[\-_][0-9]{2}[\-_]B[a-zA-Z0-9_\-]{1,6}.JPG"
findNotA = r"[0-9]{4}[\-_][0-9]{2}[\-_][0-9]{2}[\-_][B-Zb-z][a-zA-Z0-9_\-]{1,6}.JPG"

headingCSSClass = "objective"
imageCSSClass = "topPic"
imageHREF = ""
imageSRC = ""
breakText = ""
for line in flines:
count = count + 1
line = line.replace("https://", "http://")
line = line.split()[0]
if count % 2 == 1:
imageHREF = line
else: # count % 2 == 0:
imageSRC = line
#if the line ends with a "B" image, prefix it with a seciton break
matchB = re.search(findB, line)
if matchB:
breakText = sectionBreak

matchNotA = re.search(findNotA, imageSRC)
if matchNotA:
print("Not A: "+imageSRC)
headingCSSClass = "runnerUp"
imageCSSClass = "secondPic"
blogText = blogText + breakText + "\n\n" + blogPost1 + imageCSSClass
blogText = blogText + blogPost2 + imageHREF
blogText = blogText + blogPost3 + imageSRC
blogText = blogText + blogPost4 + headingCSSClass + blogPost5

# resets for the next run.
headingCSSClass = "objective"
imageCSSClass = "topPic"
imageHREF = ""
imageSRC = ""
breakText = ""

print ("BlogText: " + blogText)

The result? In the time it took me to prep a single post's links, I had prepped and named four seperate posts. This has freed up a lot more time to work on the content of the posts rather than processing them.

Analysing the code

I built this quickly, with the intent of making it useful as soon as possible. As a result, there are a few improvements that can be made. For example:

  • Take the links data file name as an input
  • Write the output to a file, with a manual override for output file name
  • Assuming all images are named consistently (they are), the script could re-order pairs of links automatically, so the source file can be unordered but still yeild an ordered post. This would require some rebuilding, but would be more versitile

All in all, the code does its job.

Resizing Images with ImageMagick

A second improvement to the efficiency of posting to my photo blog is the use of a program called ImageMagick. It's a program that allows me to resize and rename my original photos via the command-line. While I don't yet have a script to automate this part, not having to open and resize each photo individually will save me a lot of time. Again, it will increase the time I can spend doing creative things instead of copy-paste drudgery.

- - - - - - - - - -

It may not be for a wiki, but ImageMagick still works wonders.

Monday, January 17, 2011

Installing Apache web server on Windows 7

After a quick detour to install Notepad++, I'm on my way to installing Magento. Before I can get into the meat of it, though, I do require a few prerequisites.

From the installation instructions, installing Magento requires:
  • Apache 1.3.x or Apache 2
  • PHP 5.2.0 and above with Safe mode off
  • MySQL 4.1.20 and above
After a brief search, I happened upon a very handy site (Yes, my current dev machine runs Windows 7). No sense reinventing the wheel, so these instructions should do nicely.

Apache


I've chosen the latest stable release, 2.2.17, MD5-verified and ready to install.

Always one to put the right foot forward... The first thing I've done is to immediately download the wrong version (src) instead of the neatly prepped installer (msi) as per the instructions. Round 1 goes to my eagerness, but after a neat revisit to the Apache download page, I'm off in the right direction.

After kicking off the Apache installer, my first instinct was to twitch at the frozen installer progress (Did the instructions forget about that ghastly Windows 7 User Account Control?), but after only a brief pause, the UAC prompt has displayed and the Apache web server installation is back on track.

None the worse for wear, time for the next step.

PHP


I've pretty much kaboshed most of the PHP installation instructions, mostly due to its avoidance of the handy PHP for Windows installer. Pointing the installer to the Apache web server's cgi-bin folder seems like a good idea.

A configuration change...

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext" ; Uncommented (removed the semicolon at the beginning of) this line

... and I'm back to the instructions. After an update to my environment variables, looks like it's time for a reboot... and sleep.

I'll be leaving the MySQL install (and testing Apache web server and PHP) 'til tomorrow.

- - - - - - - - - -

It's time to modify the css behind my code div...
...so that really long text doesn't take up more than one line and I don't have to stare at it in a sleepy daze.
Edit: Done!

Saturday, January 15, 2011

Magento

I've been looking at Magento recently. My job has taken me into the world of e-commerce and, naturally Magento tends to crop up every now and then.

According to the installation instructions, Magento runs off of an Apache web server, PHP 5.2+, and MySQL (among other things).

And did I mention that Magento is Open Source?

Over all, it has a very attractive presentation and a usable interface for someone just getting started with the software. The Knowedge Base resources are pretty extensive and the community forums seem to be pretty active. Nothing too intimidating here, let's give it a whirl.

Tuesday, September 28, 2010

Picking the Right Password

An Appetizer...


I've been spending a lot of time lately, wondering just what I could talk about that would be perfect for me to comment on. What thing could I talk about better than anyone else on the face of this planet? What thing could I shine light on that would thrill and enthrall all who read it?

...

Nothing really.

Now, I'm not being self defeatist, I'm being practical. A year and a half out of university with an abundance of enthusiasm and a smidgen of luck, I have a great job, but no real expertise to speak of.

That's when it hit me: Take it down a notch. Start from the beginning (I hear it's a very good place to start).

What's something everybody uses, something basic... Passwords.

Passwords are something of a nuisance to everyone. A necessary evil that, one way or another, everyone encounters. Different security policies force different password requirements - punctuation, capital letters, numbers, more than six characters, less that sixteen...

What Not to do


Before getting into some tips on what should be done, here are a few suggestions on what not to do.

Don't...
  • Don't use whole words, phrases or names. - If someone wants your password, it's easy to link escapades of Fluffy to your account... assuming it's not a more high-tech dictionary attack, that is.
  • Don't use easy passwords - "12345", "abc123", "password", "princess", "qwerty"... any of them familar? If so, it's because millions of other people have the exact same password!
  • Don't use your username - it's practically giving it away
  • Don't use the same password everywhere - not all sites are created equal. Some of them are in it for the money, and that means selling your data. Usernames, passwords, age/sex/location... the sky's the limit. Keeping a different password for get-free-stuff dot something-or-other and your bank... probably a good idea.

The Meat of the Matter


So, how to choose something memorable, but something that still complies with all these sometimes-conflicting rules?
  1. Keep it simple! - pick something you won't have a hard time remembering.
  2. Mix it up - Use camelCase (caPiTalIziNg random letters), l33t (numbers and symbols in place of letters)
  3. Relate it to what you're using it for - Having a hard time remembering what your password is for dizzyducksgoquack dot com? Start it off with a DDGQ and end it off with your street's first letter and house number, for something like DDGQsj129. Make sure you can remember it later
  4. Shorten phrases by picking the first letter of every word - Like so: spbptflofw (could also be: 5pBp7f103w, 5PbP7f1oew, etc.)
  5. "What about puncuation?" one might say. What about it? Use it! - Wap?0M5.u1!

Obviously there are other factors to contend with... policies that force password changes every 30 days or have specific requirements have to be taken into consideration. In the end, it can be worth it. With access logs keeping tabs on many user activities, it's easy to be caught with a hand in the cookie jar - but if you haven't eaten the cookie, it's probably not such a good thing to look like you did.

- - - - - - - - - -
But soft! What light through yonder window breaks?

b5VV17yVVb

Sunday, May 23, 2010

Changing settings in Ubuntu

The new Ubuntu 10.04 window button layout was a surprising and unexpected change. Thanks to howtogeek for helpful instructions - and only the second hit on a Google search for: "ubuntu 10.04 close button".

To summarize (without all the nice screenshots):

The Problem

Ubuntu 10.04 window buttons (close, minimize, maximize, etc) are on the left by default.

A Solution

Make configuration changes to move the buttons around:
  1. Open the gconf-editor
    1. ALT+F2 - open the Run Application window
    2. enter gconf-editor
    3. press Run
  2. Expand Applications > metacity > general
  3. Double-click button_layout - edit the button order
  4. Enter menu:minimize,maximize,close or :minimize,maximize,close - change the order of the buttons as desired.

Button Layout Syntax - An Aside

You can place different buttons in different places, as determined by their relative order and a couple of syntactical symbols:

: (colon) is like the 'middle' of the window bar. Anything to the left of the colon will be on the left-hand side. Anything to the right will be on the right-hand side. So what if you want to put something in the middle of the window? Dig deeper!

, (comma) is the separator between elements that you want displayed.

menu is the menu button. It has functions that can also be performed by right-clicking on a window's bar, things like "minimize" and "move"

minimize is the one-click button that minimizes the window it's associated with.

maximize is the one-click button that maximizes the window it's associated with.

close is the one-click button that closes the window it's associated with.

Here endith the aside.


- - - - - - - - - -

In order of preference (pun intended):

menu:minimize,maximize,close

:minimize,maximize,close

minimize,maximize:close

maximize,minimize:close

Saturday, May 22, 2010

Ubuntu Rant and Holler

Ubuntu Saga: Upgrade The Second

I upgraded to Ubuntu 10.04 today. I say 'upgraded', but what I should say is 'installed'.

With the new installation, everything's shiny and new: distro, themes, backgrounds... configuration settings...

I started an official upgrade from 9.10 to 10.04 and it failed miserably - as it did when I attempted an upgrade from 8.10 to 9.04 almost a year earlier. Before the upgrade completed it hung, stealing my time and my GUI interface. Luckily, the command line still worked, so I was able to back up my data and start from scratch with a LiveUSB.

Hence 'installation' instead of 'upgrade'. Hence new configuration settings.

Usability

I logged into my completely new Ubuntu 10.04 installation and the very first thing I noticed: Left-hand window controls. Like a Mac.

Now, I have nothing against a Mac per se, but I do have a distaste for usability changes without gain. In my mind, this was not the brightest move, and I don't understand what inspired this odd decision. How is it useful to make a fairly significant usability change ten versions and several years in?

On the plus side, I now know where to make major configuration changes - something I had neither the interest, nor motivation to do in the past eight years that I've actively used Linux.

- - - - - - - - - -
If (!system.Upgrade()) {
frustration++

system.data.backup()
sleep(60)

install = new Installation()
install.Start()
sleep(60)

if (install.window.alignment==LEFT) {
frustration++
install.window.alignment.ChangeAlignment(RIGHT)
}
}

Wednesday, January 13, 2010

Wiki world

As part of my foray into the wiki world of common good, I've written a small, but effective little script for automating conversion and reduction of JPG format images to PNG images of a specific size, using a tool called ImageMagick:
#!/bin/sh
for img in `ls *.jpg`
do
baseimg=`echo $img | sed s/\.jpg/\.png/`
convert $img -resize '300x300>' $baseimg
done

Certainly not the most versatile piece of code (yet), but it was written in minutes and has saved me quite a bit of time so far. If/when the need arises I'll modify it (and post it here).

Enjoy!

- - - - - - - - - -
ImageMagick does a number of things: