Posts tagged 'misc'

A Simple Problem

Let’s say that at your work, you have daily meetings every day at 10.

To avoid monotony, you’ve decided to signal the beginning of the meeting by playing a different song every time.

Let’s assume the following:

  • Your music collection is organized neatly, and all the file names look like <author> -<title>.mp3
  • The files can be found and downloaded easily from a web browser.

You’d like to:

  1. Make sure to never play the same song twice
  2. Be able to answer the question: “What was the song you played X days ago ?”
  3. Have a chronologically sorted list of songs, so that you can tell yourself: “Hum. It’s been two weeks I did not play anything from Pink Floyd, let’s use Another Brick In The Wall today”

Based on your experience, how many lines of code do you need to write to solve this problem?

Writing Clean Shell Scripts

I don’t enjoy writing such code that much.

It’s often used when all you want is automate a mundane task. “I’ll just copy/paste the commands I usually run, add a few ifs and fors and that will be enough”

Well, that’s how many shell scripts come to existence I guess, but nonetheless writing such scripts is not as easy as it sounds, and there are many pitfalls to avoid.

Here a few tips you may find useful.

Thoughts on Changelogs

Some time ago at work someone suggested we start using a template for our git commit messages, based on what the Angular project does.

The rules are documented in the page on github.

In a nutshell, here’s what the commit messages look like:

* feat($anchorScroll): convert numeric hash targets to string
* docs(ngCsp): fix "directive"'s `restrict` and hide comment from output
* refactor($resource): use `route.defaults` (already merged `provider.defaults` + `options`)

We decided to start using this too, and someone on the team said: “Great! That way we can use a script to generate changelogs!”

An npm Story

What happens when you use npm in a cross-platform environment?

Let’s find out in this short story, based on actual events…

Meaningful Variable Names and the Boy Scout Rule

Quick! What’s the bug fixed by this commit?

-def compare_links(a_html, b_html):
-    a_soup = bs4.BeautifulSoup(a_html, "lxml")
-    b_soup = bs4.BeautifulSoup(b_html, "lxml")
+def compare_links(local_html, remote_html):
+    local_soup = bs4.BeautifulSoup(local_html, "lxml")
+    remote_soup = bs4.BeautifulSoup(remote_html, "lxml")

-    a_links = set(a_soup.find_all("a"))
-    b_links = set(b_soup.find_all("a"))
+    local_links = set(local_soup.find_all("a"))
+    remote_links = set(remote_soup.find_all("a"))

-    old_hrefs = [x.attrs["href"] for x in a_links]
+    old_hrefs = [x.attrs["href"] for x in remote_links]

-    new_links = [x for x in a_links if x.attrs["href"] not in old_hrefs]
+    new_links = [x for x in local_links if x.attrs["href"] not in old_hrefs]

Not that obvious, right?

Please read on to find out how this bug could never had happened, and how this commit should never have been made.

Why I Don't Like Ruby

I’m going to compare two programming languages which is something really silly to do (or is it?)

You should know I’ve only used Ruby a few times: I followed a Rails tutorial once, and I also wrote a small web app with Sinatra in about 1500 lines of code. (nice framework, by the way)

On the other hand, I’ve been writing Python code for several years, on a project with about 25,000 lines of code.

But I could not resist the temptation, so here goes …

(there’s an other classic troll at the end too, because why not?)

A Nasty Mac Virus, or How I Learned To Love the App Store

Some time ago my little sister complained that her MacBook was getting slow, and had frequent freezes, to the point it was barely usable any more.

She also was seeing many ads when browsing, even though she had an ad blocker instead.

So I lend her my own laptop while I kept hers to investigate.

Here’s what happened next …

Why I Love Arch Linux

I’ve started using Linux in 2005 with Ubuntu.

After that, I’ve tried and use a few other distributions, such as Debian, Fedora, Gentoo, Frugalware for a few years until I found Arch Linux around 2008.

Since then I’ve sticked with Arch Linux. Here’s a post explaining why. (If you like it, there may be more posts on Arch Linux later …)

Parsing nginx Logs

This article is a comment on an article I read some time ago.

It’s called Get rid of syslog (or a journald log filter in ~100 lines of Python) and you can go read it here

It contains some advice about how to parse systemd logs, following the very good principles exposed in yet another blog post, called The Six Dumbest Ideas in Computer Security.