!learn_programming@programming.dev
Ask the main part of your question in the title. This should be concise but informative.
Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.
Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.
Ask about the problem you're trying to solve. Don't focus too much on debugging your exact solution, as you may be going down the wrong path. Include as much information as you can about what you ultimately are trying to achieve. See more on this here: https://xyproblem.info/
Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient
!learn_programming
@programming.devLet's say I am making an app that has table Category and table User. Each user has their own set of categories they created for themselves. Category has its own Id identity that is auto-incremented in an sqlite db.
Now I was thinking, since this is the ID that users will be seeing in their url when editing a category for example, shouldn't it be an ID specific only to them? If the user makes 5 categories they should see IDs from 1 to 5, not start with 14223 or whichever was the next internal ID in the database. After all when querying the data I will only be showing them their own categories so I will always be filtering on UserId anyway.
So let's say I add a new column called "UserSpecificCategoryId" or something like that - how do I make sure it is autogenerated in a safe way and stays unique per user? Do I have to do it manually in the code (which sounds annoying), use some sort of db trigger (we hate triggers, right?) or is this something I shouldn't even be bothering with in the first place?
Just started as in, I'm about an hour into a 4 hour intro video. Seeing two basic ways of manipulating things and don't understand the difference.
If I want to know the length of a string and I just guess at how to do it I would try one of these two things,
What is the difference between these types of statements? How do I think about this to know which one I should expect to work?
I am really struggling to include proper testing practices into my code and would appreciate any advice on how to get going. I work in web dev so my I am interested in how to properly implement a suite of tests for websites and incorporate into it a CI/CD pipeline.
I find a lot of tutorials teach the most basic types of unit tests, 90% of the time most instructors teach how to write a test to sum two numbers, but when it comes to writing real unit test I find it hard to know what I should be testing. I learnt some cypress and have gotten better at including end-to-end testing because that makes more sense to me, but I still feel I am way short of where I should be.
How can I move forward? Did anyone else find themselves in my situation and find good resources to help them learn? Thx
From Perplexity.ai
Six Degrees of Wikipedia: Creating a program that finds the shortest path between two random Wikipedia articles using graph traversal algorithms. This applies graph theory concepts to explore connections in a large knowledge base.
Emoji Encryption: Using hash tables and cryptographic algorithms to create an encryption system that converts text to emojis. This could be an interesting way to explore cryptography concepts in a fun, visual way.
From Gemini.google.com
Procrastination Station: This website creates increasingly elaborate and ridiculous tasks to distract you from what you actually need to do. Dishes? Nah, fold your socks into origami cranes!
Dramatic Password Validator: Forget boring error messages. This program rejects weak passwords with Shakespearean insults or movie villain monologues.
From Chatgpt.com
- Time Travel Email Service: Build a data structure that allows you to send emails to yourself in the past, with time complexity considerations that are totally ignored because it’s time travel.
- Mood-Driven Random Number Generator: Implement an algorithm that generates random numbers based on the mood of the user, using sentiment analysis on real-time facial expressions.
Hello, I would like to store these http headers in classes:
Host: developer.mozilla.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://developer.mozilla.org/testpage.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT
If-None-Match: "c561c68d0ba92bbeb8b0fff2a9199f722e3a621a"
Cache-Control: max-age=0
As you can see, many have unique data (numbers, strings, list of strings). I would like to:
Is making hard coded classes for every type of header viable? How would this be done in the cleanest way possible?
https://visualstudiomagazine.com/Articles/2024/06/27/eclipse-theia-ide.aspx
Some seven years in the making, the Eclipse Foundation's Theia IDE project is now generally available, emerging from beta to challenge Microsoft's similar Visual Studio Code editor, with which it shares much tech.
I'm trying to make minesweeper using rust and bevy, but it feels that my code is bloated (a lot of for loops, segments that seem to be repeating themselves, etc.)
When I look at other people's code, they are using functions that I don't really understand (map, zip, etc.) that seem to make their code faster and cleaner.
I know that I should look up the functions that I don't understand, but I was wondering where you would learn stuff like that in the first place. I want to learn how to find functions that would be useful for optimizing my code.
When resizing an X11 window with OpenGL content, the image becomes garbled and certain parts of the window, usually at the parts that wasn't originally part of the initial framebuffer.
I couldn't find any documentation on if I supposed to call some extra functions when the window is being resized or not. I otherwise process that even as a system event, so it can be further processed by the program using my API.
I'm writing a specification for a web app that will store sensitive user data, and the stakeholder asked that I consider a number of fairly standard security practices, but also including that the data be "encrypted at rest", i.e. so that if someone gains physical access to the hard disk at some later date the user data can't be retrieved.
The app is to be Node/Express on a VPS (probably against sqlite3), so since I would be doing that using an environmental variable stored in a file on that same computing instance, is that really providing any extra security?
I guess cloud big boys would be using key management systems to move the key off the local instance, and I could replicate that by using (Hashicorp Vault?) or building a service to keep the key elsewhere, but then I'd need secure access to that service, which once again would involve a key being stored locally.
What's your thoughts, experience, or usual practice around this?
I'm working on a little gui app that will eventually (hopefully) add a watermark to a photo. But right now I'm focused on just messing around with tkinter and trying to get some basic functionality down.
I've managed to display an image. Now I want to change the image to whatever is in the Entry widget (ideally, the user would put an absolute path to an image and nothing else). When I click the button, it makes the image disappear. I made it also create a plain text label to see if that would show up. It did.
Okay, time to break out the big guns. Add a breakpoint. py -m pdb main.py
. it works. wtf?
def change_image():
new_image = Image.open(image_path.get()).resize((480, 270))
new_tk_image = ImageTk.PhotoImage(new_image)
test_image_label.configure(image=new_tk_image)
breakpoint()
with the breakpoint, the button that calls change_image works as expected. But without the breakpoint, it just makes the original image disappear. Please help me understand what is happening!
edit: all the code
import io
import tkinter as tk
from pathlib import Path
from tkinter import ttk
from PIL import ImageTk
from PIL import Image
from LocalImage import Localimage
from Layout import Layout
class State:
def __init__(self) -> None:
self.chosen_image_path = ""
def update_image_path(self):
self.chosen_image_path = image_path.get()
def change_image():
new_image = Image.open(image_path.get()).resize((480, 270))
new_tk_image = ImageTk.PhotoImage(new_image)
test_image_label.configure(image=new_tk_image)
breakpoint()
TEST_PHOTO_PATH = "/home/me/bg/space.png"
PIL_TEST_PHOTO_PATH = "/home/me/bg/cyberpunkcity.jpg"
pil_test_img = Image.open(PIL_TEST_PHOTO_PATH).resize((480,270))
# why does the resize method call behave differently when i inline it
# instead of doing pil_test_img.resize() on a separate line?
root = tk.Tk()
root.title("Watermark Me")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky="NWES")
layout = Layout(mainframe)
image_path = tk.StringVar()
tk_image = ImageTk.PhotoImage(pil_test_img)
test_image_label = ttk.Label(image=tk_image)
entry_label = ttk.Label(mainframe, text="Choose an image to watermark:")
image_path_entry = ttk.Entry(mainframe, textvariable=image_path)
select_button = ttk.Button(mainframe, text="Select",
command=change_image)
hide_button = ttk.Button(mainframe, text="Hide", command= lambda x=test_image_label:
layout.hide_image(x))
test_text_label = ttk.Label(mainframe, text="here i am")
empty_label = ttk.Label(mainframe, text="")
for child in mainframe.winfo_children():
child.grid_configure(padx=5, pady=5)
entry_label.grid(column=0, row=0)
image_path_entry.grid(column=1, row=0)
hide_button.grid(column=0, row=3)
select_button.grid(column=0, row=4)
test_image_label.grid(column=0, row=5)
empty_label.grid(column=0, row=6)
image_path_entry.insert(0,TEST_PHOTO_PATH)
image_path_entry.focus()
breakpoint()
root.mainloop()