/usr/portage

Konsequenter Schritt 15

Es gibt ja klassische Beispiele für Branchen, die meinen, gegen die Geschichte im negativen Sinne aufstehen zu können. Angenommen, bei der Einführung des Autos hätten die Postkutscher sich gegen eben jenes zur Wehr gesetzt, es wäre vergleichbar mit dem peinlichen Aufstand, den die Musikindustrie derzeitig gegen Downloader wagt. Einem ähnlichen Aufstand frönen die Freunde des »sauberen« Radsports, die ach so furchtbar finden, dass immer mehr Doping-Fälle bekannt werden. Dabei sind die Leistungen, die diese Sportler vollbringen, längst nicht mehr ohne Drogen zu schaffen. Man sollte also schnellstens darüber nachdenken, den Gebrauch von Amphetaminen, Steroiden usw. zur Gänze zu legalisieren. Ähnlich den Reifenherstellern in der Formel 1, in der die Fahrer längst nur noch vernachlässigbares Teilchen des »Gesamtsetups«, wie es so euphemistisch heißt, sind, könnten dann endlich die Pharmakonzerne munter gegeneinander antreten und hätten einen wunderbaren Werbeeffekt: »Bayer: Dopingpartner der Gewinner der Tour de France 2007, 2008 und 2009« – ein Untertitel der durchaus etwas hermacht.

Filed under , , , , & 15 comments & no trackbacks

Question of the day 7

Why does nobody develop Gstreamer-bindings for PHP?

Filed under , , , , & seven comments & no trackbacks

They are doing the right thing 7

»The neighborhood bully been driven out of every land,
He’s wandered the earth an exiled man.
Seen his family scattered, his people hounded and torn,
He’s always on trial for just being born.
He’s the neighborhood bully.

Well, he knocked out a lynch mob, he was criticized,
Old women condemned him, said he should apologize.
Then he destroyed a bomb factory, nobody was glad.
The bombs were meant for him.
He was supposed to feel bad.
He’s the neighborhood bully.«
Bob Dylan, Neighbourhood Bully

Filed under , , & seven comments & no trackbacks

Multithreaded TCP-server in Ruby 0

Hopefully on Wednesday Blogmonitor, a new project of Interdings will be open for the public. In the last days and hours I was working on the API-components. An XML/RPC-interface, an REST-service and as a nice goodie a multithreaded TCP-server where you can watch all the incoming pings when they occur. The concept is the following: when an incoming ping occurs, the encapsulated class Blogmonitor::Pingservice::Ping sends a notification to the TCP-component, which waits for incoming connections on a custom port and serves the snippet to all of the connected clients. This is invented as really simple interface and has nothing to do with more standartized technologies like »Publish & Subscribe«, also the logic would be similiar.


What does Ruby already provide?


Ruby ships an example of a multihreaded server implementation which is called GServer. It provides the possibility to create a child-class of it, overload the serve()-method and be happy. That’s really a good beginning and the concept of having patterns seems to succeed again: don’t code things twice.


Example I, first working snippet


<ol><li>require 'gserver'</li><li>class MyServer < GServer</li><li>  def serve( io )</li><li>    io.puts( "Hello world" )</li><li>  end</li><li>end</li><li></li><li>s = MyServer.new 1234</li><li>s.start</li><li>s.join</li></ol>

The code should be more or less self-explaining: load the pattern, extend the class GServer and overload the method server(), which provides an IO-object. The method puts() of the IO-object writes »Hello world« to connected client.
Just create an instance, start() the server, join().
Connect with telnet to localhost and port 1234:

telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
<strong>Hello World</strong>
Connection closed by foreign host.

Now you have a simple TCP-Server. But we miss a few things: on the one-hand the backend notification is not implemented and the connection is not persistent. If a client connects, it should not be disconnected just to receive a stream of incoming weblogs. First of all: implement the streaming thingy. Have a look at the lines 3-5 of example I: the serve()-method is executed on a new connection and disconnects the client when it method is called. But we want to have it persistant. A dirty solution would be to write the io-code in an endless loop, which works pretty fine.


