The regex [,-.]

A funny post I wanted to archive

May 29, 2022  |  🏷️Regex

Thoughts on having a sorted, modifiable list in MySQL

I had a discussion with a colleague on how to persist a sorted (linked?) list in MySQL, and would like to write down my thoughts on this since this is likely a problem I will face in the future. There must be a better way of thinking about this than I’ve come up with. If you have an idea, don’t hesitate to send me an email. Problem description We have a sorted list of a generic length....

November 24, 2021  | 

Simple Docker MySQL-Server on RAM

A simple docker command to start MySQL on a tmpfs. Things to note: Mounting localtime affects MySQL server timezone You need to have a my.cnf at the given location ($HOME/docker/mysql/my.cnf) You probably need to create /var/lib/mysql before running the command Setting sql_mode="" is probably not needed for most applications. sudo docker run -d \ --name mysql7 \ -v/usr/share/zoneinfo/Europe/Stockholm:/etc/localtime:ro \ -v$HOME/docker/mysql/my.cnf:/etc/my.cnf \ -e MYSQL_ROOT_PASSWORD=root \ -e MYSQL_ROOT_HOST='%' \ -p3306:3306 \ --mount type=tmpfs,destination=/var/lib/mysql \ mysql/mysql-server:5....

Thoughts on collation in an international database in MySQL

When you have an international database, how do you make sure that the collation is correct for all locales? Here are some thoughts. Note that you have to be careful when mixing collations in queries or SQL will complain. Table with virtual, generated columns CREATE TABLE `note` ( `id` bigint NOT NULL AUTO_INCREMENT, `text` varchar(256) DEFAULT NULL, `text_swedish` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_swedish_ci GENERATED ALWAYS AS (`text`) VIRTUAL, `text_danish` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_danish_ci GENERATED ALWAYS AS (`text`) VIRTUAL, ....

October 6, 2021  | 

Curated list of interesting programming talks / lessons

Curated list of interesting talks / lessons Psychology Jonathan Blow - Techniques for dealing with lack of motivation, malaise, depression Lists Conf42: Cloud Native 2021 Logging Making Logs Work for you with Fluentd Caching Architectural Caching Patterns (for Kubernetes) - Good caching primer Docker Images Securing Containers by Breaking In - Good image security primer

Java Tools Cheatsheet

I have always neglected to write down java tools and commands that I use for troubleshooting. I will try to put in on this page. Memory and Threads There are many tools to measure java memory. In my experience, the easiest way to troubleshoot locally is to hook your development environment up to VisualVM. There are even plugins for it in e.g. IntelliJ. It is probably possible to do this to a production server as well, but that would likely impact performance....

Optimizing MySQL Queries et. Indexes

Things I have learned from troubleshooting mySQL queries Links Index och prestanda i MySQL Join types (from explain) MySQL Profiling Commands # Run query without cache SELECT SQL_NO_CACHE * from users where name like 'Ol%'; # Profiling SET SESSION profiling = 1; SHOW PROFILES; SHOW PROFILE FOR QUERY 3; SHOW STATUS LIKE 'Last_Query_Cost'; How to index/optimize Optimize OR Example: SELECT * FROM users where customerNumber='qwe' OR birthDate='2020-01-01'; You need an index for each OR, which will create a merge index on modern innoDB....

May 24, 2020  | 

Remove subfolder from all git history

# Remove DIRECTORY_NAME from all commits, then remove the refs to the old commits # (repeat these two commands for as many directories that you want to remove) git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch DIRECTORY_NAME/' --prune-empty --tag-name-filter cat -- --all git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d # Ensure all old refs are fully removed rm -Rf .git/logs .git/refs/original # Perform a garbage collection to remove commits with no refs git gc --prune=all --aggressive

February 27, 2020  |  🏷️Git

Using black or white text depending on background color

One problem which I encounter time and time again when creating a webpage or applications is matching text color with a changing background color. When creating a GUI you usually create a lot of white boxes with a black text on it, just to get sizes and stuff matching. Then later a designer or customer decides on a theme which affects how that box looks. Most of the time the background and text colors are hand-selected so they match well enough, but from time to time you have to create a box which can change background color on demand, and then you have to have the text color matching to make the box readable....

May 11, 2019  | 

Java Regex Cheatsheet

Escaping strings in regex replace s.replaceFirst(Pattern.quote("text to replace"), Matcher.quoteReplacement("replacement text"));

March 14, 2019  |  🏷️Regex