They say you learn something new every day.

Posts tagged ‘scripting’

Automating Photoshop (08/11/2012)

I’ve been obsessed with automating and scripting things for a while now. I know it’s weird, but I actually enjoy scripting. It’s precise, it’s quick it’s efficient.

I’ve been using vbscript a lot, since you can automate most core components of Windows, you can automate Microsoft Office and also, it’s very easy. It has a syntax that really makes sense to me. There aren’t lots of curly braces, which I’m not a big fan of.

However, today, by chance, I discovered that you can automate much of Photoshop too using Actions. It essentially works by creating a Macro. You click on Window => Actions and then you can record a new action. I wish I’d known this yesterday when I went through and recoloured 26 images. But oh well, you live and learn. So I’ll be less stupid next time, which is all I can hope for.

Advertisements

URL Encoding (03/04/2012)

Ah encoding! One of those things that causes me so many problems, but which I’ve put so little thought into. Today, I discovered you can set Internet Explorer to do so automatically:

To configure Internet Explorer for automatic encoding

  1. Choose Tools > Internet Options.
  2. Click the Advanced Tab.
  3. Select the Always send URLs as UTF-8 check box.
  4. Restart the browser.

Second Highest Value (02/04/2012)

I had to get the second highest value from a database today. Something that I thought was going to be really difficult. But actually, it wazs fine:

SELECT MAX( col ) FROM table WHERE col < ( SELECT MAX( col ) FROM table )

Even More Basic (22/03/2012)

Somewhat ironically, given yesterday’s post, I found a way of making my application even simpler today.

I don’t want to go into the specifics, because this site is about general lessons, but I didn’t notice this simplification yesterday.

It involved changing one of the dependencies, and in my head yesterday I’d viewed them just as “fixed” points that I had to work around. Luckily, I was able to change them, and so make what was coming in simpler.

Once I could do this, it simplified the whole internal workflow – basically rather than splitting something into two arrays and searching either of them, I just left it as one and searched it all as once.

I think the lesson is, when you look at a problem, look at all parts of it. A friend of mine at work often says, “What’s the exam question here?”. I think it’s a good way to look at it: often people get so bogged down in the detail, they forget what it is exactly they’re trying to do.

Couldn’t give a Flying Duck (15/03/2012)

There’s a great post on CodingHorror about solving problems by explaining the problem very clearly.

Bob pointed into a corner of the office. “Over there,” he said, “is a duck. I want you to ask that duck your question.” 

I looked at the duck. It was, in fact, stuffed, and very dead. Even if it had not been dead, it probably would not have been a good source of design information. I looked at Bob. Bob was dead serious. He was also my superior, and I wanted to keep my job.

I awkwardly went to stand next to the duck and bent my head, as if in prayer, to commune with this duck. “What,” Bob demanded, “are you doing?”

“I’m asking my question of the duck,” I said.

One of Bob’s superintendants was in his office. He was grinning like a bastard around his toothpick. “Andy,” he said, “I don’t want you to pray to the duck. I want you to ask the duck your question.”

I licked my lips. “Out loud?” I said.

“Out loud,” Bob said firmly.

I cleared my throat. “Duck,” I began.

“Its name is Bob Junior,” Bob’s superintendant supplied. I shot him a dirty look.

“Duck,” I continued, “I want to know, when you use a clevis hanger, what keeps the sprinkler pipe from jumping out of the clevis when the head discharges, causing the pipe to…”

In the middle of asking the duck my question, the answer hit me. The clevis hanger is suspended from the structure above by a length of all-thread rod. If the pipe-fitter cuts the all-thread rod such that it butts up against the top of the pipe, it essentially will hold the pipe in the hanger and keep it from bucking.

I turned to look at Bob. Bob was nodding. “You know, don’t you,” he said.

“You run the all-thread rod to the top of the pipe,” I said.

“That’s right,” said Bob. “Next time you have a question, I want you to come in here and ask the duck, not me. Ask it out loud. If you still don’t know the answer, then you can ask me.”

It’s a really good point. Too often, we just haven’t sorted through things clearly enough in our head and that’s why we struggle to come up with the solution.

I read this, this morning. And while I haven’t had chance to try it out yet, I can think of times when I’ve done it. And now that I’m aware of it, I’m going to make a greater effort to think through the question when I’m facing a problem.

A Touch of Class (17/02/2012)

I think I suddenly understood classes and objects today.

I get this quite a bit with coding concepts. Or maybe concepts in general. I leave them mulling over in my head, and then suddenly, one day, I get them,

I think no one has ever really explained objects very well, and I think a key part of that is that I never got when I would use one. I think the fact that you don’t really need them makes it even harder.

But classes are basically like multiple functions in one. Here’s a demo one I built to explain them to myself:

Class TVProgram

Public StartTime
Public Test
Public ProgramTitle

Public Property Get ProgramDate
ProgramDate = Day(Test) & ” ” & MonthName(Month(Test)) & ” ” & Year(Test)
End Property

End Class

Set objTVShow = New TVProgram
objTVShow.StartTime = CDate(“17:30”)
objTVShow.Test = DateSerial(1999,9,17)
objTVShow.ProgramTitle = “TV Show”

wscript.echo objTVShow.ProgramDate & ” – ” & objTVShow.Test

So the first few lines:

Public StartTime
Public Test
Public ProgramTitle

Are like the Function variables. You assign values to these.

Public Property Get ProgramDate

Is like the Function output. You can have several of these in one class, and this is the real value to them and the thing I don’t think I got until now: classes are like functions with lots of outputs. This means you can define different outputs with the same data, or different parts of output for the same idea.

It gives me a nice warm feeling when I suddenly understand something like this. And it makes me wonder why I never understood it before. However, I think part of this comes from the fact no one ever really says what classes actually are:

You can use classes to describe complex data structures. For example, if your application tracks customers and orders, you can define two classes for them, each with a unique set of internal data (typically called properties) and functions (typically called methods). You can then manage customers and orders as if they were native VBScript subtypes. More important, because you assign a class its properties and methods (i.e., its programming interface), you have an object-oriented tool to improve VBScript applications.

Does that really help in any way? Or does that leave you even more confused by what they’re actually talking about?

Tag Cloud