Wednesday, November 2, 2011

Shotgun request

Two support scenarios:

Client: do you have those brutal shotgun, that Schwarzenegger use in first Terminator?

Naive support scenario:
Support: Sorry, this particular model not produced any more. We can try to find it on eBay, or suggest you M50 - it is also big, brutal and noisy.
(discussion goes deeper in technical differences, price and delivery options.)
...

Experienced support scenario:
Support: ok, there is some troubles with shotguns just now. Can you explain, why do you need it, and we may suggest some alternatives?
Client: I want you to shoot in my head from this shotgun!
Support: that's interesting, but why do you want us to shoot in your head?
Client: I have so terrible headache! Hope this will help.
Support: Here is a good pills just against headache ...
Client: Drugs? No! I don't want a drugs, they lead to addiction!
Support: This one is made from safe, radiation-free herbs!
Client: ok then. ... Yes, it help! Thank you!!
Support: so, do you need a shotgun?
Client: Are you crazy??!

Thursday, August 18, 2011

Zeo monitoring server and netcat

Zeo have a nice feature - monitoring server. You open connection to specified host/port and monitoring process write to their end of the socket current zeo server statistic and close connection. Question is - which tool can be used to read data from remote tcp socket? It may be trivial script on Python.
Or netcat. Just:
$ netcat <your_zeo_server> <your_monitoring_port>

, and read your statistic.

Remove terminal escape sequences from text.

sed -e $'s/\033\\[[0-9;?]*[a-zA-Z]//g'

Sunday, March 6, 2011

Core-controller application design pattern

I'm very impressed by the application design pattern of wmii (my favorite window manager during last two years) and uzbl. I can describe it this way: application decoupled to two processes. Let's call them Core and Controller. Core perform some heavyweight functions and notify Controller about significant changes trough the event queue. Controller process mostly read and sequentially/asynchronously process events and send commands back to Core. Core provide low-level functionality while Controller contain high-level logic.

Why this approach is good?

First, this approach enforce better application design - as Core and Controller live in separate processes, they can't easy and instantly communicate with each other. Therefore functions must be carefully split between this two parts. Specification of events itself is a good metaphor for application design documentation.

Second, this approach allow to implement Core and Controller on different languages, most appropriate for corresponding part. Usually it mean some lower-level language for Core and some scripting language for Controller.

Third, with proper design we are able to insert additional controller between Core and Controller, in the way, similar to shell pipes. For example to redefine application behavior for particular events/group of events without the need to rewrite/patch base Controller. This approach is similar to python wsgi schema.

And now the point of this post. Web-browser and window manager are not an only natural applications for such design pattern. Seems like web server or email server also fit this model, and probably many other applications too. So, we need simple and well-defined protocol for communications between Core and Controller. Event queue itself may be as simple as stream of text lines, but Controller must also be able synchronously inquire particular state information from Core and send commands back to Core. wmii use 9p protocols for this, but I feel it as overkill solution. i3 (fork of wmii) and uzbl use it's own protocols based directly on sockets IO. I hope there can be invented some very simple yet extensible meta-protocol that fit needs of most such applications and don't require any IDL. It can be modeled after unix shell with it's plain text command line and optional binary stdin/stdout.

Saturday, January 29, 2011

Idea for animation

Period of great raise of classical music, time when Mozart, Bach and Beethoven creating their great compositions ... because music have a great power - it is a conductor of magic power. Each composition affect the world according to it's content and feeling, it induct. It's a natural occasion to clip greatest hits of classical music and cartoon interpretation of them.

As the final great battle of good and evil the greatest symphony of Beethoven (good side) save the world from falling into the hell spelled by greatest "bad" wizard Bach. The result of this battle is that music lost it's magic power and can't directly affect reality. This wipe of magic also wipe people's memories and knowledge about magic of music - from heads as well as from books.

Wednesday, January 26, 2011

Qemu networking with TUN/TAP and forwarding.

Task definition.
Have: Linux desktop with (routed) internet connection.
Want: run (Qemu) KVM with network access from vm to desktop and internet and network access from desktop to vm.

Pre-word.
There is a lot of step-by-step recipes reg. this in the web. The problem is that I hate to use recipes I don't understand. One step aside - and everything break and you don't know what to do. Therefore I'm going to configure network manually. This note is mostly for me - to remember required steps.

Solution.

On the host
1. Create tap device.
host# tunctl -u -g kvm
There is almost no documentation reg. tunctl. This spell had been composed "by example". After this command you must see new network interface tap0 by issuing "ifconfig -a".

2. allow NAT in iptables.
host# iptables -A POSTROUTING -o eth0 -j MASQUERADE
where is network card with WAN connection.

3. allow packet forwarding. Add to /etc/sysctl.conf:
net.ipv4.ip_forward=1

4. activate tap interface before setup routing:
host# ifconfig tap0 0.0.0.0 promisc up

5. to allow connection from host to vm, we need define routing *on the host*:
host# route add -host 192.168.1.2 dev tap0
where 192.168.1.2 is IP address of vm.

On the vm

6. my host IP and my vm IP are in different subnets, therefore I need to define routing to host first:
vm# route add -host dev eth0
I'm able to PING host by IP from vm after this step.

7. and then default gateway:
vm# route add default gw
and I'm able to PING other machines by IP after this step.

8. Now define nameserver in /etc/resolv.conf. The same as on host.