Example II, persistant server


<ol><li>require 'gserver'</li><li>class MyServer < GServer</li><li>  def serve( io )</li><li>    loop do</li><li>      io.puts( "Hello World" )</li><li>    end</li><li>  end</li><li>end</li><li></li><li>s = MyServer.new 1234</li><li>s.start</li><li>s.join</li></ol>


Let’s implement the backend thingy. During my implementation I ran into a number of problems: I had a working example on my Linux-box there and after putting it on our development-system, which is a Solaris-driven T1000 from Sun I saw that from strange reason the implementation of sockets in Ruby seems not to work on Solaris, which is pretty annoying but in the end I’m happy it did not work with sockets. The next idea was to use just TCP with non-blocking connections to send packages from the ping-interface to the Live-monitor-component, but sadly Ruby on Solaris does sadly also not support non-blocking connections. The thing I’d stuck with was UDP. Good old UDP but I think it is pretty ok for this uncritical task. To send some message, you also have a pattern called UDPSocket which can be utilized to do this task.


Example III, UDP-server


<ol><li>require 'socket'</li><li>u = UDPSocket.new</li><li>u.bind( "127.0.0.1", 1357 )</li><li>message = u.recvfrom( 512 )[0]</li><li>puts message</li></ol>

Example IV, UDP-client

<ol><li>require 'socket'</li><li>s = UDPSocket.new</li><li>s.connect( "localhost", 1357 )</li><li>s.send( "Hello world", 0 )</li><li>s.close</li></ol>


The next problem is to make sure all listening TCP-clients get notified. So we need to have something like an IO-heap, where we store all the existing IO-objects and iterate through them to notify everyone. So we modify the serve()-method as it follows:

  1. def serve( io )
  2. io_heap << io</li><li> loop do; end</li><li>end</li></ol></pre> <p>But who sends the snippet to all the objects? We also overload the constructor of our MyServer class to start a notification thread which does the following tasks:<ul><li>Start the UDP-server</li> <li>Iterate to our heap of IO-objects to notify them all</li></ul></p> <h3>Example V, the complete component</h3> <pre><ol><li>require 'gserver'</li><li></li><li>class MyServer < GServer</li><li> def initialize( port, *args )</li><li> io_heap = []
  3. udp = Thread.fork do</li><li> udp_socket = UDPSocket.new
  4. udp_socket.bind( "localhost", 1357 )</li><li> loop do</li><li> payload = udp_socket.recvfrom( 512 )[0]
  5. unless payload.empty?
  6. io_heap.each do |io|</li><li> begin</li><li> io.puts payload</li><li> rescue Errno::EPIPE => error</li><li> io_heap.delete io
  7. end
  8. end
  9. end
  10. end
  11. end
  12. super(port, *args)
  13. end
  14. def serve( io )
  15. @io_heap << io
  16. loop do; end
  17. end
  18. end
  19. server = MyServer.new( 1234, host=“localhost” )
  20. server.start
  21. server.join

Isn’t it really, really short?

Filed under , , , , , , & no comments & no trackbacks

Philtrat-Ausgaben online 2

Für Interessierte: meine Artikel in der Philtrat kann man nun auch online nachlesen und nicht nur in Druckform.

[ Disclaimer: they forced me to use the Binnen-I ]

Filed under , & two comments & no trackbacks

Lebenslage: schwierig 9

