The Professional Steve

The very important blog of a professional Computer Science undergrad and professional dork

Hey, I Love Christmas Too, But Show Scrooge Some Respect

You remember watching those old christmas specials as a kid? Not the cool animated ones with Frosty and Rudolf, but the made-for-tv ones that disappeared after a few years only to replaced by something just as saccharine. Maybe they show up on the Hallmark Channel now, I don’t know.

In most of these shows, there’s always a Scrooge type character. Someone who doesn’t like Christmas, who isn’t being part of the christmas season and has to be made to comply.

Like the title says, I love Christmas. I like the music, and lights, and the decorations. As a kid, I loved getting presents. Presents are the best! But jeez, not everyone has to get into the spirit of the season. You don’t know everybody’s past. Maybe that time of year brings unpleasant memories. Maybe the Scrooge in question doesn’t like being told to be jolly when they don’t particularly feel like being jolly thank you ever so much. Maybe they’re Jewish, or an Atheist who doesn’t celebrate what they consider to be a religious holiday.

Let’s all show a little tolerance.

You are going to offend someone

It happens. They’re having a bad day. You say something you didn’t mean. All of a sudden you and that person are not in the comfortable world of cubicles, or class rooms, or small-talk. Now there are hurt feelings. You realize that sometimes situations get a bit out of control. Maybe your own feelings are hurt. Take a few moments to calm down. Don’t make an emotional decision about how to proceed. Maybe you’re in the wrong. Maybe the offender is in the wrong. It’s something to take into account, certainly. Just as it is important to take into account that these things happen.

Here’s something else to consider, after you’ve calmed down and taken stock. What is the outcome or set of outcomes you’d like to encourage? Is this someone you’re going to have to work with every day? Maybe it’s not a good idea to burn that bridge. On the other hand it’s important not to become a door mat. But think about the outcome you want to encourage before you encounter that person again.

Reblog {{discovery_collection}} : Installing Tomcat on MacOS with homebrew

I may be really, really, behind, but I am still taking a cloud computing course. Pursuant to completing an assignment in that course (that I started on my Linux machine) on my shiny new Mac, I needed to find out how to install a local instance of the Apache tomcat server. So here are some instructions. :)

This post assumes you already have Homebrew and Java installed. (I didn’t bother with Jenv yet, btw. Just the bare-bones install).

Mapping tab navigation in vim

This post assumes you already know how to use vim a little bit.

Wow this took a while to figure out. So, in case you aren’t aware, there is a way to have multiple tabs open in vim. If you have vim open, just type


:tabnew new_file_name

And a new tab will open up with that file in it.

If you don’t have vim open already and want to open a bunch of tabs at once just type:


vim -p filename1 filename2 filename3 filename4

And all your files will open at once in tabs.

To navigate between tabs you can either type ctrl-pageup and ctrl-pagedown or :tabp and :tabn.

I really don’t like the latter. I don’t want to have to constantly type crap every time I want to go to a different tab, and I don’t have the pageup and pagedown keys on my shiny new mac. So I wanted to map the left and right keys to tab navigation.

Here’s how you do it. Type the following in your terminal:


vim ~/.vimrc

This should open up a special file that vim uses to load settings before it launches. Somewhere in there type:

map <Left> :tabprevious<CR>
map <Right> :tabnext<CR>

You can look into mapping it to other keys (besides left and right) here.

Python elif

In the last post we talked about the amazing wonderments to be had by letting your programs do the decision making with if-else blocks! But wait! There’s more!! (You really can tell there’s more since I’ve added extra exclamation points!!!)

What if you, yes you, have more than one condition you want to test? After all, some user of this program might try to fool it by using a fake name other than “zoosmell pooplord”!!!!

print "What's your name?"
name = raw_input()
if name == "zoosmell pooplord":
    print "You're not fooling anybody you know."
else:
    print "Hello " + name + "!"

Then, my friend, my dear dear friend, I ask you, where will you be?

What's your name?
Zaphod Beeblebrox
Hello Zaphod Beeblebrox!

I really don’t think the user is a two-headed alien my friend, I really don’t.

elif to the rescue!!!

print "What's your name?"
name = raw_input()
if name == "zoosmell pooplord":
    print "You're not fooling anybody you know."
elif name == "Zaphod Beeblebrox":
    print "I don't really think you're from Betelgeuse."
else:
    print "Hello " + name + "!"

Let’s run that sucker!

What's your name?
Zaphod Beeblebrox
I don't really think you're from Betelgeuse.

Again!

What's your name?
zoosmell pooplord
You're not fooling anybody you know.

And again!

What's your name?
Mr. Potato Head
Hello Mr. Potato Head!

Ummmm….. Ok, let’s add that too!

print "What's your name?"
name = raw_input()
if name == "zoosmell pooplord":
    print "You're not fooling anybody you know."
elif name == "Zaphod Beeblebrox":
    print "I don't really think you're from Betelgeuse."
elif name == "Mr. Potato Head":
    print "I swear, people are so dishonest."
else:
    print "Hello " + name + "!"

Now, finally, we’re covered!

What's your name?
Mr. Potato Head
I swear, people are so dishonest.

Let’s test it again, after all, you should always test your code. :)

What's your name?
Batman
Hello Batman!

…..

There’s no winning is there?

…..

People will just…. lie to you! Everyone is a liar!

LIARS!

With School Assignments There Is A Time To Move on

I’m sure I’ve made mention of the doom spiral I tend to get myself into. I’ll be late in turning in an assignment, but because instructor’s can be cool, they will often give me extra time to get it done. The consequences of this is that I get a late start of the next assignment, which probably means I’ll be late turning that one in, and so on…

