While working with Magento 2.3.6 on Bixoto I hit a weird issue: the
bin/magento command-line tool was always eating all the RAM, even with a simple command:
$ ./bin/magento --help
PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 262144 bytes) in /home/baptiste/.../vendor/magento/module-store/Model/Config/Placeholder.php on line 146
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
The issue, as weird as it sounds, is an empty configuration value that causes Magento to end up in
an infinite loop.
When I installed Magento on my local machine, I deactivated HTTPS by setting web/secure/base_url
to NULL in the table core_config_data. This alone is the cause of the issue.
This has been reported to Magento but was closed because “it’s not a bug”. I don’t think
falling in an infinite loop on --help because some config value is NULL should really be a
normal behavior, but at least now you know how to solve it.
While following a tutorial to install Virtualbox in order to have docker working on macOS, I
hit an issue where the docker-machine create command fails with an error that looks like this:
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" at line 95 of file VBoxManageHostonly.cpp
If you search on the Web, everybody says you have to open the Security & Privacy settings window
and allow the Oracle kernel extensions to run. But I didn’t have it. I tried uninstalling
Virtualbox, re-installing through the official website, reboot, uninstall, re-install with
brew cask but I always had the issue. Some people reported having a failed Virtualbox
installation but mine seemed ok.
It failed, but it told me to check the Security & Privacy setting window. I did, and I had the
button everyone was talking about. I enabled the kernel extension, rebooted, and it worked.
Hope this can save some time to anyone having the same issue!
Code-Golf is the art of writing the shortest program in a given language that
implements some given algorithm. It started in the 90’s in the Perl community
and spread to other languages; there are now languages dedicated to
code-golfing and StackExchange has a Q&A website for it.
4clojure is a well-known website to learn Clojure
through exercises of increasing difficulty, but it has a lesser-known code-golf
challenge which you can enable by clicking on “Leagues” in the top menu.
If you check the code-golf checkbox, you then get a score on each problem that
is the number of non-whitespace characters of your solution; the smaller the
better.
The first thing you’ll note when code-golfing is that the reader syntax for
anonymous functions is a lot shorter than using fn:
; 18 chars(fn [abc](* (+ ab)c)); 13 chars#(* (+ %1%2)%3); 12 chars: -1 char because '%' is equivalent to '%1'#(* (+ %%2)%3)
Unfortunately you can’t have a reader-syntax function inside another
reader-syntax one, so you often have to transform the code not to use anonymous
functions.
for is a very powerful tool for that, because it allows you to do the
equivalent of map, and a lot more, with no function:
; invalid!#(map #(* 2%)%); 19 chars#(map (fn [x](* 2x))%); 17 chars#(map (partial * 2)%); 15 chars#(for [x%](* 2x)); Note that for this specific example; the best solution uses `map`:#(map + %%)
On some problems it can even be shorter than using map + filter:
When you must use a long function name in multiple places, it might be shorter
to let that function with a one-letter symbol:
; 120 chars#(clojure.set/difference(clojure.set/union%%2)(clojure.set/union(clojure.set/difference%%2)(clojure.set/difference%2%))); 73 chars#(let [dclojure.set/differenceuclojure.set/union](d(u%%2)(u(d%%2)(d%2%)))); Note that for this specific example; there is a 17-chars solution#(set (filter %2%))