Automating the New Blog

After many years of service, I decided to retire my old blog made with [Blogger do Google]. My experience with static site generators has always been very good, since the early static site generators that I wrote even in the 90s, some in Object Pascal (Delphi), others even in Perl! In recent years, I had the pleasure of creating the website for the first [PyCon Amazônia], using [Pelican] and before that, I was already working on a new version of the generator for my [book site]. But I wanted a new blog and something quick, after some research, I decided to try [Hugo], written in [Go] and ultra fast. I found it very simple, easy to install and multi-platform. The new site, hosted on [https://blog.nilo.pro.br] was created by converting the Blogger posts. I also took advantage of porting the infrastructure to AWS, since the cost is very low.

Read more

Migrating the chat server to Python 3.6

When Python 3.4 was released, I was so happy with the Asyncio integration that I wrote a chat server here.

Time passed and new versions of Python were released. So I decided to migrate the server to Python 3.6.

One of the big changes that occurred in Python 3.5 was support for async and await to replace @asyncio.coroutine and yield from respectively. This small change alone makes the code much easier to read, which has become lighter. But one of the main changes in Python 3.6 are f-strings that make it easy to form messages.

Read more

Consultations via Telegram

It would be nice if IT professionals could give consultations like doctors or lawyers, but something prevents us from charging for everything and this desire to share ideas consumes us.

I participate in several Telegram groups, mainly about Python, one of which is the PyCoding group and the other is the pybr. Normally I read the groups when I’m using my cell phone, so it’s not always possible to help with questions, but I’ll try to set aside a little time to explore some ideas here and there.

Read more

Using UUIDs as Primary Keys with Django and Postgres

By default, Django creates integer primary keys (32 bits) when used with PostgreSQL database. These fields are incremented automatically and work perfectly well in a local environment. A problem that appears when you create an API is the fact that sequential and numeric IDs expose details of your database.

Imagine your client has ID 1; they can imagine (and rightly so) that it’s their first client. The same can be used by competitors to know how many new clients you’ve obtained in a certain period, just by creating a new account. This may generate an uncontrollable desire in some people to explore the values of your keys.

Read more

Converting a Game Written in Basic to Python - Part III

In this third part, we have the following objectives:

  • Clean up the classes
  • Multiple planes
  • Multiple shots.
  • Generalize the game objects into a superclass
  • Display a score
  • Assign keys to shoot and play again or exit

In the version of Part II, the classes have a lot of repeated code. By analyzing each of them, we can reach a conclusion about a common behavior regarding how to draw and update the objects. A method to remove the object from the game is also used.

Read more

Converting a Basic Game to Python - Part II

In this second post, we’re going to improve our game.

Although the new version runs in Python, it still looks like an old 80s game. The first thing to fix is the animation. Since we’re using a 280 by 192 point coordinate system to simulate Apple coordinates, we multiply each coordinate by 4 when drawing. To make it look similar to the original Apple, I reduced the number of frames to 8 per second. That’s why the animation looks so jerky! To get it running at 60 frames, we need to multiply the velocities by the ratio between the old and new frame numbers: 8/60. The new version defines some constants for this:

Read more

Converting a Game Written in Basic to Python - Part I

The nostalgia of 80s computers is something I have never stopped feeling. As a child, I was fortunate to use several 8-bit computers, such as the ZX-81, ZX-Spectrum, Apple II, and MSX, or rather, their national clones (TK-85, TK-90X, TK2000), since Brazil was experiencing the era of the Informatics Market Reserve.

In a time when there was no Internet, we spent our time typing programs. A series of books on game programming was published by the Lutécia publishing house in Brazil, but the original American versions were released by Usborne.

Read more

Help Keep the Nokia Foundation Open

The Nokia Foundation is a secondary education institution, located in Manaus, Amazonas. Operating for 30 years in the region, the institution had several names like CEPI, FEPEMM, FMM and finally Nokia Foundation from 2001. With the sale of Nokia, the Nokia Foundation was maintained by Microsoft.

This year, for the first time in 30 years, the selection process of the institute has been suspended. If this situation continues, the Nokia Foundation will disappear in 3 years.

Read more

Server Chat with WebSockets and asyncio

It’s time to write about a more complete project. I’ll show you the websockets module for Python 3.4, which works very well with asyncio. To avoid interface problems, I decided to write the chat client in JavaScript. The example client was downloaded here. As usual, examples are very simple and leave us wanting more about what we could really do. Who has already tried writing a chat in JavaScript knows that WebSockets are a hand on the wheel.

Read more

Asyncio - Reading from the Keyboard

Continuing the series on Python 3.4’s asyncio module, we will see how to create a simple text-based game. The goal of the game is to display a maze and let the player move around using the numeric keypad (4 - left, 6 - right, 8 - up, 2 - down, and S for exit). To exercise our old DOS programming muscles with asynchronous programming, we will display the clock on the last line. The final result should look like this image:

Read more