Matrix operators as stack languages

On the last post we explored how some program written on APL can be translated to Futhark.

Both Futhark and APL can be considered array programming languages.

A difference between them is that APL can express inner or outer operations when handling a multidimensional array, meaning that having an array 3×3×5×7 we can sum the values when only the first dimension is different, converting it into a 3×5×7 matrix (see the operation demonstrated here). By the way, the sizes come from the example on last post and don't have any special meaning.

Writing the game of life in Futhark

Some time ago I found a found a video of someone implementing the Game of Life on APL (you should take a look at it, the rest of the post will make more sense afterwards). APL is famous for being both expressive and unreadable for the non initiated. For example this Game of Life can be expressed as (code from dyalog.com):

life{                                  ⍝ John Conway's "Game of Life".
    1 .3 4=+/,¯1 0 1∘.¯1 0 1∘.⌽⊂  ⍝ Expression for next generation.
}

The video linked above is quite interesting as it explains what all that symbols mean.

Some time later I was fiddling with the Futhark programming language and found a blog post titled "Futhark as target language for an APL compiler". This made me realize that APL and Futhark operate over (mostly) the same base concepts, and that replicating the same process on Futhark will be a good way to get to learn the basic operations of the language.

As an side note that this Game of Life is already implemented as a benchmark sample program for Futhark, so if you're interested in a useful implementation you should probably consider that one ;)

What is Futhark?

Futhark website describes the language as a "High-performance purely functional data-parallel array programming on the GPU". You could think it's something like a Haskell (with no recursion) which compiles its programs to something that a GPU can run (or anything OpenCL-enabled).

How to write a simple AwesomeWM widget

Sometimes it's useful to be able to cook up a simple widget for you desktop environment. With AwesomeWM this is easy to do if you can handle some lua. Let's see how to write a simple one that shows us the internal temperature of the computer.

A simple widget

Note: Added code to avoid memory leak on watch blocks (call collectgarbage() at the end of the watch). See: related issue.

Writing a browser extension in typescript

Every once in a while I write some small web browser extension to do little things. You could, for example, write an extension for showing the ID's of elements in a web or replacing AI with "a bunch of dudes", and after firefox adopting WebExtensions as the way to write these plugins we can make it so the same code works with Firefox and Chrome!

While we're at it, let's see which extra steps we have to take to write these extensions on Typescript, after we have a running Javascript version.

So let's go ahead and write a simple extension which allows us show the ID's of elements on a web. This could be used, for example, to generate links which end with #id-of-element which when opened will make the browser scroll to that element. We won't go in depth, let's make it fast.

Extension popup

Clone this wiki

Wow, a post after almost two years!

I'm going to be brief to avoid taking hours to make a single post and going back to not writing.

First things first, I setup a wiki for personal references/notes it's not thought to have refined or complete content, just fast tips to solve situations I encountered. It might be handy, it might not, it's your decision.

I had a bit of fun making it as minimalistic as possible, and now it should run with only sh and a markdown to html compiler. All of this while being fully version-controlled by git. You can take a look at it on my gitea or on github. (Yep, content and "code" shares version control as there's really little code)

Ok, with that out of the way...

Lots of things happened lately, but in summary

Primer batch de tweetcodes (1 - 10)

Desde finales de enero estoy publicando un tweetcode al día en gnusocial (@oneliners), y en twitter (@twtcodes). El concepto viene de una idea que tuvo @hacklego para hackliza: un twitcode sería un pequeño codigo, de no más de 140 caracteres, que tenga alguna utilidad. Parte de la idea, era también dar una explicación de como funciona, así que ahora que va más de un mes de estos twitcodes, toca empezar a explicarlos. Veamos...

Setting the brightness in Awesome

Being able to change the luminosity of a screen is always something useful, to adjust it when there's more or less light, or even switching it off to keep a laptop processing. This usually works on it's own when we use an environment like KDE or Gnome, but it may not be like this if we don't use certain drivers or if we prefer more configurable environments (like awesome).

Subuser: un Docker para el escritorio

Hoy andaba trasteando con Docker e intentando hacer que corriera una aplicación de escritorio, algo que no se puede hacer sin salirse del flujo que se espera de esta herramienta.

Docker es una plataforma que permite gestionar “contenedores”, algo similar a las máquinas virtuales de toda la vida, pero sin la sobrecarga de tener que simular otro sistema completo con su kernel y sus cosillas... Estos contenedores encontraron un entorno perfecto en los servidores, donde permiten montar más VPS, o donde permiten que cada micro-servicio corra de forma aislada sin necesidad de varias máquinas.

Sin embargo estos sistemas no estan orientados a las máquinas de “escritorio”, y se portan especialmente mal con X11. Esto es así poque para que un programa funcione sobre X11 sería necesario levantar un socket desde el anfitrion, es decir, desde fuera del contenedor, algo que no se puede automatizar a través de estas herramientas (aunque si con un shell script). Otra solución es levantar un servidor VNC dentro del contenedor, pero podemos intuir que el rendimiento es “limitado” :P.

Pues bien, hay un proyecto que pretende solventar este problema, este es Subuser. Podríamos decir, y ellos lo hacen, que Subuser es un Qubes OS ligero, simplemente da una capa de abstracción sobre Docker para permitir que aplicaciones de escritorio funcionen de forma transparente (o casi). Para ello implementaron un puente para la interfaz gráfica, y un sistema de gestión de permisos.

TensorFlow in Python3

TensorFlow is an Open Source library that Google has released earlier this month. It allows to, in a simple manner, arrange processing and training flows, with elements like neural networks, and even implement new operations over it's architecture (tutorial and examples).

This library is written in C++, but the architecture, the data to be managed and the operations are declared in Python. This is great, as it yields a great performance without having to deal with Segmentation Faults, but if you were expecting to use Python3 for this... you may have to wait a while, at this moment it's not supported [tensorflow GitHub issue #1], but it's support is planned.

Meanwhile, in this repo, in the python3 branch, you have a way to use it... it's not completely updated and there's things to tune, like checkpoints. Also, you'd have to build it manually (there's no prebuild pip package), but we'll see that can be done easily.

El Julia set en un shader

Desde que empezó el tema de los smartphone, siempre sonó interesante la idea de programar desde el propio cacharro. Si bien ya se podía desde (casi?) el principio con SL4A, nunca fué algo demasiado cómodo.

Pues bien, resulta que en F-Droid (market de aplicaciones libres) tienen un entorno que permite programar Shaders en GLSL, programas que permiten generar gráficos desde la GPU, e incluso utilizarlos como fondo de pantalla, Shader Editor.

El programilla es bastante sencillo, y parece un buen método para aprender a hacer shaders, sabiendo por ejemplo C, y a partir de los ejemplos que incluye.

Pues bien, ahí va algo programado cacharreando con esto en el tren, dibuja el conjunto de Julia, moviendose en un par de dimensiones para que quede algo dinámico.

Newer posts Older posts