Random snippets of all sorts of code, mixed with a selection of help and advice.
Determine which environment variables have been set by a script
15 April 2025 @ 11:43 pm
I'm looking for a way to determine in a script which environment variables another script sets. The script that sets the environment variables (env.sh) has various logic to retrieve those variable values and I'd like to determine if the those values have changed from one version of of the repository to another version of it (but I can't track the file content of env.sh only because it may remain unchanged, even though the environment variables it declares changed).
# main.sh
# Call env.sh to calculate a hash over the environment variables it has set (no idea how)
bash ./env.sh
# env.sh
export foo="foo" # could be changed directly in another version
export bar=`cat barversion` # content in `barversion` itself could change, but not env.sh
# ... more could be added, but we don't want to assume knowledge about this in main.sh
A file that is referenced by env.sh which may change w
Updating element value prevents change event on mobile
15 April 2025 @ 11:42 pm
I'm working with an application where some of the input elements are updated in real time using an input event. For some reason, this prevents a change event from firing on my mobile device (running ios 18.3.2). I have tested this on both Chrome and Safari and get the same issue. I have not tested any other mobile devices since I don't have any.
The below code fires a change event perfectly fine in a desktop browser but I do not get any change event in #input_b on my mobile device.
var input_a = document.getElementById('input_a');
input_a.addEventListener("change", (event) => {
Patroni does not start with etcd
15 April 2025 @ 11:35 pm
Patroni cluster dont connect to etcd but I can get list of machine manualy using cURL. What shoud i do with it? I have etcd V3 API and use "etcd3" option at config.yml for patroni. I suppose it can be python error.
I hope somebody helps to fix a bugenter image description here
Is there a way to define classes and their members and functions by syntax rather than going through the GUI (browser menu)?
15 April 2025 @ 11:35 pm
I am trying my hands at Smalltalk and downloaded Squeak as my first attempt. It seems that the "Workspace" in Squeak is where you run your code. So far so good for a "HelloWorld" example. Then I wanted to make some classes and I realized a problem: In the tutorials I've seen so far, there were only examples of adding classes through the browser menu.
Thus my question: Is there a way to define classes and their members and functions by syntax, that is, textual, as part of your script, rather than going through the the GUI?
If there is no alternative to going through the GUI, this is going to be a pain to maintain my projects. I am used to languages like C/C++, Python, Javascript and I like the fact that all of my assets are in text files. One advantage of this is that if I want to run my projects on another system, all I have to do is install the compiler/interpreter for the project's language and I can just compile and/or run from the shell. Another
Using array instead of vector in a structure in Rust
15 April 2025 @ 11:35 pm
Go:
package main
import (
"fmt"
"os"
"strings"
"time"
)
type Datatable struct {
id int
rows [][]string
}
func main() {
start := time.Now()
dat, err := os.ReadFile("C:\\Temp\\test1.txt")
if err != nil {
panic("file not found")
}
str := string(dat)
n := 200_000
tables := make([]Datatable, n)
for i := 0; i < n; i++ {
table := Datatable{i, nil}
var ll []string = strings.Split(str, "\n")
table.rows = make([][]string, len(ll))
for j, l := range ll {
table.rows[j] = strings.Split(l, "\t")
}
tables[i] = table
}
t := time.Now()
elapsed := t.Sub(start)
fmt.Println(elapsed)
var b []byte = make([]byte, 1)
os.Stdin.Read(b)
}
Rust:
use std::fs;
use std::time::SystemTime;
use std::i
Keeping MediaRecorder alive regardless of user interactions
15 April 2025 @ 11:33 pm
I'm trying to record audio from a user for an extended period of time, specifically anywhere between 10 mins and 1.5 hours. However, I want the recordings and related resources to stay alive and continue recording even if the user switches to other tabs. I've implemented it inside a useContext so that the methods are readily available for lower components
import React, { createContext, useState, useRef, useCallback, useContext, useEffect } from 'react';
import { setup_media_recorder } from '../utils/AudioUtils';
import { AlertContext } from './AlertFlag';
const MicrophoneContext = createContext();
const AudioContext = createContext();
const put_mic_local = (deviceId) => {
localStorage.setItem("microphone", deviceId);
}
const get_mic_local = () => {
return localStorage.getItem("microphone");
}
export const AudioProvider = React.memo(({ children }) => {
const { addAlert } = useContext(AlertContext);
// Microphone
const [ select
Cloud Custodian Policy to Delete Unused Lambda Functions
15 April 2025 @ 11:15 pm
I'm trying to develop a Cloud Custodian Policy to Delete Lambda Functions which haven't executed in the last 90 days. I tried developing some versions and did a dry run. I do have lots of functions (atleast 100) which never got executed in the last 90 days.
Version 1: Result, no resources given in the resources.json file after the dry run, I don't get any errors
policies:
- name: delete-unused-lambdas
resource: aws.lambda
description: Delete Lambda functions not executed in last 90 days
filters:
- type: value
key: "LastModified"
value_type: age
op: ge
value: 90
actions:
- type: delete
Version 2: Result, no resources given in the resources.json file after the dry run and I feel like Last Executed key may not be supported with lambda but perhaps with CloudWatch
policies:
- name: delete-unused-lambdas
resource: aws.lambda
description: Delete Lambda functions not executed in last 90 days
filters:
- type: va
Trying to create a Menu Bar Class in Tkinter but I can't get it to work
15 April 2025 @ 11:13 pm
I'm using Windows 11 and Pycharm
I started this program, then started to switch it to OOP. So I'm starting with making a Menu Bar Class. I can't seem to get the Menu Bar to work. The rest of the code works. It's not wired to do anything yet except put some widgets on the screen. That is it works as long as I comment out lines 30 and 31 where I try to create said menu bar.
I've seached google and youtube. I've found a few exapmples on Youtube, the web and here on Stack Overflow. I've tried everything I can think of or find over the last 3 days, nothing has worked. So now I would really like your help please.
The error get is this...
Traceback (most recent call last):
File "D:\My Data\Developement\MyMoviesOOP2\.venv\Main.py", line 118, in <module>
app = App()
^^^^^
File "D:\My Data\Developement\MyMoviesOOP2\.venv\Main.py", line 30, in __init__
self.menu_bar = Menu
Why does Instant.now() have a much higher precision on my Unix machine vs Windows?
15 April 2025 @ 10:44 pm
To get a sense of how accurate Instant.now() is on various machines, I ran a very simple test to see how often the clock updated:
public class Test {
private static final Logger logger = LogManager.getLogger(Test.class.getName());
public static void main(String... args) {
while (true) {
logger.info(Instant.now());
}
}
}
On a Intel Core i9 laptop running Windows 11, most of the log lines printed the same timestamp, and would only change every 1ms or so.
18:23:55.325 [main] INFO Test - 2025-04-15T22:23:55.325858100Z
18:23:55.325 [main] INFO Test - 2025-04-15T22:23:55.325858100Z
18:23:55.325 [main] INFO Test - 2025-04-15T22:23:55.325858100Z
18:23:55.325 [main] INFO Test - 2025-04-15T22:23:55.325858100Z
18:23:55.325 [main] INFO Test - 2025-04-15T22:23:55.325858100Z
18:23:55.326 [main] INFO Test - 2025-04-15T22:23:55.326858800Z
18:23:55.326 [main] INFO Test - 2025-04-15T22:23:55.326858800
Is there a proper way to close out a Word application using VBA?
15 April 2025 @ 10:10 pm
For reference I'm writing a script that uses an excel sheet to populate a word file from a template. After that I'm merging that word document and appending to the end of it another word document.
I'm running into issues when I try to close an instance of the Word.Application Object I've created. The issue occurs when I finish processing and I want to run the program again. If I've used the WordApplication.Quit Function, I get an Error 462 saying that the remote server machine does not exist or is unavailable. After rerunning, I can process the data again with no problem. But, if I don't quit the Word.Application object I can keep re running the program without issue. The code looks something like this.
Sub AUTOFILL()
'Dimension Word Objects
Dim wApp As Word.Application
Dim wDoc As Word.Document
DocSrc As Word.Document
'Dimension incrementers for cycling through cols and rows
Dim inc_rows As Integer
'Dimension values for saving files from PN in Cells
Dim FVa