DNS Configuration with Bind 9 on Fedora 17

Hi,

I am reporting a misconfiguration (or no-configuration?) of the Fedora 17 named service (I’m hosting the server at ovh.com). Maybe it’ll be useful for other people.

So, I’ve been struggling to find why it didn’t work for the past few days while I have the entry for wox-xion.ch registered in the correct name server of ovh, as well as a full correct zone for wox-xion.ch on my server:

; BIND db file for wox-xion.ch
$TTL 86400
 
@       IN      SOA     wox-xion.ch.      xion.luhnis.gmail.com. (
                        2013021502	; serial number YYYYMMDDNN
                        28800           ; Refresh
                        1H            ; Retry
                        1W          ; Expire
                        1H           ; Min TTL
			)
 
		A       94.23.21.95
                NS      ks370328.kimsufi.com. 
                NS      ns.kimsufi.com. 
 
; mail @ google
		MX  1		aspmx.l.google.com.
		MX  5		alt1.aspmx.l.google.com.
		MX  5		alt2.aspmx.l.google.com.
		MX  10		aspmx2.googlemail.com.
		MX  10		aspmx3.googlemail.com.
 
1		PTR	wox-xion.ch.
2		PTR	wox-xion.ch.
 
$ORIGIN wox-xion.ch.
		IN	A	94.23.21.95
wox-xion.ch.	IN	A	94.23.21.95
; more subdomains afterwards ...

I finally found out a small change in the current named.conf which made everything … die.
In the options section, I had

listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };

which should be (and is now):

listen-on port 53 { any; };
listen-on-v6 port 53 { any; };

Of course, all the name services on the server were saying “it’s ok, it works!”, but nothing from the world outside…

Zigfy and Ngjs

Hi,

I’ve started a new gallery website, which is not yet available on http://gallery.wox-xion.ch, but already on github. It’s split into two parts:

  1. Zigfy – a plugin for JQuery which creates entire image galleries from scratch
  2. NGJS – a Node.js server which will take care of the new galleries soon

The new gallery website is using:

  • Node.js for the server  / programming language
  • Express.js as server-side web application framework
  • Angular.js as client-side application framework
  • Jade as template engine
  • Less as css preprocessor

More to come, hopefully soon. By the way, the current server is running here.

My name is 802.11

names-wordle2

For my SHS (Social & Human Sciences) semester project, I decided to track wifis and especially access point names.

It’s funny what you can get with simple tracks.

The project is available here. I’ll put the tracker source code there soon.

Gesture Tracking library

full

I haven’t had time to release the code of the gesture tracking library I developed at the beginning of this year till now.

And here it is.

Given the tracking library, the ping pong application I made is really simple. Here is actually its code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/* 
 * File:   main.cpp
 * Author: Alexandre Kaspar
 *
 * Created on 9. janvier 2012, 14:34
 */
 
#include <cstdlib>
#include <iostream>
#include <cmath>
// OpenCV
#include <opencv2/video/tracking.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
//// GL and GLU
//#include <GL/gl.h>
//#include <GL/glu.h>
//#include <GL/freeglut.h>
// our library
#include <Capture.h>
#include <Frame.h>
#include <Geometry.h>
#include <Marker.h>
#include <algorithm>
 
// namespaces
 
using namespace cv;
using namespace std;
 
// global variables
bool smooth = false; //< whether to smooth the camera image
bool game = false; //< whether the game is running
bool paused = false; //< running status
 
int getFilterFlag() {
    int flag = Capture::FLIP;
    if (smooth) {
        flag |= Capture::GAUSS_SMOOTH;
    }
    return flag;
}
 
/**
 * Mouse event handler
 * 
 * @param event the mouse event
 * @param x the new mouse abscissa
 * @param y the new mouse ordinate
 */
void onMouse(int event, int x, int y, int, void*) {
    // the mouse event
    switch (event) {
        case CV_EVENT_LBUTTONUP:
            // we restart the game
            game = true;
            break;
    }
}
 
/**
 * Process a keyboard event
 * 
 * @param histimg the histogram image
 * @return whether to keep running or not (then exit)
 */
