How to open port in CentOS 7/Как открыть порт на CentOS 7

В версии CentOS 7 для управления iptables начали использовать firewalld, он в свою очередь управляется через команду firewall-cmd. В отличии от iptables, firewalld оперирует зонами и сервисами, а не цепочками и правилами. Каждому сетевому интерфейсу присваивается определенная зона, она может быть как пользовательская так и предустановленная. Список предустановленных зон: drop […]

Shorthand comparisons in PHP

You probably already know some comparison operators in PHP. Things like the ternary ?:, the null coalescing ?? and the spaceship <=> operators. But do you really know how they work? Understanding these operators makes you use them more, resulting in a cleaner codebase. Ternary operator The ternary operator is […]

Laravel relationship issues

Or in other words, dealing with complex database relations and Laravel models. Recently I had to deal with a complex performance issue in one of our larger Laravel projects. Let me quickly set the scene. We want an admin user to see an overview of all people in the system […]

How to Mock Final Classes in PHPUnit

Do you prefer composition over inheritance? Yes, that’s great. Why aren’t your classes final then? Oh, you have tests and you mock your classes. But why is that a problem? Since I started using final first I got rid of many problems. Most programmers I meet already know about the benefits of not […]

Switch with instanceof in PHP

There are situations where you need to check what class an object is. The easiest thing is just checking that with instanceof and a simple if statement. But that doesn’t look that good if you’ve got many cases: if($objectToTest instanceOf TreeRequest) { echo «tree request»; } elseif($objectToTest instanceOf GroundRequest) { […]

Constructors in Golang

There are no default constructors in Go, but you can declare methods for any type. You could make it a habit to declare a method called «Init». Not sure if how this relates to best practices, but it helps keep names short without loosing clarity. package main import «fmt» type […]

delete map[key] in go?

package main func main () { var sessions = map[string] chan int{}; delete(sessions, «moo»); } seems to work. This seems a poor use of resources though! Another way is to check for existence and use the value itself: package main func main () { var sessions = map[string] chan int{}; […]

Технология CRUD-матрицы. Практический опыт

Технология CRUD-матрицы — это хороший инструмент для каждого члена Agile-команды на протяжении всего жизненного цикла продукта. CRUD-матрица позволяет наладить адекватный диалог с клиентом и выявить дублирование функционала, а также устранить противоречивость модели. Что касается оценки времени, то в этом моменте CRUD-матрица значительно уступает такому инструменту, как “planning poker”, который позволяет […]

Find the total size of certain files within a directory branch

23 The ultimate answer is: { find <DIR> -type f -name «*.<EXT>» -printf «%s+»; echo 0; } | bc and even faster version, not limited by RAM, but that requires GNU AWK with bignum support: find <DIR> -type f -name «*.<EXT>» -printf «%s\n» | gawk -M ‘{t+=$1}END{print t}’ This version […]