Wieso macht die Stereoanlage bei dEUS merkwürdige Probleme, bei Soundgarden nicht und wieso geht es in »Schön von hinten« von Stereo Total nur ums Verlassenwerden und nicht um Analsex. Fände zweiteres lustiger. Das ist sowieso eine Frage, die ich mir in letzter Zeit häufiger stelle. Also ich hätte bei Brecht, Adorno, Focault, Marx und den ganzen Spacken immer wieder Korrekturen. Wenn die mich mal gefragt hätten, wäre Marx vielleicht nicht so ein lausiger Schriftsteller geblieben. Fühle mich vom Weltgeist vernachlässigt. Deswegen auch mein Problem mit Stereo Total. Auch erschreckend, dass ich heute schon zum zweiten Mal festgestellt habe, dass das Foxi-Geschreibsel mich amüsiert. Dabei finde ich Blogger ja eigentlich komplett doof. Aber wo die Welt nicht ins Bild passt da … jaja, Luschen passen dann das Weltbild an. Ich nicht.

Filed under & nine comments & no trackbacks

Bessere Nachrichten 0

Wer sich nicht dafür interessiert, was der erweiterte Freundeskreis Palästinas – also praktisch die gesammte deutsche Politik – derzeitig so alles »verurteilt«, »schlimm findet«, »anmahnt«, »kritisiert«, »deutlich sagt«, »zu Bedenken gibt«, etc. pp., der lese Letters from Rungholt (Archiv).

Filed under , & no comments & no trackbacks

Inkontinente Deutsche 1

Es gibt Dinge, die sind nur als »Ausflüsse« zu bezeichnen. Durchaus im körperlichen Sinne. Ebenso wie es Leute gibt, denen man anmerkt, dass sie ihre kompletten geistigen Möglichkeiten darauf verwenden, nicht zu sabbern, gibt es noch jene, die genau dieses Sabbern noch nicht einmal kontrollieren können, geschweige denn wollen.
Besondere Ausflüsse produzieren Deutsche meist dann, wenn es um Israel geht. Nur als tief sitzende Neurose zu deuten, ist dieser Antisemitismus des Moralisten in seinem Gestus ganz besonders ekelhaft. Beseelt von dem Wunsch, das »endlich einmal Schluss sei«. Zur Verdeutlichung einige Zitate:


Continue reading "Inkontinente Deutsche"

Filed under , , , , & one comment & no trackbacks

What to do? 0

During my daily work I often heard discussions about how to handle charset properly. What a server must provide to handle charsets correctly, which configuration for Apache is needed, what options must be set in php.ini to make PHP correctly working, which functions should be avoided when using PHP, which locales must be used and so on. So I want to give a short overview how to sail around common problems in a LAMP-setup.

Kernel

Just to make sure the option CONFIG_NLS_UTF8 is set to y.

Environment

To make sure, newly created filenames are there in UTF-8 and in general VT-input is handled correctly, you have to choose a charset, which comes with an .UTF-8-suffix. For german feel free to choose de_DE.UTF-8. Make sure your glibc is provides this locales. To convert current names of files you can just use convmv. For a desktop you must also adjust the font and set a correct TTY-font but this could be ignored for a server which is just administrated via remote shell.

Webservers in general – focus on Apache

To make sure, the users input is UTF-8, the server has to deliver the correct Content-Type-header. Take a look at the output of wget -S http://usrportage.de, my weblog, which is hosted on Schokokeks.org, a properly configured server (sure!):
wget -S usrportage.de
—21:00:33— http://usrportage.de/ => `index.html’
Resolving usrportage.de… 87.106.4.7
Connecting to usrportage.de|87.106.4.7|:80… connected.
HTTP request sent, awaiting response… HTTP/1.1 200 OK Date: Thu, 13 Jul 2006 19:00:27 GMT Server: Apache X-Powered-By: PHP/5.1.4-pl0-gentoo with Hardening-Patch X-Blog: Serendipity Set-Cookie: PHPSESSID=9da2ded6522851ef8ddc3ebe7590b354; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Serendipity-InterfaceLang: de X-FreeTag-Count: Array Connection: close Content-Type: text/html; charset=UTF-8
Length: unspecified [text/html]

[ <=> ] 65,557 250.71K/s