bool pollKeys() {
    char c = (char) waitKey(10);
    if (c == 27) {
        // we're done, let's exit
        return false;
    }
    // possible key events
    switch (c) {
        case 's':
        case 'g':
            smooth = !smooth;
            break;
        case 'p':
            paused = !paused;
            break;
        default:
            ;
    }
    return true;
}
 
typedef Point2d PVect;
 
PVect computeSpeed(PVect v, double s) {
    // v has values in [-1;+1]
    double angle = atan2(v.y, v.x);
    return PVect(s * cos(angle), s * sin(angle));
}
 
PVect processSpeed(PVect v, double dy) {
    double Y = v.y + dy;
    double norm = sqrt(v.x * v.x + Y * Y);
    return PVect(-v.x / norm, Y / norm); // -x for the x-bounce
}
 
void drawMargin(Mat& image, int x) {
    line(image, Point(x, 0), Point(x, image.rows),
            Scalar(0xFF, 0xFF, 0xFF), 2, CV_AA);
}
 
/*
 * Boot method
 */
int main(int argc, char** argv) {
 
    cout << "Init [game]..." << endl;
 
    geom::initTimestamp();
 
    Capture cap;
 
    cout << ". init markers" << endl;
    MarkerRef leftMarker = Marker::load("markers/y1.m");
    Scalar leftColor(0x00, 0xFF, 0x00);
    int lastLeftPos = 0;
    MarkerRef rightMarker = Marker::load("markers/r1.m_patch.png");
    Scalar rightColor(0x00, 0x00, 0xFF);
    int lastRightPos = 0;
 
    if (leftMarker && rightMarker) {
        // we're ok
        cout << ". marker loaded !" << endl;
    } else {
        cerr << "Couldn't load the markers..." << endl;
        return 1;
    }
 
    // start camera capture
    cap.open(0);
 
    if (!cap.isOpened()) {
        cerr << "***Could not initialize capturing...***\n";
        return -1;
    }
 
    const string window = "Marker Ping PONG !";
 
    namedWindow(window, 0);
    setMouseCallback(window, onMouse, 0);
 
    // game parameters
    const int margin = 50; //< pixel x-margin
    const int pingsz = 100; //< ping pong p
    const int rectsz = 20; //< ball radius
    const int speed = 30; //< ball velocity
    PVect recPos; //< the ball position
    PVect recSpeed; //< the ball speed
    int win = 0; //< the winner 1=left, 2=right
 
    cout << ". starting the loop" << endl << endl;
    cout << "Click with the mouse to restart the game." << endl << endl;
 
    // the loop
    Frame frame;
    Mat image;
    for (;;) {
 
        if (!paused) {
            // we update the filter flags
            cap(getFilterFlag());
            // we update the frame from the video capture
            cap >> frame;
            // and check that there's something
            // otherwise => we stopped using the camera
            if (frame.empty())
                break;
        }
 
        // stage constants
        const int width = frame.cols();
        const int height = frame.rows();
 
        // the image we'll draw onto
        frame(Channel::BGR).copyTo(image);
 
        // ### 1 = detect the marker => update positions
 
        // the left player
        if (leftMarker->detect(frame)) {
            point target = leftMarker->lastPoint();
 
            // we display the marker location
            rectangle(image,
                    Rect(target.x - 10, target.y - 10, 20, 20),
                    leftColor);
 
            // we set the new pos
            lastLeftPos = target.y;
        }
        // the right player
        if (rightMarker->detect(frame)) {
            point target = rightMarker->lastPoint();
 
            // we display the marker location
            rectangle(image,
                    Rect(target.x - 10, target.y - 10, 20, 20),
                    rightColor);
 
            // we set the new pos
            lastRightPos = target.y;
        }
 
        // ### 2 = draw the players
        drawMargin(image, margin);
        if (leftMarker->getHistorySize() > 0) {
            // the display range
            Rect pad(0, std::max(0, lastLeftPos - pingsz), margin, 2 * pingsz);
            rectangle(image, pad, leftColor, CV_FILLED);
        }
        drawMargin(image, width - margin);
        if (rightMarker->getHistorySize() > 0) {
            // the display range
            Rect pad(width - margin, std::max(0, lastRightPos - pingsz),
                    margin, 2 * pingsz);
            rectangle(image, pad, rightColor, CV_FILLED);
        }
 
        // ### 3 = game logic
        if (!game) {
            // we put the ball at the center
            recPos = PVect(width / 2, height / 2);
            string title;
            Scalar color;
            switch (win) {
                case 0:
                    title = "Click to start";
                    color = Scalar(0x66, 0x66, 0x66);
                    break;
                case 1: // left won
                    title = "Left won !";
                    color = leftColor;
                    break;
                case 2: // right won
                    title = "Right won !";
                    color = rightColor;
                    break;
            }
            // we display the title
            Size textsize = getTextSize(title, CV_FONT_HERSHEY_COMPLEX, 2, 5, 0);
            Point org((width - textsize.width) / 2, 3 * height / 4);
            putText(image, title, org, CV_FONT_HERSHEY_COMPLEX, 2, color, 5, CV_AA);
        }
        // we draw the ball anyway
        circle(image, recPos, rectsz, Scalar(0, 0, 0), CV_FILLED, CV_AA);
 
        // the game in itself is simple
        if (game) {
            // the real thing happens here
            // 0=check won or not
            if (recPos.x < rectsz) {
                // left lost !
                win = 2;
                game = false;
            } else if (width - recPos.x < rectsz) {
                // right lost !
                win = 1;
                game = false;
            } else {
                // we compute the ball displacement
                if (recSpeed.x == 0) {
                    // we reset the direction
                    recSpeed = PVect(1.0, 0.0);
                }
 
                // the new position
                PVect v = computeSpeed(recSpeed, speed);
                recPos = recPos + v;
 
                // computation of the new speed
                PVect nextPos = recPos + v;
                if (nextPos.x < margin + rectsz) {
                    // check for x-bounce on left
                    if (abs(lastLeftPos - nextPos.y) < pingsz + 0.75 * rectsz) {
                        // we bounce !
                        // we use the history to check the pad "speed"
                        // orientation and put that in the ball new speed
                        point disp = leftMarker->lastDisplacement();
                        double orient = disp.y / double(height); // div by disp.t ?
                        orient *= 5.0;
                        // => unit vector of (0,orient) + recSpeed
                        recSpeed = processSpeed(recSpeed + PVect(-1.0, 0.0), orient);
                    }
                } else if (width - nextPos.x < margin + rectsz) {
                    // check for x-bounce on right
                    if (abs(lastRightPos - nextPos.y) < pingsz + 0.75 * rectsz) {
                        // we bounce !
                        point disp = rightMarker->lastDisplacement();
                        double orient = disp.y / double(height); // div by disp.t ?
                        orient *= 5.0;
                        recSpeed = processSpeed(recSpeed + PVect(1.0, 0.0), orient);
                    }
                }
                if (nextPos.y < 0 || nextPos.y > height) {
                    // y-bounce
                    recSpeed = PVect(recSpeed.x, -recSpeed.y);
                }
            }
        }
 
        // ### END = display
        imshow(window, image);
        setMouseCallback(window, onMouse, 0);
 
        // check keyboard events
        if (!pollKeys()) {
            break;
        }
    }
 
    // all's done
    cout << "Done capturing." << endl;
    cout << "Bye." << endl;
    return 0;
}

