Diario - page 3

Por favor, dejad ya de usar fotos de stock de pantallas de ordenador con código PHP sacado de algún plugin de WordPress para ilustrar artículos sobre cosas que no tienen que ver con WordPress. 👏

Sobre git merge-base

Con el comando git merge-base puedes obtener el hash del commit más reciente que es común a las ramas que le digas. Esto viene bien si brancheas una rama upstream (pongamos master o develop) y luego quieres ver en qué commit hiciste el git checkout -b (por ejemplo, como parte de un rebase que estés haciendo). Esto es válido incluso cuando ha habido commits en la rama upstream después de que creaste la rama (que suele ser el caso).

Pongamos un repo en el siguiente estado:

A --- B --- C      master
        \-- D      feature/x

Entonces se cumple que:

git merge-base master feature/x
[hash del commit B]

If you’re working on a Git repository and your team makes exhaustive use of branches, every time you run git fetch, Git will download new commits on those remote branches, even if you don’t plan on having local branches tracking their remote pair. Once those branches are removed by your teammates in your remote repositories, git fetch won’t download new commits for those branches, but it won’t notify you that the branch has been removed either.

If you want to remove remote branches in your local repository that have been already removed from the remote repository, you can run git fetch --prune. This will download new commits from existing or new branches, but also if a branch has been removed from the remote repository, you’ll have that branch removed from your local copy as well.

If you don’t want to forget about prune, you can also configure your Git repository to automatically prune removed branches by running git config remote.origin.prune true. Replace origin with the name of the remote repository you have the setting to have effect on. Every time you run git fetch on that remote, deleted branches will get removed too.

I made a pre-commit hook that forbids committing directly to master or devel branches on Git. This is something that you don’t want to do if you find yourself working under some Git model such as GitFlow or GitHubFlow. Specially if you are using GitFlow. Specially if you are not alone in your project.

Yes, I know that you can fix this after you make the commit by creating a new branch and then moving back the branch pointer for devel or master a few commits back, but I would waste less time if Git actually forbid me to make the commit in first place.


BRANCH=$(git rev-parse --abbrev-ref HEAD)

BOLD=$(tput bold)
YELLOW=$(tput setaf 3)
GRAY=$(tput setaf 8)
RESET=$(tput sgr0)

for branch in $FORBIDDEN_BRANCHES; do
 if [ "$branch" == "$BRANCH"  ]; then
  echo "${BOLD}You are currently in branch ${YELLOW}$BRANCH${RESET}."
  echo "    Committing from this branch would be a bad idea."
  echo "    Would you mind... changing to a different branch first?"
  echo "${GRAY}(Or you know, using the -n flag to bypass this message."
  echo " Hey, don't look at me! I'm a script, not a police officer!)"
  echo $RESET
  exit 1

You can also download the hook as a shell script. I don’t mind. It wouldn’t be that long if I didn’t declare all these variables but, hey, colors!

The hook in action
The hook in action. Note that I can still force the commit if I need or want to by using `git commit -n` (read the docs).

Sometimes I wish we had something like SSHFS but for executable files.

Yes, I’m aware of the ssh [hostname] [command] syntax. But, just like when you mount a remote file system using something like SSHFS or DAVFS, your local applications can interact with that remote directory without them ever noticing files are not actually in your computer (aside from the network latency), I just wish the same could be done with executable files.

You run (or another application runs) ./hello, and that gets translated into ssh foo@ /usr/bin/hello. stdin is piped to the remote server, stdout is piped from the remote server. It doesn’t matter if you are on a Mac and /usr/bin/hello is a Linux ELF binary file, because the file is actually executed on a remote server. A use case for this would be being able to run remote debuggers without having to rely on fancy IDEs that support this feature, such as debugging a remote Node.js or Python script in a server or in a Vagrant box.

I guess the people behind Plan 9 actually had their point.

TIL: Jekyll’s incremental builds do not trigger rebuilds of pages that make use of the site.posts variable, which means that, if you have a page that lists recent posts using site.posts, and you update a post, the page won’t be regenerated. This can be fixed by adding regenerate: true to those pages that you want to always be regenerated on each incremental rebuild.

I make use of incremental builds to speed up the compilation time of my site in development mode, but I also have a lot of feed pages on my site, and it always drove me bonkers that my feed pages were not being regenerated, because apparently I didn’t see this footprint.

FTR, Telegram is not the proper alternative to WhatsApp or FB Messenger if you’re looking for something “open”. Just because the client is open source doesn’t make the cut, if the server is closed source, and I don’t understand why people don’t get this.

Signal may be a better alternative since the server code is open source, although it’s not easy to rollout your own server because the official client has the central server address hardcoded and you’d have to fork the client as well.

Another alternative is XMPP, although it doesn’t have a lot of traction, specially considering how modern chatty stuff such as ‘last online at’ or ‘read receipts’ depend on XEP extensions that have to be implemented by both the server and the client. Despite that, running an XMPP server nowadays is as easy as installing ejabberd, keeping sensible defaults such as making logins private, and using your Let’s Encrypt SSL certificate (yes it can be used!).

I’ve finally processed a dump of my Instagram feed and uploaded it here. Photos are stored in my Minio instance and they are implemented as photo notes. Then I’ve disabled my Instagram account for the time being. Next goal: Flickr photos, and Twitter photos.

There may be a few imported photos that may be so recent they may be present in my public global feed. Sorry, RSS readers. By the way, there is a photo feed now (RSS version) which only displays recent photos.

I’m reaching the threshold barrier where there are so many posts that Jekyll has a hard time compiling this stuff.

La cosa que estoy preparando:

Preparando una cosa.