Select orthographic mistake with the mouse pointer and press Ctrl+Enter. Let’s make our language cleaner!
Якщо помітите помилку на цій сторінці, будь ласка, виділіть її вказівником миші та натисніть Ctrl+Enter. Зробімо наше мовлення чистішим!

2007-04-11

Base64 transformations in C++

There appeared a task to encode a binary data to base64 and then decode it back. There’re many solutions, but this one I liked very much.

#include "boost/archive/iterators/base64_from_binary.hpp"
#include "boost/archive/iterators/binary_from_base64.hpp"
#include "boost/archive/iterators/transform_width.hpp"
#include <string>
#include <iostream>

using namespace std;
using namespace boost::archive::iterators;

typedef
    base64_from_binary<
        transform_width<string::const_iterator, 6, 8>
        > base64_t;

typedef
    transform_width<
        binary_from_base64<string::const_iterator>, 8, 6
        > binary_t;

int main()
{
    string str("Hello, world!");
    cout << str << endl;
    string enc(base64_t(str.begin()), base64_t(str.end()));
    cout << enc << endl;
    string dec(binary_t(enc.begin()), binary_t(enc.end()));
    cout << dec << endl;
    return 0;
}

It’s simple enough, isn’t it? But the world is not ideal, and because of a bug decoding doesn’t work, as expected. Fortunately, the bug can be worked around with a little hack.

2007-04-10

Golden gate

The short animation Golden gate came to my mind, when I saw an unsecured door in a supermarket today. Really amazing! How haven’t I noticed it yet?

2007-04-09

First milonga

It happend indeed! The other day I visited the first in my life tango milonga. After three unsuccessful attempts.

Well, I’m astonished, not deeply impressed. But I think I’ll like them in the nearest future. The music of good quality is not loud, one can just seat and have chat with others.

I felt that dancing on milongas would give me a masterfulnes and some certainty that I’m doing well, that my experience is portable indeed. It’s not an assumtion, it’s a fact!

2007-04-02

It happens sometimes...

SELECT
 orig.id, orig.plinkSerial, orig.msgIndex, orig.address, orig.method,
 orig.picPath, orig.eventType, orig.location,
 IF (trans.translation IS NULL, orig.template, trans.translation) as template
FROM
(SELECT
   m.id, m.plinkSerial, m.msgIndex, m.address, m.method, m.picPath,
   e.eventType,
   g1.value as location, g2.value as template
  FROM `eventMessages` as m, `events` as e,
   `global` as g1, `global` as g2
  WHERE m.msgIndex=e.msgIndex
   AND g1.name=e.locationId AND g1.tableId=6
   AND g2.name=e.profileId AND g2.tableId=8
   AND m.status=1) as orig
 LEFT OUTER JOIN
 (SELECT
   v.capStr as translation, w.serial, n.name
  FROM
   `captionVal` as v,
   `captionName` as n,
   `groups` as g,
   `webcoms` as w
  WHERE
   v.capId=n.captionNo AND
   v.languageId=g.lang_id AND
   g.groupId=w.grp) as trans
  ON trans.serial=orig.plinkSerial AND trans.name=orig.template

Two Olyas

Sit down between two Olyas, make a wish, and they will make it real in the evening”.