While I hope it can be useful to someone. Feel free to dig into it, there’s nothing really complicated.

It uses :

Just tell me back if you achieved something interesting with it. ;)

Arghk

IMG_8114-small

Je pense que le mot raisonne assez fort dans ma tête.

En tout cas, j’en aurai fait quelque chose, au moins…

En fait, je suis en recherche d’un stage au Japon pour mon master… :-P

Qui plus est, je suis en train de lire “Le mythe de Sisyphe” de Camus. J’ai beaucoup apprécié “L’envers et l’endroit” et me devais d’aller un peu plus loin…

L’absurde, ou pas…

Japan Impact 2012

IMG_7229

Japan Impact a eu lieu le weekend passé (25 et 26 février 2012), et l’ambiance y était.

Qui plus est, une nouvelle gallerie lui est consacré.

OpenCV Ping Pong using color markers

MarkerPingPong

The library I started after the announce of the public release of Wuw from Sixth Sense on googlecode is now getting somewhat stable (and more importantly, it works).

Here is a video :

I will put the code on a public repository when I’ll have some time.
See you soon. :D

Pure virtual & constructors

So, I made a silly mistake which I didn’t know about, once again.

What’s wrong with the following (shortened) C++ class declaration ?

/**
 * Abstract color filter
 */
class ColorFilter {
public:
 
