Random snippets of all sorts of code, mixed with a selection of help and advice.
Best practice using search params as state
2 March 2026 @ 5:30 pm
I noticed when deriving state using Route.useSearch(), and updating state using Route.useNavigate, there is a delay when updating state. Is there guidance on how to do this optimally? So far I'm keeping state in a useState, and syncing state using a useEffect
function useOptimisticTab() {
const { tab } = Route.useSearch();
const navigate = Route.useNavigate();
const [optimisticTab, setOptimisticTab] = useState(tab);
useEffect(() => {
setOptimisticTab(tab);
}, [tab]);
const handleSetOptimisticTab = (value: TabOptions) => {
setOptimisticTab(value);
navigate({
search: (prev) => ({
...prev,
tab: value,
}),
});
};
return [optimisticTab, handleSetOptimisticTab] as const;
}
Gitlab Docker Image - Private Project
2 March 2026 @ 5:25 pm
How to create private project in Gitlab gitlab/gitlab-ee:18.9.0-ee.0 (Docker) ?
Force git clone command to use a token or username:password .
Thx,
Rick
How to set up documentation with MkDocs?
2 March 2026 @ 5:21 pm
I tried to set up MkDocs for a small local project using ChatGPT, but it failed. Here is what I have as folder structure:
- mymodule/
| - __init__.py
| - tester.py
- docs/
| - docs/
| - mkdocs.yaml
and that mkdocs.yml contains:
site_name: Test Documentation
theme:
name: mkdocs
plugins:
- search
- mkdocstrings:
handlers:
python:
setup_commands:
- "import sys, os; sys.path.insert(0, os.path.abspath('../mymodule'))"
But it is not working when running mkdocs serve. How can this be fixed? I just want documentation of several files in that one folder mymodule.
class hierarchy hibernate mapping
2 March 2026 @ 5:18 pm
I'm creating the domain class mapping for the following SQL tables:
CREATE TABLE org (
id UUID PRIMARY KEY DEFAULT uuidv7(),
name VARCHAR(50) NOT NULL
);
CREATE TABLE org_entity (
id UUID PRIMARY KEY DEFAULT uuidv7(),
name VARCHAR(50) NOT NULL,
org_id UUID NOT NULL REFERENCES org(id)
);
CREATE UNIQUE INDEX ui_org_entity ON org_entity (org_id, id);
CREATE TABLE entity_field (
id UUID PRIMARY KEY DEFAULT uuidv7(),
name VARCHAR(50) NOT NULL,
org_id UUID NOT NULL,
entity_id UUID NOT NULL,
FOREIGN KEY (org_id, entity_id) REFERENCES org_entity(org_id, id)
);
I try more. This is the last EntityField class with errors:
@Entity
@Table(name = "entity_field")
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper = true)
public class EntityField extends BaseOrg {
@ManyToOne(optional = false, fetch = FetchType.LAZY
Why are these random numbers printing in the terminal? Everything else seems to be working fine
2 March 2026 @ 5:16 pm
The code below checks if a give string is a palindrome or not. I am getting the intended output in the terminal but there is also an integer printing in between every line of output. I have played with setting the return type of the is_palindrome to different things like std::string but I can't seem to get the terminal to print the correct output without the numbers. Also, every time I run the code the numbers are different.
Source Code:
#include <iostream>
#include <algorithm>
// Define is_palindrome() here:
bool is_palindrome(std::string text){
std::string rev = text;
std::reverse(rev.begin(), rev.end());
if(text == rev){
std::cout << text << " is a palindrome!\n";
}
else {
std::cout << text << " is not a palindrome.\n";
}
}
int main() {
std::cout << is_palindrome("madam") << "\n";
std::cout << is_palindrome("ada") << &quo
What does .NET DateTime Ticks represent when Kind is Unspecified?
2 March 2026 @ 4:57 pm
Take the following C# code:
DateTime.TryParse("2025-05-03T02:10:36", out DateTime dateTime);
Console.WriteLine(dateTime.Kind);
Console.WriteLine(dateTime.Ticks);
The value of Ticks is here 638818350360000000 and the value of Kind is "Unspecified". I get why Kind is not specified but I don't get how the system can determine a value for Ticks in this case. The docs say
If the DateTime object has its Kind property set to Unspecified, its ticks represent the time elapsed time since 12:00:00 midnight, January 1, 0001 in the unknown time zone.
I have not idea what that means. How can you specify the number of ticks since a certain point in time without knowing the
Animation bug on list when entering edit mode with swipe to delete disabled
2 March 2026 @ 1:59 pm
I'm trying to have an edit button on a list to be able to delete multiple items at the same time without the red delete controls at the start of each row.
To remove the delete controls I use this .deleteDisabled(editMode?.wrappedValue.isEditing == true). But when I add this line the animation is strange when entering edit mode, it's like the list bounces.
You can find an example code here:
import SwiftUI
struct ContentView: View {
@State private var items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
@State private var selection: Set<String> = []
var body: some View {
NavigationStack {
List(selection: $selection) {
ItemsList(items: $items)
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
EditButton()
}
Using matplotlib to build report of survey responses, what is the most efficient way to tally likert scores?
2 March 2026 @ 3:18 am
I am building out functionality in an existing app for a user to upload an excel file to plot out responses for survey questions. There are 4 likert questions with 2 comment response question. The relevant data is organized as such:
Q1 Q2 Q3 Q4 Q5 Q6
0 Occasionally Agree Agree comment comment Very Well
1 Frequently Agree Agree NaN NaN Moderately
2 Frequently Agree Agree NaN NaN Well
3 Frequently Agree Neither Agree nor Disagree comment comment Moderately
Currently, I do the following to build a list of all the questions, their listed responses, the 'type' of likert scale it is, and the amount each response is recorded per question.
def read_responses(xl):
responses = []
action = False
data = pd.read_excel(xl)
for name, values
Win32 C++ Generic function to set Cursor from either UI or any worker threads (SetCursor does not work from external threads)
2 March 2026 @ 12:38 am
I need to switch between Normal and Loading cursors. I see in my application that if I do
// Start Waiting Cursor
SetCursor(LoadCursor(NULL, IDC_WAIT));
// ... App Logic ...
// Resume Normal Cursor when done
SetCursor(LoadCursor(NULL, IDC_ARROW));
this works properly in direct UI-thread code, but does not work from the code of separate worker threads. To determine the Waiting cursor during certain conditions in worker threads I currently handle WM_SETCURSOR which checks global variables.
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT /* Client area only*/ &&
threadCondition1 || threadCondition2 || threadCondition3) {
SetCursor(LoadCursor(NULL, IDC_WAIT));
} else {
// Default Arrow Cursor
return DefWindowProc(hWnd, message, wParam, lParam);
}
Per Google this is because
SetCursor in Win32 API ofte
How do I reduce the remaining health here to zero?
1 March 2026 @ 11:28 am
I haven't been able to figure out how to solve this problem.
const healths = [{
1: 100
}, {
2: 100
}, {
3: 100
}, {
4: 100
}, {
5: 100
}, {
6: 100
}];
healths.forEach((curr, i) => {
// console.log(`${curr[i + 1]}`)
const damage = Math.trunc(Math.random() * (12 - 4 + 1)) + 4;
let remainingHealth = curr[i + 1] - damage;
if (i < healths.length - 1) {
console.log(`${i + 1}. player made a move, ${i + 2} knight's remaining health is ${remainingHealth}`)
} else if (i === healths.length - 1) {
console.log(`${i + 1}. player made a move, ${i - (healths.length - 2)} knight's remaining health is ${remainingHealth}`)
}
})