I have the following c function. This function returns outbuf, the output length is unknown before calling the function so the function receives a pointer to the length as an argument outbuf_len, also the caller is responsible to free outbuf. I want to get the result of this function from python, so I started…
Image uploading in Flask blog with CKeditor 5
I’m stuck with following problem while creating my Flask based blog. Firstly, I used CKeditor 4 but than upgraded to 5 version. I can’t understand how to handle image upload on server side now, with adapters etc. As for 4 version, I used flask-ckeditor extension and Flask documentation to handle i…
How to detect collision between a list of Rect and another list of Rects
So I am making a zombie shooter game in pygame. I have a player – a zombie list – and a bullets list. all of them are rectangles. I need to detect the collision between all the bullets and all zombies. – i tried colliderect but and collidelist but that is between a object and a list. I want …
How to read a variable without lock in Python threads?
I am using Python threading to do some jobs at the same time. I leave the main thread to perform task_A, and create one thread to perform task_B at the same time. Below is the simplified version of the code I am working on: I know the above code doesn’t do something meaningful. Please think of it as a s…
Finding whether there is any overlap between two date periods in DataFrame
I have the following pd.DataFrame that looks like: I want to create a new column received_medidation that states whether or not (boolean) the patient received medication between admission_timestamp and end_period (even if it was for only one second). So, the boolean should state if there is any time between a…
Parse multipart/related emails
I’m trying to parse emails and convert tables within them into pandas dataframes. Since some of the emails are multipart, I took some code from this answer. The following code works fine but it breaks with multipart/related emails (no tables are found). Here’s the header of one of the multipart/re…
ModuleNotFoundError: No module named ‘_ctypes’ while installing libraries
I have not found any useful answers elsewhere, so I want to ask for help here. I’m trying to set up a VPS and I need some libraries (like datetime and random), however, when I type pip3.10 install datetime, it just gives me a bunch of errors: What should I do? Answer As it seems, you are trying to insta…
Memoized solution to Combination IV on Leetcode gives TLE when an array is used for caching
While trying to solve Combination IV on Leetcode, I came up with this memoized solution: But this gives me a Time Limit Exceeded error. Another memoized solution, that uses a dictionary to cache values instead of a dp array, runs fine and does not exceed time limit. The solution is as follows: Why does using …
Python – dictionary with propositions (replace string values)
I have some dictionary e.g. of form: Is their a simple way to replace all strings appearing in the dictionary values of form →(q, ∧(¬(p), ∨(y, z))) or →(p, q) by (q→(¬(p)∧(y∨z))) or (p→q)? Answer I found some solution by my own using some prolog: Prolog-file (called “logic.pl”) has to contain the …
Pandas – Groupby and Standardize
I have tried to tackle this for quite some time, but haven’t been able to get a pythonic way around it by using the built-in groupby and transform methods from pandas. The goal is to group the data by columns ex_date and id, then within the groups identified, standardize the column called ref_value_1 ag…