    virtual void reset(){
        adjust(0);
    }
 
    /**
     * Constructor using an initial patch
     * 
     * @param p the initial patch used to create the filter
     */
    explicit ColorFilter(const Mat& p)
    : patch(p){
      reset();
    }
 
    ColorFilter(const ColorFilter& orig) : patch(orig.patch){}
 
protected:
    /**
     * The base patch
     */
    const Mat& patch;
 
    /**
     * Adjust the filter (narrow or broaden 
     * depending on the given factor)
     * 
     * @param d the direction of change
     * @return whether it worked
     */
    virtual bool adjust(int d) = 0;
};

From Java, you would expect that you can call your abstract function from the constructor. And you’d be right.

But you’d be in Java…

In C++, the instantiation process is a bit different and the result is that when you call the base class, its constructor can only “see” what is around in the base class, but nothing from the possible derived-classes.

One of the several reasons you can read about on artima is that you have to initialize the elements of your class before doing anything, and of course, the first thing you do from the derived class is call the constructor of the base one.

Thus, when you’re in this base constructor, there’s still nothing initialized in the derived-level. And thus you cannot use any variable from there, and especially (more importantly) no pure virtual method since these are surely only accessible from the upper levels, and aren’t available at this moment.

In the example above, I’m calling a virtual method, but which in turn is calling a pure virtual one, which I cannot do at that moment of the initialization phase.

And now, to go further, we could technically call virtual methods, but notice that they won’t behave as virtual methods since their upper-version isn’t reachable yet, so they behave as virtual function which aren’t overriden yet. Thus the following example (taken from a post on stackoverflow) prints 0 and not 1 :

#include <iostream>
struct base {
   virtual const int value() const {
      return 0;
   }
   base() {
      std::cout << value() << std::endl;
   }
   virtual ~base() {}
};
 
struct derived : public base {
   virtual const int value() const {
      return 1;
   }
};
 
int main(void) {
   derived example;
}

See you soon ;)

Galleries hivernales

Chalavornaire

Et déjà deux galleries pour cet hiver. A noter qu’une est la première de la série 2012 :

Il fait très froid ces temps-ci… bon ski malgré tout. :D

Operator unspecified-bool-type

I’ve been coding mostly in C++ these times (and will still given that the STL and boost are really easy to use). But I never stop being surprised by C++.

Recently, I’ve found yet another “new” operator I didn’t know from the shared_ptr documentation of boost. Here is its synopsis :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace boost {
 
  class bad_weak_ptr: public std::exception;
 
  template<class T> class weak_ptr;
 
  template<class T> class shared_ptr {
 
    public:
 
      typedef T element_type;
 
      shared_ptr(); // never throws
      template<class Y> explicit shared_ptr(Y * p);
      template<class Y, class D> shared_ptr(Y * p, D d);
      template<class Y, class D, class A> shared_ptr(Y * p, D d, A a);
      ~shared_ptr(); // never throws
 
      shared_ptr(shared_ptr const & r); // never throws
      template<class Y> shared_ptr(shared_ptr<Y> const & r); // never throws
      template<class Y> shared_ptr(shared_ptr<Y> const & r, T * p); // never throws
      template<class Y> explicit shared_ptr(weak_ptr<Y> const & r);
      template<class Y> explicit shared_ptr(std::auto_ptr<Y> & r);
 
      shared_ptr & operator=(shared_ptr const & r); // never throws
      template<class Y> shared_ptr & operator=(shared_ptr<Y> const & r); // never throws
      template<class Y> shared_ptr & operator=(std::auto_ptr<Y> & r);
 
      void reset(); // never throws
      template<class Y> void reset(Y * p);
      template<class Y, class D> void reset(Y * p, D d);
      template<class Y, class D, class A> void reset(Y * p, D d, A a);
      template<class Y> void reset(shared_ptr<Y> const & r, T * p); // never throws
 
      T & operator*() const; // never throws
      T * operator->() const; // never throws
      T * get() const; // never throws
 
      bool unique() const; // never throws
      long use_count() const; // never throws
 
      operator unspecified-bool-type() const; // never throws
 
      void swap(shared_ptr & b); // never throws
  };
 
  template<class T, class U>
    bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws
 
  template<class T, class U>
    bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws
 
  template<class T, class U>
    bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b); // never throws
 
  template<class T> void swap(shared_ptr<T> & a, shared_ptr<T> & b); // never throws
 
  template<class T> T * get_pointer(shared_ptr<T> const & p); // never throws
 
  template<class T, class U>
    shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r); // never throws
 
  template<class T, class U>
    shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r); // never throws
 
  template<class T, class U>
    shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r); // never throws
 
  template<class E, class T, class Y>
    std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p);
 
  template<class D, class T>
    D * get_deleter(shared_ptr<T> const & p);
}

