Plug it in, baby 2

Ignoring the cloddy ambiguous meaning of the title I’m happy to announce two new plugins for Serendipity. As you can read in the forum (1, 2) and watch in the sidebar of my weblog, I’d written two new plugins for Serendipity. The first one, »Flickr badge«, displays your last images from Flickr in your sidebar. It uses the serialize()/unserialize()-based API provided by Flickr which is very easy to use with PHP. The other plugin displays the album, which was on »Heavy Rotation« in the last week. It uses your Last.fm-account to retrieve these information and Amazon to find an appropriate cover. You can find both plugins in the CVS-repository for Serendipity (1, 2) or install them via Spartacus. Please take care that you need at least PHP 5.1 to use this plugins as I decided to use the wonderful OOP-model of PHP 5.

Filed on 26-01-2007, 02:02 under , , , , , , , & two comments & no trackbacks

Live vom Webmontag 0

So, gerade nen Vortrag über webnews.de gehört. Ich habe nicht so genau verstanden, was die machen, aber ich habe das da gefunden:


Es scheint so, als hätten sie das Problem behoben. Jetzt warte ich nur noch auf meinen Milchschäumer. Aber ich finde das cool, dass das so schnell ging!

Filed on 22-01-2007, 21:09 under , , , , , , , , & no comments & no trackbacks

Using Phing with PHPUnit3 1

If you are interested in using Phing and PHPUnit >=3.0 together, you can just use this patch. It is heavily based on this work by Kentaro Ishitoya.

Filed on 19-01-2007, 15:03 under , , , , , , & one comment & no trackbacks

Lazy, object-oriented URL parsing in JavaScript 2

Use this (no, the regexp does not check for RFC-compatibility):

My_Url = function()

