/dev/blah

things i want to remember, things i want to share

Développeur Python et adepte Linux depuis 2005, Core développeur Kivy, passionné par beaucoup trop de choses.
Profil Github gpg signature bitcoin address

Archive for February 2014

Firefly

written by tshirtman, on 2/26/14 1:35 AM.

Yeah, i like to be late at these things.

So i watched the sadly unique and incomplete Firefly season, in the past few weeks, finished yesterday. I had made the choice not to look too much into the culture around the show, and any information source about it, only choosing to watch it on the impact it seemed to have on a lot of persons in my demographics, that is: geeks.

And i have to say it was a really great experience, stopping very abruptly, sure, and all the fans have been, i’m sad it stopped in such an unfinished state, but at least i had the notion of this before even starting watching, the fact that it achieved such popularity despite such a harsh cutoff was part of what convinced to watch it in the first place (also, the fact that it wouldn’t take so much time to catchup was definitely a seller). The show is grandiose, attention to details and psychology of the characters is incredible, and each episode introduce very interesting narrative and aesthetic choices. Dialogs are really well written, and action is very well balanced with humor and drama.
It’s also self evident that a lot of plot elements have been opened and would have been explained a lot later in the show, that there was a lot of depth to explore in the long-story.

Anyway, i can only recommend it, be warned that you’ll be frustrated, but i believe its still worth it, what there is is not enough, but it’s too good to miss anyway.

Tip me if you like this :)

[book] What's property, Proudhon.

written by tshirtman, on 2/25/14 1:10 AM.

Some serious reading here, this book took the better part of my commuting time in the last few weeks, i really wanted to know what made this man so (in)famous, and i don’t regret giving it the time. The book published in two parts (memoirs), the second one addressing a lot of the critics that met the first one.

The book is entirely constructed as a demonstration that property, and specifically private property of production means, is false, in the sense that it creates contradictions, leading to injustice in societies that adopt it. Of course, such a proposition is bound to raise a few eyebrows, and the way Proudhon puts it, by very analytical deconstructions, certainly makes one feel there is a great danger here, if you think property is an important part of societies, or even, as a lot of people believe it (no judgment here), the one funding bloc of civilization. Proudhon is not proposing that everybody is free to dispose of everything, though, he goes a long way to make the distinction between possession, and property, and while he consider the latter false, the former is deemed right and very important for civilization. I’ll surely betray the author for trying to put it in a few words, but in short, you have possession of what you need to live and work, of what you produce, but you can’t possess what you don’t directly use. This distinction makes all profit not derived from one’s work, impossible, and in Proudhon’s view, justice possible.

To show the injustice of property, the two historical justifications for property are proven to be baseless, the first one being that the first person to declare something to be his property, and strong enough to hold it, can claim it as a property, is just a sanction of strength, and not a principle of justice of any kind, because it means that families will inherit different shares based on the share of their parents, and the number of their siblings (since the inheritance is not just for the first child anymore), and as the constitution makes everyone equal in rights, from birth, the birth can’t be the origin of different rights. The second source of property, work, is in no better position, because it’s self evident that a lot of exception would apply, the first one would be that it would only apply on any unclaimed property (building something in your neighbor’s garden won’t give you any right on it, you’ll rather have to pay for the destruction of your work), and secondly, when you cease to work, is the thing you worked on still your property? Proudhon’s claim that if no, then it’s possession, and if yes, then work gave you more than you earned, you only earned the benefit of your work, the better production it created, not the tool itself.

Proudhon also claims that his views are just a clarification from the views people really hold, although they are unable to understand it. He shows a lot of example where we don’t accept the principle of property as inherently inviolable, and that in the end, people just have to recognize that property is just a misconception of possession, which is the true principle we can accept.

It’s important to note that Proudhon is not a communist, he regrets that nobody came up yet with a system that doesn’t consist of either property or communality, the price of communism, a very rigid state making liberty impossible in his views, is too high to be considered a good alternative to property. His system would only share wealth among people producing what other people needs and are ready paying for, be it food or poetry, it seems pretty clear that there wouldn’t be much help for unproductive (by their peer’s definition) members of the society (considering that it’s the fact that property makes people wealthy not by their work, but by the work of others with their assets, so by not being productive themselves, that Proudhon’s disagree with, we can say it’s a coherent position). We can note that the mechanical limitation in accumulation of wealth in such a system would mean that wealth disparities would be much lower than todays standards (and they are much bigger than people usually think these days).