And I started looking at it while thinking of the way weak_ptr uses its lock() method to generate a shared_ptr instance, which can be bound to a conditional block by creating the instance in an if-block :

shared_ptr<int> p(new int(5));
weak_ptr<int> q(p);
 
// some time later
 
if(shared_ptr<int> r = q.lock())
{
    // use *r
}

So unspecified-bool-type is a specialized bool cast for condition evaluation which shouldn’t be used for bool conversions. In fact, that unspecified-bool-type is just a typedef over another bool() operator, with some type tests behind.
So far, I’ve also seen another version of it (but that is only for C++11) as

explicit operator bool() const

which means it’s a bool conversion operator, but it cannot be used for implicit conversions.

See this article on artima about the safe bool idiom. There’s a lot to learn.

CSS Display

I’m currently working on the new gallery website (mostly JQuery) and was in troubles with floating div’s. If you want an element of block type to be put into a grid (or any continuous flow layout), you need to either :

  • use a non-static positioning such as absolute or fixed (note that relative doesn’t work here, because blocks get relative to each other, and you’re stuck);
  • use float to make blocks flow, and then space them correctly.

Or well, these were the solutions I knew about.

The absolute/fixed positioning isn’t a good solution, because it clearly depends on how many elements you have, and if you don’t know that beforehand, then you’re screwed ((unless you accept a strict layout. I’ve been using this positioning a lot, but it’s not done for data flow, it’s for the base layout … or games)). Anyway, that didn’t work with me.

The float version is looking nice, as long as you don’t need it into a specific layer. That was my problem, because as soon as you set a float block, it won’t be in the normal block-size constraints, and thus if your parent container has a specific size constraint… well you’re screwed again, because the floats won’t obey it.

What then ? Maybe the float item on a list ?

You would think you can control the positioning of the outer list, but the float is a float, and it doesn’t obey any size constraint ((it does as long as there’s no need to go further, or if there are other elements which fill the space.)), so that you can encapsulate it as much as you want, it still doesn’t work.

And finally, I ran into this page about the possible display values in CSS. There were many more possible values ((and it seems there are even more, but  not all standardized, see w3cschool)) than I thought of :

inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inherit

And there was my solution, the value inline-block which results in blocks which are inlinable. Thus you can apply a size to them as you would with blocks, but still use the inline properties to have a continuous flow of blocks on the page, while keeping correct size constraints.

:)

Lights of EPFL

The Odyssea building of EPFL

A new gallery has started about lights, but now in Switzerland, for EPFL. It features some pictures of our great Rolex Learning Center. :)
I have no idea why they’ve put palm trees near the BM building, it’s snowing ! Why do they put them outside ? :?

Also note that I’ve taken some panoramas I won’t directly link on the galleries, since they are somewhat ((really)) heavy.

The first one is a panorama of the Geneva Lake ((~ 250MB)) from the EPFL/Unil sport center of Dorigny.

The second one is yet another composed picture of Lausanne ((far smaller, ~10MB)) from Chauderon over Vigie.