Mihai Stancu

Notes & Rants

Separation of powers — 2017-02-12

Separation of powers

Puterile in stat sunt separate pe arii de competenta

Intentia acestei masuri este de a evita concentrarea puterii in mana unui singur om sau a unui grup restrans.

In majoritatea tarilor in care se aplica acest principiu puterile sunt separate in 3 ramuri: executivul (guvern), legislativul (parlament) si juridicul (ierarhia curtilor de justitie).

In cateva doar apar si alte ramuri: procuratura si auditul.

Procuratura ca putere separata in stat nu ma pot exprima ce scop sau efect ar avea.

Pe de alta parte o ramura independenta de audit in stat cred ca noua ne-ar prinde foarte bine din mai multe motive:

  • Monitorizarea respectarii regulamentelor interne ale Guvernului respectiv Parlamentului — ex.: ordine de zi suplimentata intempestiv; vot pe legi necitite; dezbateri publice inexistente; etc..
  • Puteri de sesizare a institutiilor competente in cazul unor astfel de incalcari.
  • Audit de performanta al sistemului bugetar.
  • Monitorizarea cheltuielilor public atat ca si destinatie cat si ca si valori raportate la valoarea pietei.
  • Monitorizarea licitatiilor publice.
Types of majorities —

Types of majorities

Exista mai multe tipuri de majoritati

  • Majoritati simple — 50%+1 din voturile exprimate
    Majoritati duble — compusa dintr-o majoritate simpla si o conditie sumplimentare precum:

    • numarul de voturi exprimate sa fie minim X% din populatia cu drept de vot (quorum)
    • majoritati castigate in 50%+1 dintre judete (sau state).
  • Majoritate calificata sau super-majoritate — cel mai adesea 66% din voturile exprimate (doua treimi) dar orice impunere de majoritate peste majoritatea simpla poate fi considerata cerinta de o super-majoritate.

Majoritatile duble si cele calificate sunt mecanisme care ajuta la limitarea tiraniei majoritatii astfel incat o majoritate simpla sa nu reuseasca sa impuna ceva nereprezentativ unei minoritati semnificative — ex.: 50%-1 nu este o minoritate de neglijat, nici 33% nu prea este.

Representativity in democracy —

Representativity in democracy

O democratie are obligatia morala de a reprezenta interesele tuturor cetatenilor sai.

O majoritate nationala chiar si de 99% nu poate suprima total interesele a 1% din cetateni — e imoral. Daca ar fi un contract cei 1% ar renunta la contract si ar pleca, dar nu este.

De ce? Simplu, cetatenii nascuti si crescuti pe teritoriu nu-si aleg tara, nu-si aleg, conationalii, nu intra in acea relatie printr-un contract, un acord comun si nu pot parasi acea relatie unilateral (poti renunta la cetatenie daca nu ai alta?).

Si atunci cetateanul este de facto un “captiv” al sistemului in care s-a nascut. Cu efort, dupa N ani ar putea obtine alta cetatenie dar chiar si atunci, N ani va fi fost “captiv” al acelui sistem.

Democracy is not the tyranny of the majority —

Democracy is not the tyranny of the majority

Democratia nu este acelasi lucru cu tirania majoritatii. Majoritatea nu poate decide in orice subiect.

Subiecte in care majoritatea nu are drept de decizie:

  • O majoritate nationala nu poate lua decizii care au impact exclusiv regional

    Exemplu: nu putem vota prin referendum national si nici in parlament ce drumuri si poduri sa construiasca Judetul Botosani (decat daca acele drumuri si poduri sunt drumuri nationale).

  • O majoritate nationala nu poate lua decizii de impact exclusiv asupra unei minoritati.

    Exemplu: nu putem vota prin referendum national si nici in parlament nimic despre cum se organizeaza intern tagmele profesionale medici, notari, avocati, etc. putem vota doar asupra impactului lor extern (legi de malpraxis, legi de raspundere a notarilor, etc.).

    Exemplu: nu putem vota prin referendum national si nici in parlament nimic despre interzicerea minoritatilor religioase.

“Pure democracy cannot subsist long nor be carried far into the departments of state; it is very subject to caprice and the madness of popular rage.” — John Witherspoon

“That a pure democracy if it were practicable would be the most perfect government. Experience has proved that no position is more false than this. The ancient democracies in which the people themselves deliberated never possessed one good feature of government. Their very character was tyranny; their figure, deformity.” — Alexander Hamilton

OrientDB @ eMAG TechLabs — 2016-01-21
JSON logformat and analysis — 2016-01-13

JSON logformat and analysis

Setup log format

So you’re tired of reading apache with column -t or need to process them with external tools maybe push them into a logstash? Say no more:

# Inside your virtual host definition

# Declaring your custom log format as a JSON structure
LogFormat '{"time":"%{%FT%T%z}t","response":{"status":"%>s","duration":"%D","length":"%B"},"request":{"method":"%m","host":"%V","port":"%p","url":"%U","query":"%q"},"client":{"ip":"%a","agent":"%{User-agent}i","referer":"%{Referer}i"}}' json_log

# Declaring an environment variable based on the type of file requested
SetEnvIf Request_URI "(\.gif|\.png|\.jpg|\.ico|\.css|\.js|\.eot|\.ttf|\.woff2?)$" request_static=1

# Declaring separate log files (one for static content, one for dynamic pages) with the new log format
CustomLog /path/to/log/access_static.log  json_log env=request_static
CustomLog /path/to/log/access_dynamic.log json_log env=!request_static

Tool to read/analyse the logs (manually)

A small tool called jq which basically reads each line and treats it as a JSON object, then outputs them pretty printed.

The package itself doesn’t have any dependencies and is readily available in linux repos.

Minimal usage:

echo '{"a": 1, "b": 2, "c": 3, "d": [{"e": 4}]}' | jq .
  "a": 1,
  "b": 2,
  "c": 3,
  "d": [
      "e": 4

Object restructuring:

echo '{"a": 1, "b": 2, "c": 3, "d": [{"e": 4}]}' | jq '{"c": .a, "e": .d[0].e}'
  "c": 1,
  "e": 4

Parsing string content as JSON:

echo '{"a":1,"b":"[{\"c\":2,\"d\":\"3\"}, {\"c\":3,\"e\":\"5\"}]"}' | jq '.["b"]|fromjson'
    "c": 2,
    "d": "3"
    "c": 3,
    "e": "5"


echo '{"a":1,"b":"[{\"c\":2,\"d\":\"3\"}, {\"c\":3,\"e\":\"5\"}]"}' | jq '.["b"]|fromjson|.[]|select(.c == 2)'
  "c": 2,
  "d": "3"
Object Oriented Databases — 2015-12-14

Object Oriented Databases

When I said what I said about SQL and RDBMSs and that other thing I said about tree structures and hierarchies in RDBMSs this is what I meant (mostly).

Throwback Sunday

I was browsing DB Engines (valuable resource this is) looking at popularity rankings for various database systems and comparing features looking for hot new tech when I started digging into Object Oriented Databases again.

I searched for (open source?) Object Oriented Database engines more intensely nearly 6 years ago (DB Engines wasn’t around back then) and I was disappointed to find that there was little to no popular demand for pure OODBMSs. Every damn google search or wiki lookup spat out RDBMSs conjoint twin little brother, the ORDBMSs (Object-Relational Databases) but that didn’t fit the bill I had in mind.

At that time I did find one open source and pure OODBMS EyeDB which currently looks like a dead project (damn!).

I might have missed (read disregarded) some niche products (read proprietary)

I don’t remember reading about InterSystems Caché or the underlying technology MUMPS which looks very ahead of its time.

But I do remember some important players on the market: Versant and Objectivity which were (and still are) proprietary, as well as another intriguing approach JADE a proprietary full-stack system including a DB.

But why all the fuss? Why not just RDBMS like every one else (freak)?

It felt very strange to me that developers would go gentle into that good night. Developers are inherently lazy creatures which would rather spend 20h automating a 22h long repetitive task than blankly toil away at the repetitive task.

Why would they ever accept to learn an entirely new set of concepts about handling data, read about the mathematics behind it, and mentally bridge the gap between one concept and the other every damn day of the rest of their careers (a repetitive task)?

Why jump through all of these hoops when an OODBMS can achieve the same performance as any RDBMS (or better) and also do away with the systems’ impedance mismatch of using an ORM? Not to mention all the work of building and maintaining an ORM having to debug for it or to limit your access to DBMS features because of the ORM.

Why bother writing a CREATE TABLE which contains virtually the same thing as your class declaration? …and then endeavor to burden yourself with manually keeping every future change from the TABLE or the class in perfect sync with one another? ..DRY anyone?

Versant Object Database for example describes an awesome schema versioning capacity in their product which allows you to simply give the DB the newly compiled class structure and VOD will handle updating old entries to the new schema (eagerly or lazily depending on your requirements).