Recently I was firmly in the doom spiral and asked in the class’s web forum if I should turn in the assignment when it was due, even though it wasn’t working. (It worked after a fashion but has serious problems.) I got no replies to that question (one student offered to help me with the assignment, but offered no advice on when it was smart to give up.)

It was absolutely the smartest thing I could have done at that moment. I was pleasantly surprised that the incomplete assignment received a C (despite being turned in slightly late and receiving a penalty for it, I’ll remember to turn it in exactly on time next time) and I was able to start early and give more attention to the next assignment, which got an A.

Comparisonitus

I’ve made mention of The Self Publishing Podcast once or twice in this blog. They turned me onto another podcast, The Creative Penn, hosted by indie and traditional author, Joanna Penn. Joanna interviews a whole host of people associated with traditional and indie publishing and more.

One of the things she often mentions (and, to be fair, so do the SPP crew) is comparisonitus, the constant comparison of where you are in your life and career with where other people are. She’s quick to point out that this kind of thinking is in no way helpful to you in achieving your goals.

To paraphrase SPP’s Sean Platt, focus on iterative improvement. Make this week more productive than last week. Try new things and allow yourself to fail.

Be inspired by others by all means, but beating yourself up because you are not achieving what others are achieving is worse than useless; it’s actively counterproductive. You need to go your own path and measure yourself against yourself.

HTML page breaks for wkhtmltopdf

In an earlier post I mentioned how I’ve been writing school reports (the one’s that are allowed or required to be pdfs at least) in html and using wkhtmltopdf to turn them into pdfs. Well, if you’re following in my footsteps, here’s a little thing I found useful that you might also make use of.

You might notice that pages are broken a bit arbitrarily. So much so that a single line of text might have it’s top half appear on the bottom of a page and its bottom half at the top of the next. Thankfully there is a way to manually add page breaks to html.

The above article recomends two ways. I found that using a paragraph block gave me the best results:

<p style="page-break-after:always;"></p>

This doesn’t work so well with tables, but breaking one table into two provides an easy fix for that.

Python if-else

Last time we introduced if statements. Which allowed us to write programs like this:

print "What's your name?"
name = raw_input()
print "Hello " + name + "!" 
if name == "zoosmell pooplord":
    print "Hey wait a minute! That's not your name is it?!"

Which can give output like this:

What's your name?
zoosmell pooplord
Hello zoosmell pooplord!
Hey wait a minute! That's not your name is it?!

Or this:

What's your name?
Steve
Hello Steve!

So, wait. Why does our program say hello to zoosmell at all? Shouldn’t it see the ruse right away? Let’s fix that right now

print "What's your name?"
name = raw_input()
if name == "zoosmell pooplord":
    print "You're not fooling anybody you know."
else:
    print "Hello " + name + "!" 

Save that thing as greeting2.py and run it by typing python greeting2.py.

What's your name?
zoosmell pooplord
You're not fooling anybody you know.

What's your name?
Steve
Hello Steve!

From the last post you’ll remember that an if statement tests for a condition (in our case whether or not the name equals “zoosmell pooplord”) and if that condition is true, it executes indented code underneath it. With an if-else block we can cover all cases. If the condtion is true, then the indented code underneath the if statement is executed. If the condition is not true, then the indented code underneath the else block is executed.

Also, and this is important, don’t forget to put colons at the end of your if and else statements or they won’t work!

Python if statements

In the last post we talked about Python strings and string concatenation. We even saw how we can get user input and use it in our program. But the use was very limited. If we want to do more we need to tell our programs how to make decisions. For that we need if statements.

Let’s have a look at the greeting program from last time:

print "What's your name?"
name = raw_input()
print "Hello " + name + "!" 

The first line simply prints a string, the second line gets user input, and the last line prints a concatenated string. That’s all fine and dandy but the program is still kinda dumb, I mean you could say your name was “zoosmell pooplord” and the computer wouldn’t know the difference.

What's your name?
zoosmell pooplord
Hello zoosmell pooplord!

Let’s make a little addition

print "What's your name?"
name = raw_input()
print "Hello " + name + "!" 
if name == "zoosmell pooplord":
    print "Hey wait a minute! That's not your name is it?!"

Now let’s try it again:

What's your name?
zoosmell pooplord
Hello zoosmell pooplord!
Hey wait a minute! That's not your name is it?!

Buh-wuh-buh? The computer is not fooled by my ruse? Maybe I should try being honest with the computer, at least for now…

What's your name?
Steve
Hello Steve!

I’m not sure I’m comfortable with the computer knowing so much about me….

Ok, let’s break this down. What’s going on with these last two lines?

if name == "zoosmell pooplord":
    print "Hey wait a minute! That's not your name is it?!"

The way if statements work is that they first test for a condition and then, if the condition is true, execute all the indented code underneath them. Python is a bit unique in that it uses indentation to determine what’s underneath an if statement. When you study other languages, you’ll find that they use other ways, but the bottom line is always this: if statements test for a condition, if the condition is true then the code within the if statement is executed. If the condition is not true then the condition is not executed..

In our case the condition is name == “zoosmell pooplord”. That double equals inbetween name and “zoosmell pooplord” is what’s called a comparison operator. We’ll talk more about them in later posts, but this one, the double equals, is checking if the thing on it’s left is equal to the thing on it’s right. If name is equal to “zoosmell pooplord” then the program prints our indignant message. If name is not equal to “zoosmell pooplord” then the indented code is not executed.

Also, and this is important, don’t forget to put a colon at the end of your if statements or they won’t work!

Follow

Get every new post delivered to your Inbox.

Join 194 other followers