Proudhon also seem to be far from a revolutionary, he notes in a few places that his memoir is addressed to intellectuals, not to the common man, and that nobody wants to see the reaction such a thing would cause, especially in hard economic times. He calls for a deep change in legislation, before change comes up in a disastrous way, going as far as saying “saying that only an overthrow can bring reform, is, for me, doing a syllogism, and looking for truth in the unknown”, in other words, revolution is a gamble you don’t want to make.

This book was also interesting because of the expressed views on history, being written in the 1830′s, a mere 40 years after the French revolution, yet in a way more modern time (XIXth century) than this period. Of course, Proudhon being very radical in his views, it will make sense to seek other opinions on the persons and ideas discussed here, but it’s very interesting nonetheless.
The XIXth century was a high time of intellectual reflection and discussions, a lot of systems being proposed and tried, science was tentatively applied to government systems, with of course, varying success.

On the other hand, it’s interesting to see that Proudhon hold some very conservatives opinions, regarding women, for example, of course, they are symptomatic of his time, but he notes his disapproval of the early feminist movements, considering that women are simply not built to hold the same qualities as men.

On the literary side, i appreciated the style in a lot of places, but some parts where lengthy and a bit unexciting, the lack of structure (it looks like a 250 pages rambling followed by another 150 pages rambling) and the terse style, although often enjoyable, made me feel like i was crossing a desert more than a few times, maybe that’s also why i need to get back into the habit of reading :).

Closing up, i think i got out of the book with a deeper understanding of the intricacies of rights and property, of the difficulties of making equality and justice happen without limiting liberty too much. And it gave me motivation to read other books of the same kind, that is, theoretical studies on societies and socialism.

Tip me if you like this :)

Monitoring your git status.

written by tshirtman, on 2/20/14 1:58 AM.

It’s not uncommon to query various git commands to know your current state in your repository, before doing the commands that do actual things.

To avoid doing some of them needlessly, or missing important information, it’s a common solution to customize a shell prompt to add the most important information in it.

However, that’s usually quite limited, and when developing on a project, or doing some refactoring or even rebasing, you’ll often do the same commands over and over.

Doing something over and over is bad, it makes you tired and mistake prone, and computers are good at doing repeated actions for you, so you just know to know the right tools.

The watch linux command allow to execute a command every nth second (n being 2 by default), so you can let that run in a shell next to the one you work in.

A first step then is:

watch git status --short

not very advanced, but actually helpful, however, there is a few over commands you’ll want to see, for example, the existing branches and the one you are on, the git log is cool too, and git reflog, being one of my favorites.

watch "git status --short && git branch && git log --graph --oneline && git reflog"

It’s nice to see on what commit a branch is, too, so let’s add that to the branch command.

watch "git status --short && git branch -v&& git log --graph --oneline && git reflog"

We have a problem, though, log and reflog will usually be way longer than our terminal can afford, and you’ll not see reflog at all.

watch "git status --short && git branch -v&& git log --graph --oneline | head -n 10 && git reflog"

(it’s actually not needed to cut the tail of reflog, as it’s the last command)

But all of this is a bit lacking in colors, lets add them!

watch can allow colors to be used, but we still have to force git to show
them. To avoid things getting to messy, we’ll define a few git aliases:

git config --global alias.cstatus "-c color.status=always status --short"
git config --global alias.bc "branch --color -v"
git config --global alias.ll "log --graph --pretty=format:"%C(yellow)%h %C(blue)%ci%C(green) %an %C(red)%d %Creset%s"

then our watch command can be

watch -c "git cstatus && git bc && git ll | head -n 10 && git reflog --color"

This is starting to look good, but there is some need of a separation between the various commands, i found it best to simply leave an empty line.

watch -c "git cstatus && echo &&git bc &&echo && git ll | head -n 10 &&echo && git reflog --color"

