development

How to: MySQL Get Database Name and Use in Another Query

How to: MySQL Get Database Name and Use in Another Query The following SQL query get the database name and use the name to run another query. SET @dbname = DATABASE(); ALTER DATABASE @dbname CHARACTER SET utf8 COLLATE utf8_unicode_ci; References https://stackoverflow.com/questions/8096550/mysql-determine-which-database-is-selected https://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8 https://stackoverflow.com/questions/49735318/mysql-how-to-find-current-database-assign-it-into-a-string-variable https://dev.mysql.com/doc/refman/5.7/en/set-variable.html

Read more
development

Database Collation and UTF8MB4

Database collation defines how characters are compared and hence the order of rows in query results. Popular Encodings UTF8: Uses 3 bytes for a character UTF8MB4: Uses 4 bytes for a character, so allows more characters. How to Decode Collation utf8mb4_unicode_520_ci UTF8MB4 Unicode 5.2.0 comparison for characters ci: Case Insensitive comparisons Reference https://stackoverflow.com/questions/37307146/difference-between-utf8mb4-unicode-ci-and-utf8mb4-unicode-520-ci-collations-in-m# https://www.monolune.com/mysql-utf8-charsets-and-collations-explained/ Written […]

Read more
development

Go, gorm, nested JSON and associations

Go, gorm, nested JSON and associations gorm provides a clean way to store a nested JSON with the relation of associations among tables. The following code creates a DB with three levels of nesting. package main import ( “encoding/json” “fmt” “github.com/jinzhu/gorm” _ “github.com/lib/pq” ) const ( host = “localhost” port = 5432 user = “postgres” […]

Read more
development

Mac OS X: role “postgres” does not exist

Install Postgres brew install Postgres Try to log in. $ psql -h localhost -d postgres -U postgres psql: error: could not connect to server: FATAL: role “postgres” does not exist Create the user $ /usr/local/opt/postgres/bin/createuser -s postgres Start the server $ pg_ctl -D /usr/local/var/postgres start pg_ctl: another server might be running; trying to start server […]

Read more
development

Building a Video Conferencing Service With WebRTC

What I learned in WebRTC It’s a peer to peer communication protocol to transfer media, text, and data. It does need a server for the control path that includes device discovery and agreement. The process is called signaling. The signaling server is free of any protocol and just needs to make two or more WebRTC […]

Read more
development

Interface Quirks in Golang

An interface defines a set of methods. A struct type implements these methods and qualifies the object type as an interface type. However, how the struct implements the interface? There are two ways: As a pointer handler As a value handler Implementation with a struct value handler package main import ( “fmt” ) type Dummy […]

Read more
development

Design Pattern: Active Record

Active Record An Active Record Object represents a row in a DB table. The object has fields mapping to a column in the table and methods to access table data. Active Record connects classes to relational database tables to establish an almost zero-configuration persistence layer for applications. The library provides a base class that, when […]

Read more