I needed to convert dates to ISO-8601 calendar week and year in a bash script. This is what I came up with:
parser = optparse.OptionParser()
_, args = parser.parse_args()
y, w, _ = datetime.datetime.strptime(args, "%Y/%m/%d").isocalendar()
print "%d/%02d" % (y, w)
It takes input from the command line as YYYY/MM/DD and outputs YYYY/WW.
Copyright Automattic 2012. Public domain where recognized; otherwise Apache 2.0.
Posted by Andy Skelton on December 5, 2012
1 of 16
Posted by Andy Skelton on November 29, 2012
While in Burlington, Vermont, I worked at the excellent Office Squared downtown coworking space. Some days I had to go out for lunch. That one burrito place on Church Street was unworthy of mention. My next try was Top of the Block Sandwich Shoppe. Here I found my usual.
My first time there, I was overwhelmed by the endless options on the sandwich menu. I didn’t want to spend half my lunch break studying a food list. So I simply asked for a sandwich. Any sandwich would do, I said, as long as it’s good. No, I don’t have any food allergies or restrictions. Just make it a sandwich, not a wrap. Surprise me.
This intrigued the young ladies behind the counter. The lucky one who got to make my sandwich was thrilled by the possibilities. She could make whatever she fancied and I would probably love it. The others kept an eye on the project, jealous of her creative opportunity.
I took my sandwich back to the office and I loved it. The bread, the special mayo, the juicy meat and unconventional mix of veggies. This was a unique sandwich made by a person whose curiosity and passion had been aroused by a simple, open-minded request: make me a sandwich. A good one.
Each week I went back once or twice for a new sandwich. Each visit brought smiles to the faces behind the counter. Each sandwich was better than my memory of the last.
By the third visit I didn’t have to speak my order. My request was so memorable that I was an instant regular. I am the guy who wants a random sandwich. Surprise me.
My surprise sandwich was the most consistently pleasurable lunch outside of my home. For the same price everyone else paid for their made-to-order sandwich I got joy, suspense, and possibly the best sandwich made that day.
When ordering a sandwich what I really want is two slices of bread surrounding something good. Turkey, peppers, mustard, none of the above, whatever. Maybe not every sandwich maker has the passion or the sense of humor to do it right like Top of the Block. Maybe I’d be unhappy with the “surprise item” from most other places. I’m happy I found these professionals and took that chance.
Posted by Andy Skelton on October 23, 2012
My 2-year-old daughter suddenly became afraid of the dark. “I’m scared of the dark!” became her screaming mantra at bedtime and her objection to entering any room without an electric light on–even when there was still daylight. This is how I helped to ease her back into a painless bedtime routine. Read the full post »
Posted by Andy Skelton on September 6, 2012
How many times have you frantically googled “svn merge revert” to remember how to undo a recent commit? If you answered “too many” then you were probably confused by the syntax of
svn merge -rARG1:ARG2. After this post you’ll never have that problem again because you can easily memorize
svn merge -c-ARG instead.
# to undo changeset 1234 in the working copy:
svn merge -c-1234 files
c is for “change” and the
- means “in reverse”. When you read that command to yourself, say “svn merge change in reverse 1234″. That is sensible enough that you can remember it forever, even in an emergency. Right?
To apply several changes at once, use several
# to undo two changesets at once:
svn merge -c-1234 -c-1220 files
To re-apply the changes in your working copy for debugging, use
# to re-apply the changes you undid:
svn merge -c1220 -c1234 files
May this knowledge shave precious seconds off your next svn emergency!
Posted by Andy Skelton on June 14, 2012