There is still one ugly detail though, and that’s the header produced by the watch command, thanksfully, it can be easily discarded using the -t option:

watch -ct "git cstatus && echo &&git bc &&echo && git ll | head -n 10 &&echo && git reflog --color"

The result is probably that you want to add a few things to .gitignore, delete a few branches hanging around for no reasons, and slap people doing too long commit titles :P. Which is probably a good task for the forthcoming spring :).

Bonus points if you use a tiling windows manager, and can give this a chunk of the side of your screen ;).

Tip me if you like this :)

Using tex_coords in kivy for fun and profit

written by tshirtman, on 2/19/14 1:45 AM.

Your gpu is an awesome thing, it can do all kind of calculations, very fast. For example, instead of telling it exactly how you want each pixels to be, you can throw textures and vertices at it, and have it correctly deduce how this things will have to look.

To do this, though, you must tell it what part of the texture will be stuck to each vertice. This is usually denoted using texture coordinates.

Texture coordinates, like usual coordinates, indicate the place of something. Instead of noting them x and y, they are often called u and v, which allows to clearly note what parts of an equation relate to each.

While kivy offers you high level canvas instructions, it gives you a pretty good access to lower level features, and you can actually manipulate the texture coordinates of your Rectangle instructions. This allow for cheap zooming, repeat-scrolling, and other image manipulations, since your gpu is doing all the actual work.

tex_coords = u, v, u + w, v, u + w, v + h, u, v + h

which is better understood as:

tex_coords = [
    u,     v,
    u + w, v,
    u + w, v + h,
    u,     v + h
]

considering a default tex_coords value, where u and v = 0, and w and h = 1 (all values are relatives, so usually between 0 and 1).

u, v + h-------u + w, v + h
|              |
u, v-----------u + w, v

which means the 4 angles of your texture, will be on the 4 angles of your rectangle, how dull!

One way to play with different values, is to create a little app showing you the effect of deformations.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty, ListProperty
from kivy.core.image import Image as CoreImage

kv = '''
#:import chain itertools.chain
RootWidget:
    canvas:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
            pos: root.pos
            size: root.size
            texture: app.texture
            # here is our usage of the calculated texture coordinates
            # we devide by 100 because we took the input with a 100x100
            # rectangle as default value
            tex_coords: [x / 100. for x in chain(*root.points)]

        PushMatrix
        # translate the rectangle to make it easier to play with
        Translate:
            xy: root.width / 2, root.height / 2

        Color:
            rgba: 1, 0, 0, .5
        Line:
            points: chain(*root.points + root.points[:1])
            width: 2
        PopMatrix
'''


def dist(point, pos):
    return ((point[0] - pos[0]) ** 2 + (point[1] - pos[1]) ** 2)
    # ** .5 # who cares about square root here? it doesn't change the order


class RootWidget(Widget):
    # the default values, a 100x100 square, displayed around the middle of the screen
    points = ListProperty([[0, 0], [100, 0], [100, 100], [0, 100]])

    def on_touch_down(self, touch, *args):
        # compensate the translation done in canvas
        pos = touch.pos[0] - self.width / 2, touch.pos[1] - self.height / 2

        touch.ud['point'] = min(
            range(4), key=lambda x: dist(self.points[x], pos))

    def on_touch_move(self, touch, *args):
        # compensate the translation done in canvas
        pos = touch.pos[0] - self.width / 2, touch.pos[1] - self.height / 2
        # update the point
        self.points[touch.ud['point']] = pos


class TexCoordsApp(App):
    texture = ObjectProperty(None)

    def build(self):
        self.root = Builder.load_string(kv)
        self.texture = CoreImage.load(
            'GrassGreenTexture0002.jpg').texture
        self.texture.wrap = 'repeat'
        return self.root


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

The texture have been scrapped on the web and is not very interesting, but you can find it here.

Of course, this is much more a learning device (helful because these transformation are not quite straighforward for our brains) than a practical application, but a lot more can be done.

Here is, for example, a little infinite scroll app uting this concept.

edit: Ben Rousch kindly created apks out of the two examples, if you want to try them on android: TexCoordsExample ScrollExample

Tip me if you like this :)

