Code and Stuff

Feb 26, 2013

SVG Filter Tests

Applying SVG filters to various things


Apply filter to WebRTC Webcam capture. Webcam code was taken from Mozilla.

Or on a normal video (source wikipedia;


To test the canvas I will reuse my Image Compositing post "plasma" like animation.


Youtube can work using flash or html5. Probably the HTML5 uses a video tag or a canvas (never actually checked that), but we are interested in the flash version. By default, if available, youtube uses flash (as of feb 2013). Click Here for the original Rhett & Link GMM video.


Mid february 2013 i tested Mac Firefox 19, Mac Chrome 25 and Windows Firefox 19
  • Chome shows some strange behaviour with animated stuff (e.g. convolution not applied)
  • Firefox SVG filters are quite slow (especially the erode and dilate)
  • Firefox SVG filters are not applied to flash videos on Windows. They are on a Mac 10.6

Feb 20, 2013


EPrints supports JSON-P. It is therefore possible to include a list of publication with javascript on a different host without the need for the CORS headers.

Here an example using SUPSI's eprints repository. List of publications with creator being david huber:


    You will need the url to the JSON export of the desired search. In other words: perform the search, choose to export as JSON and copy the url. In my case the url was:

    Append to that url the JSONP part:

    Replace functionName with any desired function name. As expected by JSONP, the new URL will return a javascript that can be used with a script tag and will pass to functionName an array of publication objects.
    <script type="text/javascript" src="the JSONP URL"></script>
    This script tag can also be injected in the DOM when needed. For instance at DOM ready with the following JQuery code:
    // execute when DOM is ready
    $(function() {
      $(document.body).append("<script type='text/javascript' src='the JSONP URL'></script>");

    Feb 13, 2013

    C++ Polymorphic

    Used to Java I was quite surprised to discover that the RTTI of C++ works "polymorphic" only when the classes contain at least one virtual method. This means that if we have two classes, A and B where B inherits from A, and we ask for the typeid of an instance of B from a dereferenced A pointer, RTTI will tell us the type is B only if A has a virtual method otherwise it will tell us the type is A.

    This is best shown in code:

    #include <iostream>
    #include <typeinfo>
    class A { };
    class B : public A { };
    class VA {
      virtual void dummy(){ }; 
    class VB : public VA { };
    int main() {
      B* b = new B; // typeid is B, ok
      A* a = new B; // typeid is A!
      std::cout << "b: " << typeid(*b).name() << std::endl;
      std::cout << "a: " << typeid(*a).name() << std::endl;
      VB* vb = new VB; // typeid is VB, ok
      VA* va = new VB; // typeid is VB, just like java :-)
      std::cout << "vb: " << typeid(*vb).name() << std::endl;
      std::cout << "va: " << typeid(*va).name() << std::endl;
      return 0;
    will output the following:
    b: 1B
    a: 1A
    vb: 2VB
    va: 2VB
    The second line tells us that the type is A even if we created the object with "new B".

    This implies that we will not be allowed to dynamic_cast an A pointer to a B one. gcc will reports that the cast is not permitted becase the "source type is not polymorphic".

    A* a = new B;
    B* c = dynamic_cast<B*>(a); // compilation error
    It is, however, perfectly fine to cast the classes with the virtual method:
    VA* va = new VB;
    VB* vc = dynamic_cast<VB*>(va);