Skip to content

Instantly share code, notes, and snippets.

@dmagda
dmagda / movies_recommendations_snippet.md
Created January 9, 2024 16:18
Movies Recommendations Snippet

"Movies Recommendations"

client.sql(
    "SELECT id, title, overview, vote_average " +
    "FROM movie WHERE vote_average >= 7 " +
    "AND genres @> \'[{\"name\": \"Science Fiction\"}]\'" +
    "AND 1 - (overview_vector <=> :prompt_vector::vector) >= 0.7 " +
    "ORDER BY overview_vector <=> :prompt_vector::vector LIMIT 3")
 .param("prompt_vector", promptEmbedding.toString())
@dmagda
dmagda / kong_and_yugabytedb.md
Last active January 8, 2024 22:08
Starting Kong on YugabyteDB

Create a custom Docker network:

docker network create custom-network

Start YugabyteDB:

rm -r ~/yb_docker_data
mkdir ~/yb_docker_data
@dmagda
dmagda / order_snippet.md
Created August 30, 2023 15:18
orders snippet
orders = jdbcTemplate.query(
    "SELECT * FROM pizza_order WHERE id = ? and location = ?::store_location",
    (prepStmt) -> {
        prepStmt.setInt(1, id);
        prepStmt.setString(2, location);
    },
    new OrderRowMapper());
@dmagda
dmagda / uninstall_custom_k3s_build.md
Created July 24, 2023 19:33
Uninstall Custom K3s Build
  1. Stop all the K3s processes:
    sudo kill $(ps aux | grep 'k3s' | awk '{print $2}')
  2. Create the k3s_uninstall.sh script with the following content and execute it:
    #!/bin/sh
    set -x
    systemctl stop k3s

systemctl disable k3s

@dmagda
dmagda / k3s_yugabytedb_final.md
Last active July 21, 2023 15:55
Kubernetes on YugabyteDB: Final Instruction

Start YugabyteDB Instance

rm -r ~/yb_docker_data
mkdir ~/yb_docker_data

docker network create custom-network

docker run -d --name yugabytedb_node1 --net custom-network \
  -p 15433:15433 -p 7001:7000 -p 9000:9000 -p 5433:5433 \
@dmagda
dmagda / query_with_builder.md
Created May 16, 2023 16:35
Generating Query with StringBuilder
                StringBuilder queryString = "insert into test (id, f1) values ";
                
                // add placeholder for values
                for (int counter = 0; counter <= 100; counter += 1) 
                    queryString.append("(?, ?),");

                // replace the trailing ',' with a ';'
                queryString.replace(queryString.length() - 1, queryString.length(), ";");
@dmagda
dmagda / Chinook_PostgreSql_utf8.sql
Created February 23, 2023 15:45
Chinook Database
This file has been truncated, but you can view the full file.
/*******************************************************************************
Chinook Database - Version 1.4
Script: Chinook_PostgreSql.sql
Description: Creates and populates the Chinook database.
DB Server: PostgreSql
Author: Luis Rocha
License: http://www.codeplex.com/ChinookDatabase/license
********************************************************************************/
@dmagda
dmagda / join_algorithm_types.md
Last active February 4, 2023 00:16
Join Algorithms

Nested Loop Join

// Loading records that satisfy the WHERE predicate.
// Can be an index or full table scan.
var subsetTable1 = getData(table1, wherePredicate);
var subsetTable2 = getData(table2, wherePredicate);

var resultSet = new LinkedList();
@dmagda
dmagda / outage_demo.md
Last active December 20, 2022 16:01
YugabyteDB Outage Demo

YugabyteDB Outage Demo

Use this demo to showcase how YugabyteDB handles failures.

Start Cluster

Create the custom network:

docker network create custom-network
@dmagda
dmagda / mock_data_generation_postgres.md
Last active May 24, 2023 05:29
Mock data generation with built-in database capabilities

Mock data generation with built-in database capabilities

Relational databases such as PostgreSQL can do much more than store and return your application records. Those databases usually come with comprehensive compute capabitilies.

In this short note, let's review the generate_series function of PostgreSQL, then can generate mock data of various complexity.

  1. Create a sample table for time-series data:
    create table sensor (
      id int,