За что я ненавижу Eloquent ORM

Я обожаю тупой код. Тупой в том смысле, что даже через 10 лет, если заказчик попросит тебя внести изменения в него, ты сможешь сделать это не вникая во всю логику, даже будучи после пятничного корпоратива, ничего в старом коде не сломав. И тупой в том смысле, что не нужно прикладывать […]

The Magic of Laravel Macros

Ever wanted a piece of functionality in a part of Laravel that doesn’t exist? Let me introduce you to Laravel macros. Macros allow you to add on custom functionality to internal Laravel components. Let’s start with a simple example on the Request facade. Request::macro(‘introduce’, function ($name) { echo ‘Hello ‘ […]

Assignment to entry in nil map

Why does this program panic? var m map[string]float64 m[«pi»] = 3.1416 panic: assignment to entry in nil map Answer You have to initialize the map using the make function (or a map literal) before you can add any elements: m := make(map[string]float64) m[«pi»] = 3.1416

Convert uint64 to a String

We’ve already got a post on converting an integer to a string but the process of converting a variable of type uint64 to a string is a little different. For an int we can use Itoa(), but for an unsigned int 64 we can still use strconv but we can […]

Concurrency, Goroutines and GOMAXPROCS

When new people join the Go-Miami group they always write that they want to learn more about Go’s concurrency model. Concurrency seems to be the big buzz word around the language. It was for me when I first started hearing about Go. It was Rob Pike’s Go Concurrency Patterns video […]

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 […]

Повторная отправка HTTP-запросов в Guzzle с помощью RetryMiddleware

Если приложение обращается к каким-либо сторонним сервисам через API, часто встречается ситуация, что сторонний сервис временно недоступен, или перегружен. Т.к. от результатов запроса может зависеть дальнейшее выполнение скрипта, требуется предусмотреть такую ситуацию, и временный отказ внешнего сервиса не должен вызывать серьезных сбоев в работе приложения. Одним из решений будет повторная […]

How to determine the size of MySQL databases and tables

This article demonstrates how to determine MySQL database size and MySQL table size. You can do this by using the phpMyAdmin web interface or by using the command line. USING THE COMMAND LINE You can use the mysql command-line program to determine the sizes of MySQL databases and tables. To do this, […]

Использование констант в SELECT-запросах SQL

Любите ли вы «магические числа» в коде? Все эти if (a == 259)… Никто их не любит. И SQL-запросов это касается в той же степени, как и языков программирования. «Магические» числа делают код нечитаемым, любые изменения в нём будут головной болью, и нужно всегда избегать их, если есть такая возможность. […]

Как добавить сразу две связанные по ключу записи в базу при помощи SQL

Если перед вами стоит задача добавить некое словарное значение в одну таблицу, при этом, значение первичного ключа может вычисляться автоматически (из sequence, например) и тут же создать еще одну запись в другую таблицу, так, чтобы эта вторая запись ссылалась на первую (например, имела ID новой записи из первой таблицы в […]