Using sqlite with h2 console

Sometimes we(developers/programmers) may need to see database tables in tree and run some select, insert quickly on the db, H2 console is the best tool in spring boot to reach database on dev environment. And I saw a question about “Using Flyway with SQLite database in spring boot”, I have been using liquibase around 5 years but I have not tried flyway before, learning opportunity. So I preapred an example with gradle spring boot, sqlite and h2 console and answered the question. ...

October 10, 2023 · 1 min · Özkan Pakdil

Java find how many character repeating in a string

How to find how many characters are repeating in a string. @Test void anotherQ() { // Q1 -- given a String like aaabbbcccaa need to return output like a3b3c3a2. String input = "aaabbbcccazzdddxx"; char[] arr = input.toCharArray(); for (int i = 0; i < arr.length; i++) { char c = arr[i]; int charCounter = 1; System.out.print(c); while (i + 1 < arr.length && c == arr[i + 1]) { charCounter++; i++; } System.out.print(charCounter); } System.out.println("\n" + transformString(input)); } public static String transformString(String input) { if (input == null || input.isEmpty()) { return input; } StringBuilder result = new StringBuilder(); int count = 1; char currentChar = input.charAt(0); for (int i = 1; i < input.length(); i++) { char c = input.charAt(i); if (c == currentChar) { count++; } else { result.append(currentChar).append(count); count = 1; currentChar = c; } } result.append(currentChar).append(count); return result.toString(); } The output is “a3b3c3a1z2d3x2” find the working code here for full working example. ...

October 7, 2023 · 1 min · Özkan Pakdil

Add `open with fleet` into context menu in linux mint

If you install the Fleet from JetBrains Toolbox you can use the config below. Add code below to ~/.local/share/nemo/actions/fleet.nemo_action [Nemo Action] Name=Open in Fleet Comment=Open in Fleet Exec=/home/USERHOME/.local/share/JetBrains/Toolbox/apps/fleet/bin/Fleet "%F" Icon-Name=Fleet Selection=Any Extensions=dir; Do not forget to change the USERHOME to your user home path. Then in files go to folder you want to open with intellij then right click and choose open in intellij.

October 3, 2023 · 1 min · Özkan Pakdil

Postgresql group by day, week and month examples

at the end of any product there will be a reporting interfaces for counts. let say you build a advertisement site which gives people to publish their products on the site. they will want to see how many people visited their product in daily basis or weekly. I used to do this in mysql like this SELECT create_time as Date, count(id) as 'Count', FROM views_of_product group by date_format(create_time, '%d %m %Y') order by date_format(create_time, '%Y-%m-%d') desc limit 7 this will nicely show last seven days views. but I needed to do same thing in postgresql. and like other days its not easily to find. I should check other report codes from project but no I allways research on google :) anyway here is my code: ...

September 30, 2023 · 2 min · Özkan Pakdil

Turning an array clockwise or counterclockwise

Turn an array clockwise therefore the last element comes to first and all hops to right. And counterclockwise meaning last element comes to first and others hops to their left. import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Solution { public static void main(String[] args) throws IOException { int[] arr = new int[]{1, 3, 5, 7, 9}; int K = 3; turnTheArrayToRight(arr, K); System.out.println("-----------"); turnTheArrayToLeft(arr, K); System.out.println("-----------"); // no need to reinvent the wheel. List l = new ArrayList<>(); Arrays.stream(arr).forEach(i->l.add(i)); Collections.rotate(l, K); // rotate right System.out.println(Arrays.toString(l.toArray())); Collections.rotate(l, -1 * K); // rotate left System.out.println(Arrays.toString(l.toArray())); } private static int[] turnTheArrayToRight(int[] nums, int k) { for (int j = 0; j < k; j++) { for (int i = nums.length - 1; 0 < i; i--) { int temp = nums[i - 1]; nums[i - 1] = nums[i]; nums[i] = temp; } System.out.println(Arrays.toString(nums)); } return nums; } private static int[] turnTheArrayToLeft(int[] nums, int k) { for (int j = 0; j < k; j++) { for (int i = 0; i < nums.length - 1; i++) { int temp = nums[i]; nums[i] = nums[i + 1]; nums[i + 1] = temp; } System.out.println(Arrays.toString(nums)); } return nums; } } Output ...

September 28, 2023 · 2 min · Özkan Pakdil