Python Tips

Posted on Wednesday, Jul 01, 2020 in programming • Tagged with python, tips, lists, functools, itertools, timezone

A collection of small Python scripts and tips.

This post is based on a Twitter thread I started in April 2020 and works as a centralized way to read all the tips in an easier format than Twitter's 280 characters.

Both will be updated frequently.

List Flatten without explicit loops

  • Using Itertools' chain
1
2
3
4
5
6
import itertools

test = [[-1, -2], [30, 40], [25, 35]]
list(itertools.chain.from_iterable(test))

>>  [-1, -2, 30, 40, 25, 35]
1
2
3
4
test =  [[-1, -2], [30, 40], [25, 35]]
map(int, ''.join(c for c in test.__str__() if c not in '[]').split(',') )

>> [-1, -2, 30, 40, 25, 35]

Not pretty in my opinion ;)

Count individual items of any iterable

1
2
3
4
5
6
7
8
from collections import Counter
count = Counter(['a', 'b', 'c', 'a', 'a', 'b', 'd'])

print(count)
>> Counter({'a': 3, 'b': 2, 'c': 1, 'd': 1})

count['a']
>> 3

Repeat a series of values from any iterable

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import itertools as it

data = it.cycle([1, 2])

for i in range(10):
    print(next(data))

>> 1
2
1
2
1
2
1
2
1
2

Name slices to reuse them

1
2
3
4
5
6
7
8
# slice(start, end, step)

STEPTWO = slice(None, None, 2)
integer_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

integer_list[STEPTWO]

>> [0, 2, 4, 6, 8]

This is the same as:

1
integer_list[::2]

Reverse any "indexable" collection that supports slices

1
2
3
4
5
6
# slice(None, None, -1) or [::-1]

integer_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
integer_list[::-1]

>> [9, 8, 7, 6, 5 …

Continue reading

Recruiting Tips for Recruiters

Posted on Wednesday, May 13, 2020 in eng-mgmt • Tagged with personal, software, engineering, recruiting, tips, hiring, management, sourcing

Since I started my professional life, several years ago, I've dealt with technical recruiters, that's great, right? I'm able to improve my quality of life, grow in a career path, and pursue interesting projects.

Unfortunately, my day to day experience with recruiters is not always great, usually, it takes a lot of time to filter interesting offers from less interesting ones. Based on my experience, I'll try and give a few hints on what makes the recruiting/sourcing process more enjoyable for engineers, engineering managers, product managers, and UX specialists, and hopefully with better results for recruiters.

Instead of ranting about a specific situation on Twitter, I thought it might be useful to describe what "good recruiting" looks like for me.

Let's start:

  1. Do your homework: most engineers and engineering managers I know maintain some kind of blog, Github profile, or LinkedIn profile. Some engineers give talks at local Meetups. They have invested a lot of time publicly sharing some of their work. It is nice to deal with recruiters that have taken their time reviewing that public information if recruiting is a numbers game, you'll drastically increase your chance of screening the right candidates if you do a little research beforehand. And... please, please, please, get the name right in your first contact you wouldn't believe me how many recruiters call me by another name...

  2. Be expressive with the job description: No, I'm not interested in a position I know nothing about, giving out my number to "know more", is not practical to anyone. Tell as much as you can about the position, the team, the kind of projects. The more information a possible candidate knows about the position the more interested (or not) they can be about continue the selection process. You want a software engineer to work …


Continue reading

[Debian] Changing Docker's default /var/lib/docker directory

Posted on Tuesday, Sep 10, 2019 in programming • Tagged with debian, docker, directory, systemd

By default, Docker storage its files in the /var/lib/docker directory in the file system. If, like me, you're running out of disk space in the default file system, you can quickly change the default directory. This are the steps I followed in Debian 10, it should work with any distro that uses systemd

As superuser, modify the systemd docker startup script. Edit the file /lib/systemd/system/docker.service replacing the ExecStart command:

1
$ sudo vim /var/systemd/system/docker.service

Change the line:

1
ExecStart=/usr/bin/docker daemon -H fd://

to

1
ExecStart=/usr/bin/docker daemon -g /new/path -H fd://

then stop the service, and be sure that the daemon is completely stopped:

1
2
$ sudo systemctl stop docker
$ ps -aux | grep -i docker

The only output should be the one from grep. Then you can reload the system and -optionally- synchronize your current docker data to the new directory

1
2
3
$ sudo systemctl daemon-reload
$ sudo mkdir /new/path
$ sudo rsync -aqxP /var/lib/docker /new/path

Your docker installation should be running in the new data directory:

1
$ ps -aux | grep -i docker

That's it.


A Quick Guide to Install Spotify in Debian 9.0

Posted on Wednesday, Jul 05, 2017 in personal • Tagged with personal, spotify, debian, music, install, apt

A quick guide of the steps I took to install Spotify version 1.0 in Debian 9.0. First of all, the Spotify team doesn't (officially) support the Linux version, so even if they claim to be compatible with de lastest version of Ubuntu's LTS, it tends to fall behind with the dependencies.

With a fresh install of Debian, you'll need dirmngr installed before adding the Spotify repository to your apt list:

1
$ sudo apt install dirmngr

After dirmngr installation, you'll need to add the Spotify keys and repositories (just check the instructions in the Spotify for Linux website):

1
2
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886
$ echo deb http://repository.spotify.com stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list

If you follow the instructions at Spotify's website, the installation should be ready with the update and install commands from apt:

1
$ sudo apt update && sudo apt install spotify-client

But is a common case that not all the dependencies are up to date between Spotify and Debian, so you'll need to add them "by hand".

1
2
3
4
5
6
The following packages have unmet dependencies:
 spotify-client : Depends: libssl1.0.0 but it is not installable
                                  Recommends: libavcodec54 but it is not installable or
                                                          libavcodec-extra-54 but it is not installable
                                  Recommends: libavformat54 but it is not installable
E: Unable to correct problems, you have held broken packages.

First you'll have to download the exact same version of the package that Spotify needs, in my case it was libssl1.0.0, I downloaded it from: https://packages.debian.org/jessie/libssl1.0.0.

Then just install it with apt and try re-installing Spotify:

1
2
3
$ wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0 …

Continue reading

A Farewell to a Great Company

Posted on Tuesday, Nov 08, 2016 in personal • Tagged with personal, work, posma, posma group, career

This month marks my final month as a CTO/Lead at Posma Group. It's been six years of ups and downs, working in varied and interesting projects, but most of all, working with amazing people, both coworkers and clients. In six years, we went from just the 3 cofounders to a team of 20+ between two offices, working in lots of different projects.

Thanks to all the people who helped me grow and learn along the way. It was a great experience in so many ways.

I wish all the luck to Jorge and Oscar in their aim to keep growing the company and the great team of Posma Group. I'm sure we'll work together in some project, sometime in the future!

Now, let's see what comes next!

Posma Group 2016