21:00:33 (250.19 KB/s) – `index.html’ saved [65557]


You see the header Content-Type: text/html; charset=UTF-8. (You can also the a bug in S9Y, which poorly casts an array, but anyway.) So your browser is notified, that it should send UTF-8 encoded data. That’s the whole secret. To configure Apache properly, make sure the directive AddDefaultCharset is set to UTF-8.

One thing at last: if you’re using AJAX-functions from Prototype for JavaScript-purposes, you have to reencode the string delivered by the AJAX-call. In PHP the following would work:
$string = utf8_encode( $_POST[‘key’] );

MySQL

Before transacting any data, make sure your connection charset is set to UTF-8:
SET NAMES utf8;
By the way: have I ever mentioned you should ever use mysql_real_escape_string() instead of mysql_escape_string()?

PHP

Just two rules: use mb_string-functions whereever it is possible, set the INI-setting default_charset to UTF-8 and – anyway – don’t use functions from the ereg-family also they have an mb_-Prefix. They aren’t binary-safe, that’s all you need to know.
Also make sure, your sources are UTF-8 encoded. Use iconv to correct those who are not.

Update


I forgot to mention, that the functions htmlentities(), html_entity_decode() and htmlspecialchars() does not reflect PHPs default_charset-directive but assumes iso-8859-15 as the default charset, which is pretty annoying and should be considered as a bug, from my point of view. So you need to pass UTF-8 as the third parameter to the function to make sure it will work properly with Unicode.

Filed under , , , , , , , & no comments & no trackbacks

Werbeeinblendung 0

Ich wollte nur mal darauf hinweisen, dass der Deutschnationalist Manfred Rouhs nun einen publizistischen Gegenspieler bekommen hat. Ob Biedermanni beleidigt ist, wenn man ihn fragt, ob sein Nachname wirklich französisch ist?

Filed under , & no comments & no trackbacks

Meine Lieblingsszenen der WM 8

Coole Aktion: John Pantsil mit Israel-Fahne.
Zidane mit dem Köpfchen: Einen besseren Abgang kann man nicht haben. Die schleimigen Nachrufe bleiben aus, das Feuilleton hält einfach die Fresse

Filed under , , , & eight comments & no trackbacks

Wer kommt mit? 0

Ab und an ist selbst in Bonn was los.

Filed under , , , , & no comments & no trackbacks

Die Revolte der Geläuterten 0

Flennen im Kollektiv: wenn Deutsche sich selbst betrauern

Zwei Dinge sind überraschend an der vergangenen Herrenfußball-Weltmeisterschaft: Einerseits, dass die befürchteten polizeilichen Repressalien deutlich weniger massiv, als im Voraus vermutet, ausfielen und andererseits, wie wenig schlecht Frisierte heuer anzutreffen waren¹.


Continue reading "Die Revolte der Geläuterten"

Filed under , , , , , , , , , & no comments & no trackbacks

Atheism is a non-believe 0

»We really have nothing to talk about other than our conviction, that religion sucks.«
Brannon Braga

Interesting talk by Brannon Braga on the Atheist Conference in Ireland.


Source: Stefan Horning

Filed under , , & no comments & no trackbacks

Aufgeräumt 2

Um dem sich anbahnenden Chaos in der Kontaktliste des Lieblingsclients wieder etwas Herr zu werden habe ich nach Gutdünken Leute entfernt, mit denen ich seit längerer Zeit nichts mehr zu tun hatte oder bei denen ich mich nicht mehr an die Ursache ihrer Existenz in meiner Kontaktliste erinnern konnte. Wenn Sie meinen sollten, Sie seien fälschlicherweise gelöscht worden, dann täuschen Sie sich mit sehr hoher Wahrscheinlichkeit. Falls doch, einfach nochmal hinzufügen. Wer bisher nicht drin stand aber schon immer in den Genuss des Kontakts zu mir kommen wollte, dem sei dies auch gestattet (Kontaktdaten).

Filed under , , , & two comments & no trackbacks

Newer Entries ↘