Random snippets of all sorts of code, mixed with a selection of help and advice.
How do I determine the concrete subclass of an Object knowing only the abstract superclass?
17 April 2026 @ 2:01 pm
I'm using an external library which builds an internal representation of an abstract syntax tree (AST) for a toy programming language given an XML file representation of the AST.
The method I'm using, fromXML, returns an AST, but according to the library documentation, AST is an abstract class. It has many concrete subclasses such as AST.program, AST.expr, and AST.stmt_list. My goal is to generate assembly-like code for a program given its AST, yet to do that I have to work with an instance of a concrete class, as AST has no fields.
The only way I could think of solving this problem is by checking (with the instanceof operator) whether the AST returned by fromXML is an AST.program and casting it into an AST.program. This has worked so far, since fromXML has only returned AST.program
Cloudflare Pages Worker fetch() returns "error code: 1016" for Supabase REST API, only from DFW edge
17 April 2026 @ 1:40 pm
I'm running a Next.js 15 app on Cloudflare Pages (edge runtime). Server Components fetch data from Supabase using the @supabase/supabase-js client. The fetch works perfectly from most edge locations but consistently fails with error code: 1016 when the Worker executes at Cloudflare's DFW (Dallas) PoP.
Setup:
// src/lib/supabase.ts
import { createClient } from "@supabase/supabase-js";
export const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!, // https://[ref].supabase.co
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
global: { headers: { 'x-application-name': 'my-app' } }
}
);
// src/app/blog/[slug]/page.tsx
export const runtime = "edge";
const getPost = cache(async (slug: string) => {
const { data, error } = await supabase
.from('BlogPost')
.select('*')
.eq('slug', slug)
.single();
if (error) {
console.error('Fe
cargo install in custom location
17 April 2026 @ 1:27 pm
I install cargo in
ls -la /opt/rust/
total 0
drwxr-xr-x. 1 root root 24 Mar 28 17:18 .
drwxr-xr-x. 1 root root 20 Apr 16 14:45 ..
drwxr-xr-x. 1 shirika shirika 12 Mar 28 17:20 cargo
drwxr-xr-x. 1 shirika shirika 96 Mar 28 17:20 .rustup
Gemini says """ To stop Rust from sneaking back into your home directory, you need to ensure your shell always knows that /opt/rust/ is the true home for these tools.
You likely need to add these lines to your shell profile (e.g., ~/.bashrc, ~/.zshrc, or /etc/profile for system-wide use). """. But I already has in in Path /opt/rust/cargo/bin. Is it because I set . "/opt/rust/cargo/env" in .bashrc rather than system environment? Why home directory still have the rust .rustup?
Blazor - OnAfterRenderAsync not trigger when page is accessed from an e-mail?
17 April 2026 @ 1:27 pm
I have a server-side application, and one feature of the application is that a user can request to reset their password. Essentially the way that this works is: they provide their username, and then they get an e-mail containing a link to a special ResetPassword component that also contains a token in the URL (passed as a parameter in the component).
In my OnAfterRenderAsync method on firstRender, I have a little bit of logic to validate the token, and then determine if the "reset" button is actually active or disabled, and a display message is changed based on the validation.
But I noticed when I arrive on the page through the link in the e-mail, my Form Model on the page is preset, but the display message is missing and the token hasn't been validated. Click the Reset Password button also does nothing.
I should mention that I do have
@rendermode InteractiveServer
in my Routes.razor and haven't have any issues so far wi
What is the difference between spring.cloud.gateway.server.webflux.httpclient.response-timeout and spring.cloud.gateway.httpclient.response-timeout
17 April 2026 @ 1:24 pm
What is the difference between these two Spring Cloud Gateway properties -
spring.cloud.gateway.server.webflux.httpclient.response-timeout and spring.cloud.gateway.httpclient.response-timeout
Are both these configurable from external configurations?
Print all data in the SQL Database as nested dictionary
17 April 2026 @ 1:16 pm
import psycopg2
# establishing the connection
conn = psycopg2.connect(
database="CONNE py",
user='postgres',
password='asdf',
host='localhost',
port= '5432'
)
cursor=conn.cursor()
tables = ["Class_A", "Class_B", "Class_C"]
outer_dict={}
for table in tables:
cursor.execute(f'SELECT name, department, overall_percentage FROM {table}')
rows=cursor.fetchall()
inner_dict={}
for row in rows:
name, department, overall_percentage=row
inner_dict={
'name':name,
'department':department,
'overall_percentage':overall_percentage
}
outer_dict[table]=inner_dict
print(outer_dict)
cursor.close()
This is my existing code, while running this program i only get the output of last data in the table (for each table).
this is the output:
{'Class_A': {'name': 'Ranga', 'depa
Behaviour at reading linebased data from a socket
17 April 2026 @ 12:54 pm
I have an external weather sensor, which gives periodically linebased NMEA-Data:
$WIMWV,357.0,R,5.2,M,A*1A\r\n$WIMWV,123.0,T,5.2,M,A*1A\r\n
The structure of the data contains exactly two lines (R and T), completed by the linebreak \r\n, which are send consecutively. After a time delay of approx. a half second, the next two lines are send. I can verify this by using e.g. Putty. So the output of Putty is like a data stream of receiving always a bunch of two lines separated by a delay:
$WIMWV,357.0,R,5.2,M,A*1A\r\n
$WIMWV,123.0,T,5.2,M,A*1A\r\n
//time delay ~0.5s
$WIMWV,357.0,R,5.2,M,A*1A\r\n
$WIMWV,123.0,T,5.2,M,A*1A\r\n
//time delay ~0.5s
and so on ...
This looks fine! Now, I would like to consume this data stream based on a native Java-Service. The procedure of reading from the socket is separated in a thread. Her
Calculate how many days passed since the last played match for each team
17 April 2026 @ 12:47 pm
I am trying to create two columns in my dataframe, with the days passed since the last match played from both the home team and the away team.
This is what my dataframe looks like:
Date team_home team_away
2026-05-10 Tottenham Arsenal
2026-05-11 Liverpool West Ham
2026-05-13 West Ham Chelsea
2026-05-13 Arsenal Liverpool
and I would like to have this:
Date team_home team_away home_diff away_diff
2026-05-10 Tottenham Arsenal 0 0
2026-05-11 Liverpool West Ham 0 0
2026-05-13 West Ham Chelsea 2 0
2026-05-13 Arsenal Liverpool 3 2
This is because for example West Ham played the 2026-05-11 before the 2026-05-13 so there are 2 days difference between the dates.
I am struggling to put th
Efficient, parallelized graph6 parsing with numpy or SIMD?
17 April 2026 @ 11:47 am
I have a multigraph class in Python that is used as a base for simple undirected, unlooped graphs.
I wrote my own graph6 parser based on the advice in the SO post.
NetworkX implements it in a similar manner. However, both read the graph6 format sequentially (unless Python does vectorize loops somehow, which I doubt).
Decoding (Di)Graph6 essentially does the following;
Create a row vector v based on the char values
(Conditionally) subtract -63 (can be vectorized)
Unpack the bytes into bits (preferably into groups of six)
Use the bit vector to add the edge [i,j] value to the A numpy array.
@class
C++ ranges::elements_of(ranges::iota_view(0, 11)); }() | ranges::reverse_view() | ranges::to<vector>()
17 April 2026 @ 11:42 am
I need to use a generator to generate a decreasing sequence. This is what I try:
vector<size_t> data = []() -> generator<size_t>
{ co_yield ranges::elements_of(ranges::iota_view(0, 11)); }() | ranges::reverse_view() | ranges::to<vector>()
and it complains about missing argument to reverse_view(). Error:
2457 | { co_yield ranges::elements_of(ranges::iota_view(0, 11)); }() | ranges::reverse_view() | ranges::to<vector>();
| ^
Console.cpp:2457:94: error: no matching function for call to ‘reverse_view()’
This instead works for me:
[]() -> generator<size_t>{ co_yield ranges::elements_of(ranges::reverse_view(ranges::iota_view(0, 11))); }() |