Where do geniuses come from? (Review of the book "Surely You're Joking, Mr. Feynman")

So where do geniuses come from? Unfortunately, the answer is unknown to anyone.
But some interesting assumptions can still be found in the book "Surely You're Joking, Mr. Feynman!".

Many will say that it all depends on genes. Yes, undoubtedly, genes are the main clue of any personality. It cannot be done without them. But there are other equally important circumstances.

Only a free world gives birth to free individuals, ready to take as much as possible from life. And give back as much, if not more. Almost all winners of the Nobel Prize and other prestigious world awards belong to the free world. Oppressed continents, which were the majority not long ago, do not produce geniuses.

And it is the geniuses that are the progress of the world. Humanity needs them to improve the lives of every individual. Now this quality multiplies not in centuries, but in decades.

But let's get back toRichard Feynman.
The book is a vivid example of how a person enjoys life, in a good, sublime sense.

Encapsulation using closures in JavaScript

One of the unusual features of JavaScript is encapsulation using closures. It is unusual because in many other programming languages, this mechanism is implemented using classes. In JavaScript, however, there is a different mechanism that may seem strange if you don't understand the nuances of variables and functions.

If a variable or object in JavaScript is not placed inside any function, they become global. All global elements in JavaScript are properties of the global object. For browsers, this object is window. At the same time, statements like for, if, and others do not affect the visibility of variables.

Creating global variables is generally undesirable as it can lead to hard-to-detect errors and makes it difficult to transfer code to other applications.

Remove the default block sonata.admin.block.admin_list in SonataAdminBundle.

When using SonataAdminBundle and SonataBlockBundle, I wanted to remove the default block.

It doesn't provide much benefit, as it simply duplicates the functionality of the side menu on the dashboard.

When installing SonataBlockBundle, if we simply write in the configuration:

    default_contexts: [sonata_page_bundle]
    blocks: []

(in the future we will add our own blocks, but for now we just leave an empty array), we will catch an error.

Symfony Blog Bundle

HarentiusBlogBundle - bundle for a blog/simple portal (or complex, if using bundle inheritance and extension). View of this site.

As a backend, SonataAdminBundle is used. Implemented:

1. Admin panel (WYSIWYG, ckeditor), image/audio uploading, player.

2. Tags, categories, archives, tag cloud

3. Statistics

4. RSS-feed (requires modification)

5. "Smart" caching of everything, content is served very fast

To "ease the soul":

1. Tests

Iteration over a time period in PHP

Repeatedly had to work with a list of dates on php (by days, for example) if there is a start and end of the period ($dateStart, $dateEnd). For example, to synchronize working/non-working days for the DatePicker from jQueryUi with the backend. Or if you need to display reports by days.

I suggest several options for solving this problem, both the most obvious way and a more elegant way (as it seemed to me).

Symfony Widgets Bundle

Widgets Bundle - a bundle for easy widgets management. (Supports only widgets which require only client-side code for displaying). Includes both client side (for displaying) and admin side (adds admin classes and has a SonataAdminBundle dependency) functionality.

Can be used (for example) for adding counters, banners, advertising network codes (google adsense, etc).

Was created during this blog has been developing.

Caching Symfony controller

During developing this blog I invented one more bicycle for Caching Symfony controller. But first of all lets see how did this task arose.

For example, I have a list of categories, archives and tags on a sidebar. It is relatively easy to get last one (one query), but much harder to get list of categories and archives. For getting categories, we need to select trees (categories can be nested) and using subqueries inside queries get number of articles in every category (result is a little bit monster). For getting the archives list, we need iterate over all articles and gather list of years/months. All this actions isn't very sophisticated, but it is better to avoid them.