Switching to i3wm

written by tshirtman, on 2/17/14 12:15 AM.

I’ve been a wmii user for more or less 5 years, and until now although it was not much maintained anymore, i was unable to replace it with something else.

Last time i checked, neither awesome, i3, xmonad, or either of the few tiling WMs i tried, seemed to fulfill my needs, i wanted dynamic tagging of workspace, full keyboard navigation, and the same tag on all screen in a multiscreen setup (more on that later). So, although it had a few bugs, i decided that wmii was still the best thing out there.

Recently, hobbestigrou suggested me having a look at qtile, being in python, it would be easy to script and adapt to my use case.

I did look into it yesterday, and spent some time configure it for my use. In the end, i had most things working, although i wasn’t crazy about the window placement capabilities, and using the doc hadn’t been a thrilling experience.
The last standing point however was, the separate tag management per screen, but, at that point i was ready to give that a chance, considering i often pinned a window to all workspaces on the second screen (but not all the time).
So i decided to give a second chance to i3wm, considering it’s the spiritual successor of wmii, i may be more excited at the window placements.

And while it took me some time to wrap my head about the tree system of i3 (the split shortcut (Meta4+v) turned out to be quite important), i have to admit it solves all the limitation of wmii’s one, while avoiding the limitations of layout systems of other tiling managers.

Now, i3 doesn’t expose a dynamic tagging system out of the box, but it offers a nice cli api, and i found a blog post offering a good explanation on how to use it, i adapted it to make it slightly faster, but the idea stands.

I’m still a bit confined by the inability to share tags across screens, i gave myself a way to move a window/container from one screen, but it’s still a bit different. I won’t try to force i3 to see only one screen, as i did on my first try, because that caused all sorts of swampy issues, and it’s clearly not the way it’s meant to be used.

Other than that, it’s pleasing to see all the nice improvement of the window manager over its ancestor, it’s certainly way more pleasing to look at, and to configure.

Anyway, my configuration is now on github, for my own profit (easier to setup on multiple machines), and for the curiosity of others :).

Tip me if you like this :)

Keyboard Kata

written by tshirtman, on 2/12/14 2:08 AM.

So i spent most of the evening copying texts on dactylotest, most of the time barely reading them, while listening to tv, to work on my typing speed and regularity, and it paid a little, for the first time, i passed the 70WPM mark, and i hit 60WPM most of the time, which is a progress from the 50WPM i considered normal not long ago.

70WPM

so yes, practice makes perfect…

Tip me if you like this :)

Using jinja2 outside of the web.

written by tshirtman, on 2/10/14 12:56 AM.

I may be the last person out there to do that, but i hadn’t actually gotten to that yet.

So here is the thing, sometime you want to produce a text file, with some complex structure, and string.format is not really up to the task, so you scratch your head and wonder what could be useful to… template an output.

Then a nice lib like jinja2 totally makes sense.

For my use case, i want to generate java source code, using info parsed from other java source code (thanks to the awesome plyj lib), so it’s easy to give the general form of the output file, and to pass the content after that.

{% if package %}package {{ package }};{% endif %}
import {{ module.package_declaration.name.value }}.*;
{{ imports }}\

public class {{ cls.name }}{{ suffix }} extends {{ cls.name }} {
    public interface I{{ cls.name }} {\
    {% for method in methods %}
    {{ method.return_type | get_type }} {{ method.name }}({{ method.parameters | render_params }});\
    {% endfor %}
    }

    private I{{ cls.name }} implem = null;

    public void setImplem(I{{ cls.name }} implem) {
    this.implem = implem;
    }

    {% for method in methods %}
    {{ method.return_type | get_type }} {{ method.name }}({{ method.parameters | render_params }}) {
    if (this.implem)
        return this.implem.{{ method.name }}({{ method.parameters | render_params_values }});
    }{% endfor %}
}

One problem i had, though, was when it turned out it would be convenient to use custom filters inside my template, it took me some time to find the relevant documentation about how to register functions as filters in this situation (since people usually use jinja2 in a framework, they document how to do so using the environment used by this framework).

So the answer was not to use jinja2.Template directly, but to build an environment before.

env = jinja2.Environment()

