Server Side Events offer an easy way to push data to clients. It’s much easier to implement than websockets or another technology. IF you stumble on the problem of connections not getting aborted, when clients closed the event resource, or if you see the data coming in chunks, you need to tweak your PHP server,… Continue reading Fixing Server Side Events and Connection Aborted Issues
Setting default values for requests the easy way
PHP 7 introduced the Null Coalesce Operator, and this is a very neat addition to PHP in practice. It will let you write code that is much easier to read and much more concise. You don’t have to wrestle anymore with isset() and ternary operators. Just write this: $offset = $_GET[‘offset’] ?? 0; It there… Continue reading Setting default values for requests the easy way
JSON Encoding of number problem
You can get quite surprising results if you try to json_encode something like json_encode($n[“number”]=3.53). echo json_encode($n[“number”]=3.53); 3.5299999999999998 Seems there is a bug in PHP, that parse floats with wrong precision. Currently json_encode() uses EG(precision) which is set to 14. The solution is to cast the number to string: echo json_encode($n[“number”]=(string) 3.53); “3.53” Another solution is… Continue reading JSON Encoding of number problem
How to format JSON in VIM/GVIM
The strength and beauty of VIM is the simple interaction with lots of external programs. To format any JSON file in VIM/GVIM: :% !jq . % means the file you’re working on, and `!jq` is run the external command `jq` That’s all. You need to have `jq` installed: sudo apt install jq whatis jq jq… Continue reading How to format JSON in VIM/GVIM
The ease and beauty of VIM
Never thought that I would write a post with the ease of VIM in the title. But honestly I tried a lot of editors still coming back to VIM. VIM is a lot more hackable then Atom. Probably because I like bash, python and javascript, while Atom is javascript hackable only. VIM is not easy… Continue reading The ease and beauty of VIM