fzf - fuzzy finder on stereoids

Every once in a while I find a new tool that boosts my productivity so much, that I don’t understand how I managed to work without it up to this point.

Today I want to introduce you to a general-purpose command-line fuzzy finder, called fzf -

  • No dependencies.
  • Blazingly fast.
  • Works out of the box, but also extremely configurable.
  • Flexible layout using tmux panes.
  • Batteries included:
    • vim & neovim plugin - I see it as ctrlp.vim on steroids.
    • Key bindings (bash, zsh & fish)
      • CTRL-T paste the selected files and directories onto the command line.
      • CTRL-R paste the selected command from history onto the command line.
      • ALT-C cd into the selected directory.
    • Fuzzy auto-completion for bash, zsh & fish.

But hey, why listen to me when you can just see it in action?

Can you spot the bug?

Take a look at the following snippet:

def foo(flag):
return "hello", "world" if flag else "friend"

Now, here are two possible evaluations. which one is correct?

> foo(True)
("hello", "world")

> foo(False)
"friend"
> foo(True)
("hello", "world")

> foo(False)
("hello", "friend")

In python the "hello", "world" statement is implicitly evaluated as a tuple, which causes the confusion. foo‘s statement can be interpreted in two different ways:

# option A
("hello", "world") if flag else "friend"
# option B
"hello", ("world" if flag else "friend")

So which one is correct? Option B -

> foo(True)
("hello", "world")

> foo(False)
("hello", "friend")

Takeaways?
Explicit is better than implicit , and of course:

My humble direnv .envrc

This one is dedicated to all the lazy productivity enthusiasts out there. First, If you haven’t read my direanv blog post go ahead and read it.

.envrc is the dotfile that direnv uses to to do its magic. I usually split my .envrc into two parts:

.envrc

A script that is tailored to the project at hand:

source_env .pyenv
export NAME=odedlaz

I put all my exports there.

.pyenv

A script that bootstraps anything my python app needs:

layout python python3
if [ ! -f ".direnv/direnv.lock" ]; then

for req in requirements requirements-test; do
if [ -f $req.txt ]; then
echo "direnv: installing project $req"
pip install -r $req.txt 1> /dev/null
fi
done

for package in ipython bumpversion; do
echo "direnv: installing $package"
pip install --upgrade $package 1> /dev/null
done

date +%FT%TZ > .direnv/direnv.lock
fi

Did you see what I did there? If a user has direnv installed, all the needed project requirements are installed once he enters the projects directory.

I’ve also added a lock file to make sure direnv doesn’t perform unneeded, lengthy, installations every time a user enters the directory. If you want to update the requirements, you just need to run

rm -f .direnv/direnv.lock && direnv reload

The ideal solution would be to create a custom alias, but aliases aren’t supported at the moment.

####security model
If you’re worried of unwanted loading of unvetted .envrc files, look at the following screencast:

explainshell - visualizing commands

I find myself, every now and then, staring at a really long command, trying to figure it out. Here’s a good example:

ssh user@remote "tar czpf - /path/on/remote" | tar xzpf - -C /path/on/local

If you get the gist, but don’t remember all the knobs by heart, don’t worry. none of us do. that’s what man pages are for!

explainshell greatly simplifies things - It give you an easy, readable, visual representation of the command (click to open):

explainshell currently contains 29761 parsed manpages from sections 1 and 8 found in Ubuntu’s manpage repository. According to its author, Idan Kamara, A lot of heuristics were used to extract the arguments of each program, and there are errors here and there, especially in manpages that have a non-standard layout.

The project is available on GitHub and licensed under GNU GPLv3.

Regular Expressions

Regular Expressions are one of the most important tools in a programmer’s toolbox.
A regex master can achieve magical string manipulation with a few characters!

If you’ve never heard about regular expressions, now is time. RegexBuddy can help get you started.

Most languages that have a standard library, also have their own implementation of regular expressions. python has re, go has regexp, elixir has :re, rust has regex (which has go bindings too!) etc’.

Those Implementations are not the only ones though, there are numerous regex engines in the wild. I gathered the interesting ones for you in this blog post.

Read More

Poor mans daily blog backups

A few weeks ago I outlined the steps I took to migrate from WordPress.com to a self hosted ghost-powered blog on DigitalOcean.

One of the key highlights to self hosting is the ability to control everything.
That also means I need to configure everything by myself, including daily backups.

DigitalOcean provide a backup service for 20% of the droplet price. That’s only 2$ a month in my case.
But where’s the fun in that? I want to do that myself!

In this blog post I’ll show you how easy it is to backup your Ghost blog to Google Drive.

! Even if you don’t have a ghost blog, I really recommend reading this one, just to marvel the awesomeness of the Unix Philosophy.

Read More

A better way to handle multiline strings in python

I’m a PEP8 fanatic, which means my code always follows the style guidelines.
I’ve got both yapf and flake8 configured, and they can make my life a living hell if I try to fight them.

One of the guidelines that annoy me the most is the Maximum Line Length guideline.
I can follow it most of the time, but when I have a REALLY long string, I just can’t.

The following example violations the < 80 characters rule:

text = "We hereby declare the establishment of a Jewish state in Eretz-Israel, to be known as the State of Israel."
print(text)

A quick fix would be to break the text to multiple lines and add \.
Not the prettiest solution, but there’s no other way, right?

text = "We hereby declare the establishment " \
"of a Jewish state in Eretz-Israel, " \
"to be known as the State of Israel."
print(text)

I just found out that breaking the text and adding parenthesis has the same effect:

text = ("We hereby declare the establishment "
"of a Jewish state in Eretz-Israel, "
"to be known as the State of Israel.")
print(text)

Not life changing, and I’m a bit embarrassed that it took me five years to figure this out.
I believe some of you didn’t know that either, so I’m taking one for the team :)

Please, don't track me.

I recently gave a talk about the “Dark Web” at the Technion. A big portion of the talk was dedicated to privacy / anonymity, and the forces who try to break it. During the talk, I was asked if one can be tracked when using TOR.

TL;DR: fingerprintjs2 easily breaks TOR anonymity.

In this post I’ll explain a bit about fingerprinting and how fingerprintjs2 was able to fingerprint me behind TOR. I’ll also outline my own do’s and don’ts when surfing the web.

Read More