then to setup my filters in this environment:

env.filters['render_params'] = render_params
env.filters['render_params_values'] = render_params_values
env.filters['get_type'] = get_type

and to use env.template_from_string(template_string) to create a Template object from my string.

Tip me if you like this :)

Worthiness of effort

written by tshirtman, on 2/9/14 1:08 AM.

If it’s worth to be done, it’s worth to be done well. If you aren’t struggling, it’s not worth doing it.

Tip me if you like this :)

flappy bird is a stupid game.

written by tshirtman, on 2/7/14 1:54 AM.

No, seriously.

Difficulty is flat, once you got past a pole, you know you can get past any pole, if you got past a dozen, you know you can theoretically go “all the way” (and there is no difference between theory and practice, in theory), so it’s just a matter of being consistent, the challenge is just to avoid losing focus, or stressing (because you are getting near of your high-score), but each pole is just as easy as the first one in the game.

So getting past pole 1 is enough to “beat the game”, of course, then you’ll set other arbitrary limits, trying to push further and further, but it’s just a matter of how lucky you are at avoiding accidents. I decided to put the limit at 50, and got to it today, so that’s it for me, and i’ll resume more interesting activities :P (it was already to high a limit, but i think it’s enough to consider i didn’t “beat the game” by accident).

Tip me if you like this :)

Magnet: a widget to easily make your interface more lively

written by tshirtman, on 2/6/14 12:38 AM.

Kivy has a very nice Animation class, that allows you to move move widgets around (or other things), by updating any numeric property to a target value, just by setting a time and a transition function. Still, when you are building a complex interface, it can still be a bit cumbersome to manually trigger animations for all the elements, and to keep track of them.

After being frustrated about this issue for some time, i tried my luck some time ago, at doing a nicer, “90% use cases” interface, and the Magnet garden widget was born.

Its usage is simple, you simply use it to wrap your target widget, and give it rules about how to transition when the magnet is moved. As the magnet is moved or resized by the usual kivy logic, instead of making the wrapped widget immediately follow such constraints, it’ll create and keep track of animations to achieve a smooth transition to the new values for you.

As any garden “flower”, to install it, you need to install and use the garden project.

python setup.py install

(either in a virtualenv or system-wide)

then do:

garden install magnet

you can now import it a kivy application:

from kivy.garden.magnet import Magnet

Garden Magnet video

Tip me if you like this :)

Tags

#FIXME 3G absurd ad_sense alterway aléatoire android animation anonymity atheism bach backlog bash bitcoins blog blogging boldness book books boulot bricolage bépo C canvas captcha captures carte SD censure christianity chroot CLI cli cloudwatt code colors comfort zone command line community company life conferences contest copwatch copwatchnord-idf core-devs cours ct705 culture deb debian debug deformation dehors dessin dev distribute distribution débutant déploiement développement ebooks eeepad eeepc effect ego empty en escher event firefly flappy bird flask fosdem foss fr fun game garden gdb geek culture git github goals graphics grrr gödel hack hackathon hacked hacking health hooks i3 images IMAP inspirational install isync java jeu jeu video jinja2 jni keyboard keynav kivy kv lame learning lib libre life linux lol macosx magnet mail mailing-list mails maths mbsync meetings memory leak mesh meta mint mirroir MIT module motivational mouse museomix mutt nexus7 no-mouse notmuch nottoomuch offlineimap onycroit opencourseware osc packaging paris passphrase password patch pentacatyl people perte de données ping pip planning plugin positioning pr procrastination programmation progress project projet property proudhon proxy psf publisher/consumer pull-down pygame pyjnius pypi python pythonar qtile raid rapsberry pi reading recorder references release religion responsive review reviews réseau réseaux sociaux résurection salon screenshots script self service shows shutil shyness sizing solib sortie sousous!!! spam spritz stash status systeme système templating terminal texture texture coordinates Thomas Paine thread thème tiling time time management. tip tips tools transformer tutorial tv twitter typematrix typing ubuntu ubuntu-fr ultimate-smash-friends unity update upload images useless usf utils value VDM video vie/mort vim virtualenv visite widget windows wm wmii work workflow workflow. zine études