Hack to Learn

Fun with StackOverflow questions: finding answers while having no prior domain knowledge of the topics, with a little bit of detective work.

These are the questions I had the most fun answering on SO – hopefully I will find time to write a few words for each of them.

Set Directory Permissions CHMOD with JSCH

I had no idea what JSCH was. A quick Google search returns: “JSch is a pure Java implementation of SSH2”.

The question details a seemingly bizarre behavior, but I’ve used chmod before: maybe I can figure it out.

OP describes “775” as an integer. That clicked something. I recall that permission codes were not interpreted as decimal; but rather either hexadecimal or octal.

Converting 775 from decimal to hex yields 0x307. Close! But he’s getting 0x407 instead.

Let’s try octal: this time we get 0o1407. That’s not it either.

Hmm, 775, 407, 0x307, 0o1407. Eureka! It’s quite possible that JSch or Filezilla truncates any overflow for permission codes with value greater than 0o777, because there are only 3 permission groups: user, group, world (as it’s not unreasonable to assume there’s nothing past the 3rd least significant bit). So decimal 775 -> octal 0o1407 must have been truncated to octal 0o407.

I submitted the answer with an explanation of permission groups, and the decimal representation of 0o775, which is 509.

Answer accepted by OP =)

remove up to _ in perl using regex?

I had never seen Perl code until then, but then I thought, why not!

I read the question, scanned through some quick-start tutorials on Perl, grabbed what I remembered on regex, and answered with a working solution. All done, in less than 4 minutes.

Shell Script for Flip Canvas Vertical

I actually didn’t even realize this was doable in shell script, a few minutes of research taught me otherwise!

Very strange stringstream and std::getline behaviour

A question that more or less answered itself when I reviewed the documentation for stringstream.

Today’s date, minus X days in shell script

The requirements changed from “minus X days” to “minus X working days” after I answered the question, but I didn’t give up. Perseverance paid off!

Is there a better way to write this “if” boolean evaluation?

Python: how do I know if my list has all 1s?

Convert seconds to formatted time in shell

Elegant and efficient way to start GUI programs from terminal without spamming

How have both local and remote variable inside an SSH command

BASH – How to retrieve rows from a file from #SOF to #EOF

binary operator expected in win-bash

Sum of even integers from a to b in Python