| WITH RECURSIVE traversed (id, name, path, `left`, `right`) AS ( | |
| SELECT id, | |
| name, | |
| CAST(JSON_ARRAY(id) AS JSON), | |
| `left`, | |
| `right` | |
| FROM binary_tree | |
| WHERE id = 1 | |
| UNION | |
| SELECT b.id, |
| -- When SQLite is compiled with the JSON1 extensions it provides builtin tools | |
| -- for manipulating JSON data stored in the database. | |
| -- This is a gist showing SQLite return query data as a JSON object. | |
| -- https://www.sqlite.org/json1.html | |
| -- An example table with some data | |
| CREATE TABLE users ( | |
| id INTEGER PRIMARY KEY NOT NULL, | |
| full_name TEXT NOT NULL, | |
| email TEXT NOT NULL, |
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" |
Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".
Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).
Let's dig in:
| package main | |
| import "fmt" | |
| func main() { | |
| slice := make([]int, 159) | |
| // Split the slice into batches of 20 items. | |
| batch := 20 |
| package main | |
| import ( | |
| "crypto/tls" | |
| "golang.org/x/crypto/acme/autocert" | |
| "log" | |
| "net" | |
| "net/http" | |
| ) |
Authorization and Authentication are hard. when you only have to implement them once (as you do within a monolith) instead of over and over again, it makes the developer happy :-), and maybe leads to less implementation failures.
When you have a bunch of microservices, this is something that has to be considered.
Implement it once or in every microservice, or something in between?
| package main | |
| import ( | |
| "encoding/json" | |
| "errors" | |
| "database/sql/driver" | |
| "fmt" | |
| "github.com/jmoiron/sqlx" | |
| _ "github.com/lib/pq" | |
| "log" |
| # Backup | |
| docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql | |
| # Restore | |
| cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE | |