tales of code

Happy birthday!

Happy birthday!

Calling bash to “fork”

I frequently open new terminals to execute a few quick commands, so I don’t have to change directories or anything else in my current working session.

I just realized I can just call bash, do whatever and then exit to return right to where I was, as I was.

Ha! Why did that never occur to me?

shplot and the Olympics

Some time ago I wrote shplot, a small tool to output bar charts as unicode text.

The Olympics weren’t everywhere at the time, but as they are now, why not a chart of the medals won by each country so far?

screenshot

Fun! I’m glad I wasted that time.

Stop trying to get rid of the keyboard

We used to communicate in gestures.

Gestures were good to refer to concrete stuff, but as communication became more abstract, gestures turned out to be a poor transport.

So we created language.

With language we could express ideas of incredible complexity, such as this very sentence you are reading. I dare you to say that in signs.

Language was such a good idea, that things worth saying became things worth writing, and eventually portable, personal means for writing were invented. Then writing was easy, but it had to be faster: the typewriter partially addressed that need, and finally the keyboard came along.

The fastest way of using the best tool for communication we ever created. The keyboard.

Smartphones, tablets, they are all fantastic devices, but we still use notebooks. Why? Simple: they have a keyboard. They enable us to express complex ideas quickly, using language.

I hope this gesture madness is just a passing trend.

Two Java design quirks

Here’s a question for you: why, given that in Java assignment evaluates, do standard setters return void?

loading source…

I know, right? Also:

loading source…

Oh well.

P vs NP: I finally understood why I care

What changes if, after so many years, someone finally proves what everyone seems to suspect: P != NP? Why is it important? What does the question tell me? Some problems are harder than others? No shit. Really?

Well, what makes a problem hard? Is it hard for you? Hard for me? Hard for the average human?

Those are entirely different criteria, for almost any interpretation of you, me and average human. Or are they? Well, it depends. Here’s the key question:

Do problems have intrinsic difficulty, or is difficulty dependent on the approach?

In other words — is P != NP?

I’m never using Points again

Did you ever have to face the somewhat embarrassing task of merging x-y coordinates with row-col coordinates code? Did you hate humanity and yourself?

I did. Twice.

It was nobody’s fault, really. It’s actually Point's fault. For the mathematically inclined, Point(x, y) means x-horizontal-y-vertical-from-lower-left, while in the world of matrices, that’s x-vertical-y-horizontal-from-top-left.

I take a vow, here and now, and the Internet can bare witness: I will never, ever use the name Point again, and favor rc and xy instead. No confusion possible.

6 steps to learn anything

I meet more and more people that seem to think intellect works somewhat like this:

  1. Ignorance
  2. Eureka!
  3. Comprehension

Well, here’s the deal. It’s more like this:

  1. Ignore it
  2. Think it may be
  3. Be convinced it is
  4. Question it
  5. Realize it is not.
  6. Repeat

Now, the meaning of this relevation is twofold:

  1. If you don’t understand something, it’s not because you just simply can’t, or because it’s hard stuff— it’s because you are being lazy. There is no trick to it, no magic. Rinse and repeat. Great thinkers are quick, trained repeaters.

  2. You can never understand it fully. Embrace that. It also means you can always understand it better.

So I don’t want to hear any more of this I can’t get it or this is out of my reach nonsense. It is out of my reach too, I’m just working hard to get closer.

Piping to and from the clipboard

Did you know that using xclip (xwhat?), you can pipe from your command line to the X clipboard, and back? I have an alias for it in my bashrc:

alias xc="xclip -selection clipboard"

To produce that line, I could’ve opened a terminal and typed…

~$ cat .bashrc | grep xclip | xc

… then pasted here. I admit I didn’t, though, the grep occurred to me as I wrote this. I manually deleted the rest of the text when I pasted it =D.

Speaking about grep, you can copy something from, say, your web browser, and use it as search pattern. To retrieve the contents of the clipboard, xc -o will do the trick:

~$ cat some_file | grep `xc -o` 

It’s very handy! Give it a try. I promise the more you get used to it, the more you’ll love it.

A cookie for zeroing, who posted this. Thanks for the laugh!

A cookie for zeroing, who posted this. Thanks for the laugh!