miércoles, 19 de agosto de 2015

Kivy - variable Label

Lately I have been working with Kivy to produce some simple Apps. One of the things I needed was a Label which text could be changed by double clicking on it. I came up with this derived class that merges Label, TextInput and Popup.

from kivy.app import App

from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput

class variableLabel (Label):

def __init__(self, text):
super(variableLabel, self).__init__()
self.text  = text

def on_touch_down(self, touch):
if touch.is_double_tap and self.collide_point(*touch.pos):
_input = TextInput(text=self.text, multiline=False, auto_dismiss=False)
popup = Popup(title='Editing Label text', content=_input)
_input.bind (text=self.on_text)
_input.bind (on_text_validate=popup.dismiss)
popup.open()

def on_text (self, instance, value):
self.text = value

class MyApp(App):

def build(self):
return variableLabel("New")

if __name__ == '__main__':
MyApp().run()

Do you have suggestions for improvement?

viernes, 16 de enero de 2015

Binary numbers to fractions

The mapping from binary numbers to fractions described in this article can be written in GNU Octave as the function

bin2q = @(x) arrayfun (@str2num,x) (2.^-[1:length(x)].')

Giving the results that .0100... and .001111... map to 1/4

octave> bin2q ('0100000000000000000')
ans =  0.25000
octave> bin2q ('0011111111111111111')
ans =  0.25000

Números binarios a fracciones

El mapeo de números binario a fracciones, descriptoi en este artículo se puede definir como la siguiente función en GNU Octave

bin2q = @(x) arrayfun (@str2num,x) (2.^-[1:length(x)].')

Dando el resultado que .0100... y .001111... se mapean en 1/4

octave> bin2q ('0100000000000000000')
ans =  0.25000
octave> bin2q ('0011111111111111111')
ans =  0.25000

domingo, 14 de septiembre de 2014

Salteños visitarán Bélgica

Este post es derivado de este otro.

Muchas cosas han sucedido desde la última visita de Dwengo a Salta. Si están siguiendo la página de CErrobotics ya saben de los robots fabricados en Campo Quijano y las placas Dwengo fabricadas en la escuela técnica Albert Einstein de Salta. Quizas algunos también se hayan enterado de las actividades de Fundasoft en Córdoba, que ahora comineza con sus cursos en programación y lanza su propia versión de la placa Dwengo (hace un tiempo publiqué una reseña de la historía de Dwengo).

Los que nos mantiene ocupados el día de hoy es la organización de la semana Internacional de Robótica en Gante, Belgica (del 22 al 27 de Octubre, 2014). Con el dinero que logramos juntar con nuestra campaña en IndieGoGo (dato curioso: las únicas contribuciones argentinas son de gente que vive en el exterior ¿crisis económica o poca cultura de la internet?) solventaremos los gastos de traslado de 4 jóvenes Salteños. Estos son los seleccionados:

• Matias Fajardo (17): habitante de Orán, desde niño fascinado por los robots. Ha construído sus propios aparatos gracias a instruccions que obtuvo de revistas y de la internet.
• Marcos Emanuel Sosa (15): nacido en J.V. Gonzales, es un hacker del radio-control desde pequeño. Un visionario que se preocupa por el mañan de la humanidad. Esperamos oir sus ideas!
• Florencia Antonella Correa (17): viene de Moldes y confiesa no saber mucho de robótica. Sin embargo muestra un sorprendente compromiso con la divulgación de la ciencia y la tecnología en su entorno. Vamos!
• Lourdes Guyot (18): es de Salta capital y participó en el proyecto CErrobotics, ahora busca consolidar su experiencia en robótica.

Serán acompañados por Carlos Alberto Ríos quién ha mantenido una actividad constante en su escuela, integrando cada vez mas jovenés a su clase de robótica de los días Sábados.

Este evento será el último de mi estadía en Bélgica, puesto que mi postdoctorado en la universidad de Gante llega a su final. Mi próximo destino es incierto, pero seguramente, por cuestiones personales, estaré cerca de Suiza. El plan es continuar con este tipo de actividades desde mi nuevo lugar.

sábado, 13 de septiembre de 2014

Best practices in Science [coming from Cybernetics] by N. Wiener, 1947

The following text is extracted from the introduction to the first edition of "Cybernetics, or Control and Communication in the Animal and the Machine". I put it here because Norbert Wiener not only gave his opinion about good and evil in science but he also recommended an attitude and the expected behavior of the ethical scientist. I have highlighted phrases that for me are most important and provided some links.

On ethical science...
"
Those of us who have contributed to the new science of cybernetics thus stand in a moral position which is, to say the least, not very comfortable. We have contributed to the initiation of  new science, which, as I have said, embraces technical developments with great possibilities for good and for evil. We can only hand it over into the world that exists about us, and this is the world of Belsen and Hiroshima. We do not even have the choice of suppressing these new technological developments. They belong to the age, and the most any of us can do by suppression is to put the development of the subject into the hands of the most irresponsible and most venal of out engineers. The best we can do is to see that a large public understands the trend and the bearing of the present work, and to confine our personal efforts to those fields, such as physiology and psychology, most remote from war and exploitation. As we have seen, there are those who hope that the good of a better understanding of man and society which is offered by this new field of work may anticipate and outweigh the incidental contribution we are making to the concentration of power (which is always concentrated, by its very conditions of existence, in the hands of the most unscrupulous). I write in 1947, and I am compelled to say that it is a very slight hope.
"

On values...
"
... I say that the first industrial revolution, the revolution of the "dark satanic mills", was the devaluation of the human arm by the competition of machinery. There is no rate of pay at which a United States pick-and-shovel laborer can live which is low enough to compete with the work of a steam shovel and an excavator. The modern industrial revolution is similarly bound to devalue the human brain, at least in its simpler and more routine decisions. Of course, just as the skilled carpenter, the skilled mechanic, the skilled dressmaker have in some degree survived the first industrial revolution, so the skilled scientist and the skilled administrator may survive the second. However, taking the second revolution as accomplished, the average human being of mediocre attainments or less has nothing to sell that is worth anyone's money to buy.
The answer, of course, is to have a society based on human values other than buying and selling. To arrive at this society, we need a good deal of planning and a good deal of struggle, which, if the best comes to the best, may be on the plane of ideas, and otherwise--who knows?
"

On slavery...
"
I have said that this new development [cybernetics] has unbounded possibilities for good and for evil... It gives the human race a new and most effective collection of mechanical slaves to perform its labor. Such mechanical labor has most of the economic properties of slave labor, although, unlike slave labor, it does not involve the direct demoralizing effects of human cruelty. However, any labor that accepts the condition of competition with slave labor accepts the condition of slave labor, and is essentially slave labor. The key word is of this statement is competition. It may very well be a good thing for humanity to have the machine remove from it the need of menial and disagreeable tasks, or it may not. I do not know. It cannot be good for these new potentialities to be assessed in terms of the market, of the money they save...
"

martes, 17 de diciembre de 2013

Windows 8 bothers me again

So it happens... I boot my computer on Windows 8 to try a software that I couldn't manage to run under Debian Jessie, to check whether it is worth all the pain. While testing this software in Windows 8, this OS was updating, though I was completely unaware of this (It is my fault to not deactivate automatics update from the very first day?). When I decided I want to go back to Debian and restarted the machine, I got this friendly screen saying that I should not turn off my computer becuause W8 was configuring the updates. "Ok!", I thought, "I did not know it, but that's ok.".
The process took hours and when it was finally finished and the pc restarted , it booted directly into W8 without passing through GRUB, "UhOh..."
I immediately went to the internet and found that that GRUB is easy to re-install. I grabbed a copy of live Debian, and made a bootable USB. I could boot from the USB and followed the instructions from the dpkg bot at irc channel #debian-next:

To reinstall boot to your Debian install disk/live CD, switch to the other console (Alt-F2), then mount your root filesystem (mount -t "fs type" /dev/"partition" /target ; mount --bind /dev /target/dev ; mount -t proc none /target/proc ; mount -t sysfs none /target/sys), then chroot into it (chroot /target) and run update-grub && grub-install /dev/"device".  Also works for EFI.

I did this and rebooted. Sadly it did not work and I got:

Reboot and Select Proper Boot Device

Since then (it has been 3 days! I wish I could sue MS for all the time wasted!) I am trying all suggestions I get that do not look too dangerous. I am about to re-install my Debian, but I am not sure this will solve the problem.

Technical data
Machine: ASUS K55V
It is a UEFI machine but I have

Fast boot [disable]
Secure boot [disable]
Launch in CSM [enable]
PXE OpRom [disable]

As far as I understand this means that I am in BIOS compatible mode.

My Disk was partitioned in the following way (it has a protective MBR strcuture)

EFI partition
Windows partition
Some KiB not allocated
Root partition
Swap
Home partition

This worked fine until the update in question. Following a suggestion from user amphi in #debian-next I added a 1 MiB BIOS Boot partition (shrank the EFI partition by 1 MiB). I thought this did not make sense, cause the system worked for 1 year and half without this partition, but when everything fails, you do what is left. The disk now looks like

EFI partition
BIOS Boot parition
Windows partition
Some KiB not allocated
Root partition
Swap
Home partition

The only effect of this is that my BIOS/EFI now detects 2 windows bootable sectors instead of just one.

Ideas?
Will re-installing Debian solve the problem?
What should I do with the EFI partition? Back it up (it has the bootloaders) and then remove it completely?

Se ha producido un error en este gadget.