Wednesday, December 13, 2017

A div with a post-it 3D look

This just caught my eye while reading this thing. At first I searched for the image, but to my surprise it was all about CSS sorcery:

<html>
  <head>
    <style>
      .postit {
        position: relative;
        display: inline-block;
        width: 250px;
        border-bottom-right-radius: 36px 12px;
        padding: 15px 15px 10px 10px;
        border: 1px solid #e0dcbf;
        background-color: #fff8dc;
        margin-bottom: 12px;
      }
      .postit::after {
        content: "";
        display: block;
        position: absolute;
        width: 80%;
        height: 30px;
        bottom: 18px;
        right: 18px;
        z-index: -1;
        transform: rotate(3deg) skew(8deg);
        box-shadow: 13px 18px 6px rgba(0,0,0,0.3);
      }
    </style>
  </head>
  <body>
    <div class="postit">text</div>
  </body>
</html>

Saturday, December 9, 2017

A C++ container which keeps insertion order

C++ is a poorly designed programming language, and I live a love-hate relatioship with it.

On my vacation days, when working on WinLamb for the next version of SRTEd, I needed a container to keep track of the order the elements were inserted. Among the many useless obscure things that C++ has, it doesn’t have such a container. So I had to write one, which after much struggle I named it the insert_order_map.

Usage example, including iterator support for C++11 range-based for loop:

insert_order_map<wstring, wstring> all = {
  { L"initial", L"blab" },
  { L"initial2", L"bleb" }
};

all[L"first"] = L"abcdef";
all[L"second"] = L"123456";

for (insert_order_map<wstring, wstring>::entry& e : all) {
  wstring key = e.key;
  wstring val = e.value;
}

At first I wondered about using a sentinel linear search, line the one used within store. But then I realized that 99% of the time I’ll be using a string as the key with few elements inserted, thus the initial copy of the string at each search would take away the performance gains of the sentinel algorithm. So I decided to stick to an ordinary linear search.

Friday, December 8, 2017

Avast antivirus sucks

Last month, after having had enough of Avira antivirus intrusive ads popping on my screen all day, I removed it and installed Avast. Then I started seeing my whole trusty Windows 7 x64 going slow, mainly when switching between processes, but until then I blamed the almost 8 years old computer.

That was until yesterday, while debugging C++ in Visual Studio, when I noticed an Avast DLL being loaded in the console. What the hell? It seems that Avast was somewhat injecting its DLL everywhere, making everything go slow. I immediately uninstalled Avast, and instantly my computer became fast as before.

So far I’m running no antivirus program, and I’m in doubt if I really need one. It feels a bit insecure, but at the same time so... fresh.