Random snippets of all sorts of code, mixed with a selection of help and advice.
Multiple CDFS on the same plot with specified ranges
10 November 2025 @ 2:34 am
I was trying to do something for a project where I create two random 3D vectors, project them onto a 2D plane by removing their x-component, taking the dot product between the two to find their separation and then forcing their separation to be between 0º and 90º.
I'm then running into the issue where I can't plot my data how I want to. I want to create 3 CDF's onto the same plot where we specify angles between 0-90º. I want to show the CDF for the following regions 0-20, 70-90 and 0-90. The issue I'm running into is either: my CDF will either be a single linear line, a CDF that only works between the specified angles and completely disappears outside of that range, and or a CDF that works only within its specified region and then flatlines outside of my specified range.
I will include an example of what I want my plot to look like.
import numpy as np
import matplotlib.pyplot as plt
num_samples = 50000 #number of samples
theta_all = np.arccos(np.rand
Resolve "ON CONFLICT DO UPDATE command cannot affect row a second time" error in WITH statement (PostgreSQL)
10 November 2025 @ 2:02 am
I have two tables:
Table keywords has two columnes: id and v (which hold the keyword's value).
Table main has, amoung others, two columns that are each a FK (foreign key) into the keywords table's id, named key1_id and key2_id.
Now, I want to insert pairs of keywords (key1 and key2 as $1 and $2) into the main table, like this:
WITH
key1 AS ( INSERT INTO keywords (v) VALUES ($1) ON CONFLICT (v) DO UPDATE SET v = EXCLUDED.v RETURNING id ),
key2 AS ( INSERT INTO keywords (v) VALUES ($2) ON CONFLICT (v) DO UPDATE SET v = EXCLUDED.v RETURNING id )
INSERT INTO main ( key1_id, key2_id )
SELECT key1.id, key2.id
FROM key1, key2
RETURNING id
Basically, the two keys often have recurring values, so I use the keywords table to keep a unique set of them (mostly for storage optimization, as I have millions o
Looking for a better way to handle animation trigger calling in Unity using a Blend Tree and object instantiation
10 November 2025 @ 1:43 am
I'm fiddling around with a 2D side-scroll game using C# in Unity. Basically, I have a method that gets called when I hit an animation trigger on the animator and that method instantiates a GameObject (in my case, an arrow) that has force applied to it. Everything is working good and error free with the exception that I am getting 2 arrows spawning at once. I did some digging and found that my method that instantiates the arrow GameObject is running twice because of my blend tree shown here:
[As you can see, the blend between two animations causes the trigger to be called from each one; thus causing 2 object instances.]
[I have attack triggers on each "ArcherFire" animation because it should launch an arrow in any of the 4 positions of 30 degrees, 60 degrees, 90 degrees, and 120 degrees.]

[As you can see, the blend between two animations causes the trigger to be called from each one; thus causing 2 object instances.]
[I have attack triggers on each "ArcherFire" animation because it should launch an arrow in any of the 4 positions of 30 degrees, 60 degrees, 90 degrees, and 120 degrees.]

Cannot query "admin": Must be "ChatMessage" instance in Django
10 November 2025 @ 1:42 am
In View Function
it can show this error
Request Method:GETRequest URL:http://127.0.0.1:8000/inbox/Django Version:4.2.25Exception Type:ValueErrorException Value:Cannot query "admin": Must be "ChatMessage" instance.Exception Location:D:\Socialmedia\.venv\lib\site-packages\django\db\models\sql\query.py, line 1253, in check_query_object_typeRaised during:core.views.messages.inboxPython Executable:D:\Socialmedia\.venv\Scripts\python.exePython Version:3.9.13Python Path:['D:\\Socialmedia', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\ER-RPJ\\AppData\\Local\\Programs\\Python\\Python39', 'D:\\Socialmedia\\.venv', 'D:\\Socialmedia\\.venv\\lib\\site-packages']
def inbox(request):
How to implement modern Google login using Kotlin and Jetpack Compose?
10 November 2025 @ 1:35 am
I'm trying to build a modern login screen using Kotlin and Jetpack Compose that supports Google authentication. I want the UI to follow current design best practices and integrate smoothly with Firebase or other recommended services.
So far, I've set up a basic Jetpack Compose layout, but I'm not sure how to properly configure Google Sign-In, handle authentication callbacks, and manage user sessions. I’ve looked into Firebase Authentication but I’m still unclear on how to connect it with Compose and make the login flow seamless.
Can someone provide a step-by-step tutorial or example project that shows how to:
• Set up Google Sign-In with Firebase
• Integrate it into a Jetpack Compose UI
• Handle login success/failure and navigate accordingly
Any help or guidance would be greatly appreciated!
how to see which user reacted on a post in telegram channel
10 November 2025 @ 1:28 am
Im not a programmer but as an admin of a telegram channel i need to know who reacted on a post. I saw questions where people use telebot in python to see this information but i dont understand anything. really need help. Would be grateful for any answer.
Pytest - ordering pytest_addoption implementations from other plugins
10 November 2025 @ 12:13 am
I am trying to add a new option to xdist's --dist flag. In my plugin.py file:
@pytest.hookimpl
def pytest_addoption(parser: pytest.Parser) -> None:
# Modify the existing xdist 'dist' option to add our new scheduling mode
group = parser.getgroup("xdist", "distributed and subprocess testing")
distopt = next(filter(lambda opt: opt.dest == "dist", group.options), None)
distopt._attrs["choices"].append("perdevice")
The issue here is that I require xdist to have already added options before I can modify them. This is confusing me a bit because according to Pytest's documentation, plugin hooks are run on a LIFO basis - I would think since this new plugin is registered last, it would execute first.
Deming Regression R - Prediction/Confidence Interval and use of total least squares
9 November 2025 @ 8:45 pm
I want to use deming regression for the calculation of a linear function between two variables which both have measurement errors. In addition, I have to assume that the regression goes through the origin (based on the physics behind the data). I used the deming() function from the deming package so far. This function uses maximum likelihood estimation for determining the best fit. I have two questions:
How can I calculate the prediction and conficence interval for the regression based on the data obtained through the deming function?
Is there a function which enables the calculation of a deming regression through the origin which relies on the calculation and finding the minimum total least squares?
Thank you in advance!
More parsing-friendly Python debugger locals() output
9 November 2025 @ 8:22 pm
I need the locals() text output to be easier to parse then what the default output is. I am using a IDE that I wrote in C that starts a tty() to run pdb and it captures the output from locals() and parses it into useable data for my IDE.
I wrote a few Python functions that can output the format I am looking for but I can't get the debugger to use those functions without including it directly in the source code I am trying to debug. I made a package (pdbext) from them and sending the import pdbext to pdb injects that into the code I am debugging in the current function as an another local instead of pdb loading it outside into the debugger itself. I want to avoid having to include a debug package in every source file.
I also tried to extend the pdb.Pdb class and include those functions as members in that class and use a do_parse_locals () class method. However pdb no longer worked. Typing a simple next wou
Cant calling API from my server because of CORs
9 November 2025 @ 7:02 pm
I am making a todo desktop app which run locally on user's device. I am using Electron Forge + Vite + ReactJs and ExpressJs.
Folder structure:
src/
├─ db/
│ └─ database.js
├─ main/
│ └─ index.js
├─ preload/
│ └─ index.js
├─ renderer/
│ ├─ index.html
│ └─ src
| ├─ main.jsx
│ ├─ App.jsx
src/main/index.js
import { app, BrowserWindow } from 'electron'
import path, { join } from 'path'
import { fileURLToPath } from 'url'
import express from 'express'
import cors from 'cors'
import db from '../db/database.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
// === Express API ===
const server = express()
const port = 4000
server.use(express.json())
server.use(
cors({
origin: '*',
methods: ['GET', 'POST'],
allowedHeaders: ['Content-Type', 'Authorization']
})
)
server.get('/api/hello', (req, res) => {
res.json({ message: 'Hello from Expre