My_Url.parse = function(url)
{ this.url = url result = this.url.match(this.regexp) this.scheme = result1 this.host = result2 this.port = result3 this.path = result4 return this

My_Url.prototype.parse = My_Url.parse
My_Url.prototype.regexp = /(https?:\/\/)([a-zA-Z0-9_\-\.]+)(:[0-9]+)?\/?(.*)?/

url = new My_Url()

This will open an alert window with the content »foobar.com«.

Filed on 03-12-2006, 02:02 under , & two comments & no trackbacks

»sleep« for special purposes 2

I have a problem which occurs every evening: often I started a video using realplayer before going to bed. Realplayer does not close itself at the end of the video, which is correct in general but in my case not the best practice. Realplayer is a proprietary tool and uses Open Sound System (OSS), which is a bit antiquated nowadays. Also OSS was blocking the sound device when playing sounds. The crap Enlightment Sound Daemon (ESD) was a result of that issue. Back to my topic. Often when I go to bed I want to watch a video, but always want my Banshee to wake me up in the morning. But Banshee cannot play any sound, if the device is blocked by realplayer. So I need to kill realplayer once the video is done or a bit later but before the next morning. So I do something like sleep 3600 ; kill <pid> which works pretty fine. If I’m drunken, which takes place naturally rarely, I have the problem that I do not remember how big the integer after my sleep must be. And, especially when I’m drunken, I hate it to have my video quitting before it is done or I felt asleep. So I need a sleep-replacement which is more convenient and usable when being drunken. In fact I need a sleep replacement which can handle strings like »2m«, »2h«, »60*60*2« etc. pp. Download it! And now I can go to bed.

Filed on 15-11-2006, 02:02 under , , , & two comments & no trackbacks

Nee, is klar 7

for ($i=0;$i<count($thread_ids);$i++) $thread_ids[$i]=$thread_ids[$i];

Filed on 19-10-2006, 18:06 under & seven comments & no trackbacks

Die Welt ist schlecht 1

... und erst ihr Code:

    /* WAS IST DAS ???
    //ich weiss es auchnicht aber es ist schon lange auskommentiert glaube ich
    $db->Execute("UPDATE weblogs SET title='$_POST[blog_title]', info='$_POST[blog_desc]',name='$_POST[blog_name]',template='$_POST[blog_template]' WHERE id = ".$_SESSION['weblog']['id']);
    $db->Execute("UPDATE weblogs SET aktiv='$_POST[blog_aktiv]' WHERE id = ".$_SESSION['weblog']['id']);

Filed on 22-08-2006, 16:04 under , , , & one comment & no trackbacks

Question of the day 7

Why does nobody develop Gstreamer-bindings for PHP?

Filed on 25-07-2006, 20:08 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
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( "", 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 on 23-07-2006, 18:06 under , , , , , , & no comments & no trackbacks

ezComponents 1.1 released 0

On June 12th ezPublish, the new employer of Sebastian Bergmann, released ezComponents 1.1. I’m lazy, read the changes by yourself and begin to use one the most helpful PHP-patterns.

Filed on 18-06-2006, 05:05 under , , , & no comments & no trackbacks

Sprücheklopperei 2

Den mitlesenden Computeraffinen gilt es die letzte Einlassung des Kollegen Ohlig nicht vorzuenthalten:

»Python ist eine Strebersprache. Ruby ist dagegen irgendwie mehr Rock ’n Roll«
Schöner lässt es sich kaum zusammenfassen, auch wenn dem Streben manchmal ein gewisser Reiz anhaftet. Letztmalig festgestellt beim Schreiben von mod_jabber.py letztes Wochenende. Der Zwang zur ordentlichen Einrückung ist beim Debuggen schon eher anstrengend.

Filed on 23-05-2006, 21:09 under , , , , , & two comments & no trackbacks

Portage-notification for Gentoo via Jabber 3

Getting notified via mail about recent warnings, information messages and error on your Gentoo system is good thing but getting notified via Jabber could be also helpful in some cases. The new notification framework of portage in the current 2.1-serie previews makes it easy and possible to implement somthing like this. To show how easy it is, I did it. You can see the result in the Gentoo Bugzilla. I am utilizing XMPPPY, a friendly Python-library to do so.

How to use?
1.) Install an ebuild of the 2.1-serie of sys-apps/portage
2.) Install dev-python/xmpppy
3.) Copy this file to /usr/lib/portage/pym/elog_modules/mod_jabber.py
4.) Edit /etc/make.conf and set the following options:
PORTAGE_ELOG_SYSTEM="jabber" PORTAGE_ELOG_JABBERFROM="sender@host.com:password" PORTAGE_ELOG_JABBERTO="jid1@host.com jid2@host.com admin@foo.com"

As of a request by solar and Jacub Moc I did a proper release which is availiable there and wrote an ebuild. All you have to do now is to install the ebuild and edit you configuration.

Filed on 21-05-2006, 15:03 under , , , , , , , & three comments & no trackbacks

Quality assurance with __call(), __get(), __set() 0

__call(), __get() and __set() are so called magic functions of PHP-classes. __set() is called, when you’re trying to overload a property of a class, __get() is called, when you trying to fetch a property which is undefined and __call is executed if you’re going to call a method which is not defined. Example:

class Test
{ public function __set( $name, $value ) { echo “Name: {$name}\n”; echo “Value: {$value}\n”; }

public function __get( $name ) { echo “Name: $name\n”; } public function __call( $method, $parameter ) { echo “Method {$method} called with following parameter:\n”; var_dump( $paramter ); } }
This should be enough, to understand what this functions are doing. Now you can modify the magic functions to log its error messages or to trigger a warning. One hint: Also it seems, it’s not a good idea to throw an exception, because this will lead to silent stops in your program in combination with register_callback_function(). A good idea is to create a base-class, which provides such QA-mechanisms for free and all of your classes are children of this class. Also it would be a good idea if something like this would be implemented in PHP.

Filed on 14-05-2006, 16:04 under , , , , , & no comments & no trackbacks

Question 0

Sometimes even I, as cautionary as I am normally, must consult my audience. How to create and handle fucking tai64n-timestamps in PHP?

Filed on 14-05-2006, 00:12 under , & no comments & no trackbacks

MySQL Storend Procedure Programming 2

Falls mir jemand einen Gefallen tun möchte. Über dieses Buch würde ich mich sehr freuen.

Filed on 13-05-2006, 17:05 under , , , , & two comments & no trackbacks

Newer Entries ↘