Random snippets of all sorts of code, mixed with a selection of help and advice.
Create DSN for SQL Server with Username and Password
14 June 2026 @ 3:09 pm
How to automatically create DSN for connection to MS SQL server with supplied username and password?
I have searched online and cant find anything that works.
The following code I have used worked if I am not supplying username and password, but I need the one that works with supplied username and password:
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0 ' NULL Pointer
'Function Declare
#If Win32 Then
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, B
Is HTTP error 500 appropriate when I raise a ValueError?
14 June 2026 @ 3:07 pm
I raise the ValueError exception if I find a user in data base
try:
db.session.query(User).filter_by(id=user.id).one()
raise ValueError("The user already exists in data base")
except NoResultFound as e:
# Ajouter à la session
db.session.add(user)
db.session.commit()
And the error status is 500. Is that correct? Normally error 500 is the consequence of a server error and should not be the status if I raise a ValueError.
Unsafe call of a type that could not be resolved
14 June 2026 @ 2:34 pm
I want to define a static list of integers, then check to see if some random variable's value exists in the list of integers. In the example below, the list contains 0 and 1 and I want to check to see if the value 1 exists in the list (for simplicity). Later, this 1 will be a variable. How do I do this?
FunctionIDs.model.ts:
export const FunctionIDs: number[] = [
0 //some value
, 1 //some other value
] as const;
OtherFile.ts:
import { FunctionIDs } from './models/FunctionIDs.model'
if (FunctionIDs.includes(1)) { //2 ERRORS HERE POINTING TO THE LAST PARENTHESES
//do something
}
The 2 errors:
Unsafe call of a type that could not be resolved
Unsafe member access .includes on a type that cannot be resolved
In C++ atomic operations, are the generated values allowed to circularly depend on their own computations?
14 June 2026 @ 2:17 pm
As described in https://cppreference.com/cpp/atomic/memory_order :
Even with relaxed memory model, out-of-thin-air values are not allowed to circularly depend on their own computations, for example, with x and y initially zero,
// Thread 1:
r1 = y.load(std::memory_order_relaxed);
if (r1 == 42)
x.store(r1, std::memory_order_relaxed);
// Thread 2:
r2 = x.load(std::memory_order_relaxed);
if (r2 == 42)
y.store(42, std::memory_order_relaxed);
is not allowed to produce r1 == r2 && r2 == 42 since the store of 42 to y is only possible if the store to x stores 42, which circularly depends on the store to y storing 42.
But what about this:
How to parse razor templates with Abstract Syntax Trees from C# code outside of ASP.NET context? [closed]
14 June 2026 @ 1:56 pm
I need to write a tool that processes given Razor templates. It cannot parse them as if they were pure HTML. It must access the AST of the document in order to analyze its HTML markup elements as well as embedded C# code.
I could not find any mature and maintained library to parse Razor. My current implementation uses Microsoft.AspNetCore.Razor.Language, but most of its API methods are internal and I am forced to create reflection based wrappers for the functionality I need as I go, which is extremely awkward. Nothing like working with Roslyn, for example, to process C# source code.
If you have faced the same challenge, how have you resolved it? Maybe I am missing some library that does what I need?
Fitting an image inside CtkLabel
14 June 2026 @ 1:40 pm
I have a CTkFrame and inside it I have a CTkLabel defined as follows:
self.info_frame = ctk.CTkFrame(self, corner_radius=12)
self.info_frame.grid(
row=1, column=0, padx=20,
pady=(0, 10), sticky="ew")
self.info_frame.grid_columnconfigure(0, weight=0)
self.info_frame.grid_columnconfigure(1, weight=1)
self.lbl_thumbnail = ctk.CTkLabel(
self.info_frame,
text="[Thumbnail]",
corner_radius=12,
width=272,
height=153,
fg_color="gray20")
self.lbl_thumbnail.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
Later on in the program, an image is written to self.lbl_thumbnail and the text changes to "" so the only visible thing will be the image.
Here is how it is done:
def _build_thumbnail_image(self, image_data):
image = image_data.convert("RGBA")
image = ImageOps.fit(
image,
(272, 153),
Using C++26 <simd> library [closed]
14 June 2026 @ 12:48 pm
My C++ compiler (g++ 16) have changed the <simd> library implementation under the hood forcing me to learn the new version of the library.
I have got 2 problems:
I don't know how to set the ABI template parameter to std::simd::basic_vec. I can't use default ABI, because I need a vector with a specific size (like a 4-element float for example),
I don't know how to set values of the vector. I tried passing values through constructor parameters (there is no constructor that accepts values this way) and using operator[] (there is only read-only version of the operator)
I searched the Internet, but I'm finding only information about the old way of working with <experimental/simd> library. Also cppreference.com is unusable, because most of the page for simd is in red links (unfortunately with key ele
Movie recommendation database problem in SQL Server [duplicate]
14 June 2026 @ 12:24 pm
create table Movies
(
movie varchar(100),
genre varchar(100)
)
create table Actors
(
actorName varchar(100),
movie varchar(100)
)
create table Users
(
userName varchar(100),
movieName Varchar(100),
rating int
)
How would one get the top movies by genre?
Can a transformation pattern be inferred from example input/output pairs?
14 June 2026 @ 8:38 am
I'm experimenting with a small tool that receives:
an input string A
an expected output string B
Example:
Input:
{'name':'John','email':'john@email'}
Output:
insert into users (name,email)
values ('John','john@email');
The idea is to automatically infer a reusable transformation rule from such examples.
A very naive implementation could generate something like:
\{'name':'(.*)','email':'(.*)'\}
with a replacement:
insert into users (name,email)
values ('$1','$2');
I'm not interested in this specific JSON→SQL example (there are obviously simpler solutions).
My actual question is:
Given multiple example pairs (input → output), are there known algorithms, libraries, or research areas that try to infer a generalized transformation pattern automatically?
I'm looking for ter
Reference vs Pointers
14 June 2026 @ 6:28 am
There is a significant difference between a reference and a pointer. But I want to ask at the low level how are they different. Some people say that references are just pointers under the hood but and compiler is responsible to differentiate between a pointer and a reference.
Is it true that references are basically pointers under the hood with restricted control (for safety and easy of use)? If this is false then jump to my second question.
Is it correct to say that references point to a variable/object and pointer point directly to a memory location? as the fact that pointers support pointer arithmetic whereas references do not?
I am a pre-final year computer science student and has been coding in C for the past one year, but some questions still remain inside me and I ask them here. This question is general and not constraint to C language.