From 12e5244cc80c82eb26cce7a270eecd656025b5b4 Mon Sep 17 00:00:00 2001 From: io42630 Date: Wed, 2 Apr 2025 10:55:21 +0200 Subject: [PATCH 1/5] format --- README.md | 24 +++++++++++------------- data/{README.adoc => README.md} | 5 ++--- 2 files changed, 13 insertions(+), 16 deletions(-) rename data/{README.adoc => README.md} (59%) diff --git a/README.md b/README.md index 9af66ed..a4cf77e 100755 --- a/README.md +++ b/README.md @@ -1,24 +1,22 @@ -### Field Kit +# Field Kit Meant as a collection of easy-to-use tools that cover common use cases. WIP. -#### List of Use Cases +## List of Use Cases * Parsing - ** PDF - ** CSV + * PDF + * CSV * Processing - ** Elastic (?) + * Elastic (?) * Deployment - ** Host (?) - ** Servlet Container - ** Frontend (?) - ** Data Visualization (?) + * Host (?) + * Servlet Container + * Frontend (?) + * Data Visualization (?) - - -### Setup +## Setup * WIN -** pyenv win + * pyenv win diff --git a/data/README.adoc b/data/README.md similarity index 59% rename from data/README.adoc rename to data/README.md index 556f32e..1601d2b 100755 --- a/data/README.adoc +++ b/data/README.md @@ -1,6 +1,5 @@ -= DATA -:toc: +# DATA +## API -=== API * https://pokeapi.co/docs/v2 From 93044aa90544a177722c92611f55a81242b9106b Mon Sep 17 00:00:00 2001 From: io42630 Date: Tue, 15 Apr 2025 08:53:30 +0200 Subject: [PATCH 2/5] + doc --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4cf77e..82ded49 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Field Kit -Meant as a collection of easy-to-use tools that cover common use cases. -WIP. +* a collection of easy-to-use tools that cover common use cases. +* also serves as workspace for exercises. + * those results should be migrated to their respective `about-foo` once some knowledge is consolidated. ## List of Use Cases From 1547543d014ef84b0081e7444cdacbd9db7decc0 Mon Sep 17 00:00:00 2001 From: io42630 Date: Tue, 15 Apr 2025 08:54:15 +0200 Subject: [PATCH 3/5] + haskell stub --- .tool-versions | 1 + README.md | 5 +++++ haskell-kit/hello.hs | 4 ++++ 3 files changed, 10 insertions(+) create mode 100644 haskell-kit/hello.hs diff --git a/.tool-versions b/.tool-versions index cbe95a6..87f20cb 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,3 @@ java temurin-21.0.3+9.0.LTS maven 3.9.6 +ghc 9.8.4 diff --git a/README.md b/README.md index 82ded49..40e3914 100755 --- a/README.md +++ b/README.md @@ -21,3 +21,8 @@ * WIN * pyenv win + + +### Haskell Kit + +asdf plugin add ghc diff --git a/haskell-kit/hello.hs b/haskell-kit/hello.hs new file mode 100644 index 0000000..6e5b5ab --- /dev/null +++ b/haskell-kit/hello.hs @@ -0,0 +1,4 @@ +main = +-- print "Hello World!" +-- putStr "Hello World!" + putStrLn "Hello World!" From 6c93896de93de025394b042f44d1a59b36635f55 Mon Sep 17 00:00:00 2001 From: io42630 Date: Tue, 15 Apr 2025 08:55:41 +0200 Subject: [PATCH 4/5] + add mariadb --- .env-tp | 2 ++ .gitignore | 1 + docker-compose.yaml | 13 +++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 .env-tp diff --git a/.env-tp b/.env-tp new file mode 100644 index 0000000..93943f7 --- /dev/null +++ b/.env-tp @@ -0,0 +1,2 @@ +MYSQL_ROOT_PASSWORD=password +MYSQL_PASSWORD=password diff --git a/.gitignore b/.gitignore index 50e45c4..a7e806c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ **/target/ *.iml +*.env diff --git a/docker-compose.yaml b/docker-compose.yaml index b1c88d8..9dc0f06 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,6 +23,19 @@ services: - ME_CONFIG_MONGODB_ADMINUSERNAME=admin - ME_CONFIG_MONGODB_ADMINPASSWORD=password - ME_CONFIG_MONGODB_SERVER=mongodb + + + mariadb: + image: mariadb:11.3.2-jammy + command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_USER=user + - MYSQL_PASSWORD=${MYSQL_PASSWORD} + - MYSQL_DATABASE=DB + ports: + - "24001:3306" + volumes: mongo-data: driver: local From b84425cb176c2078a852d911b3cc51d45d8e3072 Mon Sep 17 00:00:00 2001 From: io42630 Date: Tue, 15 Apr 2025 08:56:13 +0200 Subject: [PATCH 5/5] + add sql exe --- exercises/sql/company.sql | 90 +++++++++++++++++++++++++++++++++++ exercises/sql/diff-counts.sql | 48 +++++++++++++++++++ exercises/sql/hackers.sql | 53 +++++++++++++++++++++ exercises/sql/population.sql | 39 +++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 exercises/sql/company.sql create mode 100644 exercises/sql/diff-counts.sql create mode 100644 exercises/sql/hackers.sql create mode 100644 exercises/sql/population.sql diff --git a/exercises/sql/company.sql b/exercises/sql/company.sql new file mode 100644 index 0000000..8e9a6f0 --- /dev/null +++ b/exercises/sql/company.sql @@ -0,0 +1,90 @@ +-- CREATE +CREATE TABLE Company +( + company_code VARCHAR(255) PRIMARY KEY, + founder VARCHAR(255) +); + + +CREATE TABLE Lead_Manager +( + lead_manager_code VARCHAR(255) PRIMARY KEY, + company_code VARCHAR(255) +); + + +CREATE TABLE Senior_Manager +( + senior_manager_code VARCHAR(255) PRIMARY KEY, + lead_manager_code VARCHAR(255), + company_code VARCHAR(255) +); + +CREATE TABLE Manager +( + manager_code VARCHAR(255) PRIMARY KEY, + senior_manager_code VARCHAR(255), + lead_manager_code VARCHAR(255), + company_code VARCHAR(255) +); + +CREATE TABLE Employee +( + employee_code VARCHAR(255) PRIMARY KEY, + manager_code VARCHAR(255), + senior_manager_code VARCHAR(255), + lead_manager_code VARCHAR(255), + company_code VARCHAR(255) +); + +-- INSERT + +INSERT INTO Company (company_code, founder) +VALUES ('C001', 'Alice Johnson'), + ('C002', 'Bob Smith'); + +INSERT INTO Lead_Manager (lead_manager_code, company_code) +VALUES ('LM001', 'C001'), + ('LM002', 'C002'); + +INSERT INTO Senior_Manager (senior_manager_code, lead_manager_code, company_code) +VALUES ('SM001', 'LM001', 'C001'), + ('SM002', 'LM002', 'C002'); + +INSERT INTO Manager (manager_code, senior_manager_code, lead_manager_code, company_code) +VALUES ('M001', 'SM001', 'LM001', 'C001'), + ('M002', 'SM002', 'LM002', 'C002'); + +INSERT INTO Employee (employee_code, manager_code, senior_manager_code, lead_manager_code, company_code) +VALUES ('E001', 'M001', 'SM001', 'LM001', 'C001'), + ('E002', 'M001', 'SM001', 'LM001', 'C001'), + ('E003', 'M002', 'SM002', 'LM002', 'C002'), + ('E004', 'M002', 'SM002', 'LM002', 'C002'); + + +-- QUERY + +SELECT DISTINCT C.company_code, + C.founder, + COALESCE(LM.total_lead_managers, 0) AS total_lead_managers, + COALESCE(SM.total_senior_managers, 0) AS total_senior_managers, + COALESCE(M.total_managers, 0) AS total_managers, + COALESCE(E.total_employees, 0) AS total_employees +FROM Company AS C + LEFT JOIN (SELECT DISTINCT company_code, + COUNT(lead_manager_code) AS total_lead_managers + FROM Lead_Manager + GROUP BY company_code) AS LM ON C.company_code = LM.company_code + LEFT JOIN (SELECT DISTINCT company_code, + COUNT(senior_manager_code) AS total_senior_managers + FROM Senior_Manager + GROUP BY company_code) AS SM ON C.company_code = SM.company_code + LEFT JOIN (SELECT DISTINCT company_code, + COUNT(manager_code) AS total_managers + FROM Manager + GROUP BY company_code) AS M ON C.company_code = M.company_code + LEFT JOIN (SELECT DISTINCT company_code, + COUNT(employee_code) AS total_employees + FROM Employee + GROUP BY company_code) AS E ON C.company_code = E.company_code +ORDER BY C.company_code; diff --git a/exercises/sql/diff-counts.sql b/exercises/sql/diff-counts.sql new file mode 100644 index 0000000..a69d089 --- /dev/null +++ b/exercises/sql/diff-counts.sql @@ -0,0 +1,48 @@ +WITH city_counts AS (SELECT COUNT(CITY) AS total_cities, + COUNT(DISTINCT CITY) AS distinct_cities + FROM STATION) +SELECT total_cities - distinct_cities AS city_difference +FROM city_counts; +-- city_counts is a CTE (Common Table Expression ) +-- it is a temp table, which in this case has just one row + + +-- Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. +-- Your result cannot contain duplicates. +SELECT DISTINCT CITY +FROM STATION +WHERE CITY REGEXP '^[aeiouAEIOU].*[aeiouAEIOU]$'; + +SELECT DISTINCT CITY +FROM STATION +WHERE LOWER(SUBSTR(CITY, 1, 1)) IN ('a', 'e', 'i', 'o', 'u') + AND LOWER(SUBSTR(CITY, LENGTH(CITY), 1)) IN ('a', 'e', 'i', 'o', 'u'); + +-- NOT start with vowels +SELECT DISTINCT CITY +FROM STATION +WHERE CITY REGEXP '^[^aeiouAEIOU]'; -- ^ae.. negates the expression + + +-- NOT end with vowels +SELECT DISTINCT CITY +FROM STATION +WHERE CITY REGEXP '[^aeiouAEIOU]$'; -- ^ae.. negates the expression + +-- NOT start or END with vowels +SELECT DISTINCT CITY +FROM STATION +WHERE CITY REGEXP '^[^aeiouAEIOU]' +AND CITY REGEXP '[^aeiouAEIOU]$'; + + +-- order by last 3 characters, then by ID +SELECT NAME FROM STUDENTS +WHERE MARKS > 75 +ORDER BY SUBSTR(NAME, -3), ID; + + +SELECT CITY, LENGTH(CITY) AS NAME_LENGTH +FROM STATION +ORDER BY LENGTH(CITY) DESC, CITY ASC + LIMIT 1; diff --git a/exercises/sql/hackers.sql b/exercises/sql/hackers.sql new file mode 100644 index 0000000..3b7e2ae --- /dev/null +++ b/exercises/sql/hackers.sql @@ -0,0 +1,53 @@ +-- Create the HACKERS table +CREATE TABLE HACKERS +( + hacker_id INT PRIMARY KEY, + name VARCHAR(255) NOT NULL +); + +-- Create the SUBMISSIONS table +CREATE TABLE SUBMISSIONS +( + submission_id INT PRIMARY KEY, + hacker_id INT, + challenge_id INT, + score INT, + FOREIGN KEY (hacker_id) REFERENCES HACKERS (hacker_id) +); + +-- Optional: Insert some sample data into HACKERS +INSERT INTO HACKERS (hacker_id, name) +VALUES (1, 'Alice'), + (2, 'Bob'), + (3, 'Charlie'); + +-- Optional: Insert some sample data into SUBMISSIONS +INSERT INTO SUBMISSIONS (submission_id, hacker_id, challenge_id, score) +VALUES (101, 1, 1001, 95), + (102, 1, 1002, 90), + (103, 2, 1001, 85), + (104, 3, 1003, 80); + +-- Select data to verify the setup +SELECT * +FROM HACKERS; +SELECT * +FROM SUBMISSIONS; + + +SELECT H.hacker_id, + H.name, + HTS.total_score +FROM HACKERS H + JOIN + (SELECT MaxScores.hacker_id, + SUM(MaxScores.max_score) AS total_score + FROM (SELECT S.hacker_id, + MAX(S.score) AS max_score + FROM SUBMISSIONS S + GROUP BY S.hacker_id, + S.challenge_id) AS MaxScores + GROUP BY MaxScores.hacker_id + HAVING SUM(MaxScores.max_score) > 0) AS HTS ON H.hacker_id = HTS.hacker_id +ORDER BY HTS.total_score DESC, + H.hacker_id; diff --git a/exercises/sql/population.sql b/exercises/sql/population.sql new file mode 100644 index 0000000..4c3b4ba --- /dev/null +++ b/exercises/sql/population.sql @@ -0,0 +1,39 @@ +-- CREATE +CREATE TABLE CITY +( + ID INT PRIMARY KEY, + NAME VARCHAR(255) NOT NULL, + COUNTRYCODE VARCHAR(3) NOT NULL, + DISTRICT VARCHAR(255) NOT NULL, + POPULATION INT NOT NULL +); + +-- INSERT +INSERT INTO CITY (ID, NAME, COUNTRYCODE, DISTRICT, POPULATION) +VALUES (1, 'Tokyo', 'JPN', 'Tokyo', 13929286), + (2, 'Delhi', 'IN', 'Delhi', 16787941), + (3, 'Shanghai', 'CN', 'Shanghai', 24183300), + (4, N'São Paulo', 'BR', N'São Paulo', 12106920), + (5, 'Mumbai', 'IN', 'Maharashtra', 12442373), + (6, 'Cairo', 'EG', 'Cairo', 9500000), + (7, 'Dhaka', 'BD', 'Dhaka', 8906039), + (8, 'Mexico City', 'MX', 'Mexico City', 9209944), + (9, 'Beijing', 'CN', 'Beijing', 21542000), + (10, 'Osaka', 'JPN', 'Osaka Prefecture', 8839469); + +-- QUERY + +SELECT ROUND(AVG(POPULATION), 0) AS average_population +FROM CITY; + +SELECT SUM(POPULATION) +FROM CITY +WHERE COUNTRYCODE = 'JPN'; + + +SELECT MAX(POPULATION) - MIN(POPULATION) AS population_difference +FROM CITY; + + + +DROP TABLE CITY;