Dynamic fields with Flask-WTF

02 Mar 2019

Lately I've been working on a side project that requires dynamically adding or removing fields to a form: ideally, I should be able to add any number of fields and the server should receive the data correctly.

While a combination of FieldList and FormField works great when adding fields in the backend, I wanted to dynamically add and remove fields in the client (through Javascript) without having send requests to the server until finally submitting the form with all the dynamic fields. Here's how that went.

TL;DR: Example code is available at https://gist.github.com/rmed/def5069419134e9da0713797ccc2cb29.

Tags: flask wtforms dynamic fields javascript

Using RPi Zero as a Keyboard Part 3: Sending and receiving reports

13 Jul 2017

In this third and last part of the series we will use the new keyboard to send keystrokes to the connected computer. To do this, I will provide a couple of examples using Bash and Python, although they can be easily translated to other languages.

Tags: keyboard input zero report keys descriptor linux rpi hid raspberry pi pi output

Using RPi Zero as a Keyboard Part 2: Report descriptor

05 Jul 2017

In this second part of the series we'll see the structure of HID report descriptors and how to apply them to the virtual keyboard. When done, the gadget will be completely configured and ready to use.

Tags: keyboard zero report descriptor linux rpi raspberry pi hid pi hidrd

Using RPi Zero as a Keyboard Part 1: Setup and device definition

26 Jun 2017

The Raspberry Pi Zero is a cool little piece of hardware with many possibilities. One of them is that it can work as a USB host OR as a USB gadget, meaning that it is possible to implement different types of devices such as ethernet, HID (keyboard, mouse, gamepad, etc.), audio, mass storage, etc. In this 3-part series of post we'll see how to configure and use a simple and generic keyboard gadget to send keys to the connected host.

In this part I'll go over the process of defining the gadget, breaking down what each different configuration files is used for and giving example values.

Tags: keyboard gadget zero configfs linux rpi hid raspberry pi pi

Bridge? wat-bridge?

13 Oct 2016

Instant messaging services are very common nowadays. For instance, I use Telegram, while many people I know use WhatsApp, and that's cool. This, however, leads to a question I am asked often: "why don't you install WhatsApp?". The answer to that can be summarized in two main points: "because I don't want to" and "because I cannot install WhatsApp on my phone". But then again, it is interesting to see the user fragmentation between different services, so the Telegram bot API got me thinking about creating a "bridge" between WhatsApp and Telegram, just for fun.

TL;DR: source code available at https://github.com/rmed/wat-bridge

Tags: network bot messages whatsapp messaging telegram instant

Using Selenium to parse a timetable

27 Sep 2016

The University of Greenwich portal offers a link to view your own timetable for any week or term. Even though it is useful, it would have been even more useful if it had a way of downloading the full timetable as an iCalendar file to import in calendar applications such as Google Calendar (other apps are available). I like being able to quickly access my calendar from my phone, but I am too lazy to copy the timetable to a piece of paper (which is what a friend suggested), therefore I wanted to try implementing a script to automatically convert the timetable to a .ics file.

Tags: parse university python spider scrapy web greenwich selenium script

Using acme.sh with nginx

10 Aug 2016

acme.sh is a script utility for the ACME spec used by Let's Encrypt. It is pretty simple and has no requirements, so I wanted to try using that in the server to issue and renew certificates rather than doing the process in my local machine and then copying the required files. It supports several modes for issuing the certificates, such as the Apache mode which I have used before, although there is no specific mode for nginx, so it is not possible to have completely automatic configuration if you use that server.

After installation we are now able to issue certificates, but there is a single problem: how should the challenge be solved? While it would be possible to stop nginx and have a local web server run on port 80, this might not be a good practice for production server. In my case, I cannot use another port (say, port 88) because that would require modifying some firewall rules, and that's kind of a bummer :)

So what are we going to do? Simple: use the webroot method and configure nginx to serve the challenges so that applications don't actually care about the challenge endpoint.

Tags: acme ssl secure server web nginx let's encrypt https

Migration system for Zoe microservices

03 Aug 2016

This is the title of my Bachelor Thesis, which focused on the development of an addition to the Zoe virtual assistant that enabled live migration of Zoe agents during runtime. Rather than modifying the original system or employing solutions such as virtualization or containers, which may have been a little too overkill for this scenario, I designed and implemented a software-based solution with the help of my supervisor, Professor David ExpĆ³sito from UC3M.

Tags: document bachelor python academic thesis zoe gul

Wrapper for EMT Madrid API

28 May 2016

EMT Madrid, (the organization that operates the buses in Madrid), offers a public API with information such as waiting times, stop locations, etc.

I used this API some time ago to develop the madtrans Zoe agent: I performed the requests manually and parsed the data accordingly, although I only implemented some of the endpoints offered by the API. After a while I thought about creating a wrapper for the API in order to use it to improve the agent.

With the documentation available, I started developing the wrapper. I am not ashamed to admit that this development lasted less than a week: I got somewhat frustrated with some particular things of the API and put the project aside. Some weeks ago, however, I decided to continue developing the wrapper because of another project of which I will not talk about just yet.

The result is the pyemtmad wrapper for Python! It is definitely not perfect, but at least simplifies things greatly for me and kind of works. In order to use it, you just need credentials to access the API and instantiate a Wrapper as follows:

from pyemtmad import Wrapper

wrapper = Wrapper('MY_ID', 'MY_PASSWORD')

All the endpoints are then available through attributes of the wrapper object. Parameters and further details are available in the documentation.

Hope it is useful for someone!

Tags: api emt transport wrapper python

Fun with exact matching in Zoe

24 Mar 2016

I'm currently working on something related to Zoe that has some complex/dangerous operations. Given that it is an agent, I would like to communicate with it using Telegram or Jabber. Using natural language commands results in a comfortable communication for regular users. However, this has some drawbacks when dealing with sensitive stuff.

Tags: zoe match commands natural

1 2 3 4