Skip Navigation

User banner
Learn Programming

Members
0
Posts
47
Created
3 yr. ago

Posting Etiquette

  1. Ask the main part of your question in the title. This should be concise but informative.
  2. Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.
  3. Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.
  4. 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

🌉 bridged from !learn_programming@programming.dev by Tidepool

I made an Anti-AI blocklist using a python script.

I don't know how reliable or practical it is. After learning python programming I needed to work on any project to actually improve my skills and understand how python works. So i built a Anti-AI blocklist using various sources and my own manual denylist.

I also implemented a dead domain link filtering by trying to initialize a query to each entries. If it fails more than 10 times, it will be added to dead domains, only applicable for external sources. Yes, I know most of you guys will ask what if some domains get blocked by security firewalls. I don't know. In my research I found that there is no ways to identify it is blocked by a firewall or actually a dead domain by the response received. But I will try to improve it as i can.

The update process is done using github actions. First I setup built-in scheduling only to realize even after 12 hours days it didn't run atleast once. So after getting fraustrated I used a domain called cron-job.org to setup triggers. Now it working flawlessly.

github.com

I struggle to find material that is easy enough for me to follow and well structured

I've done a bit of programming before. I'm in a bachelors program for structural engineering, but they only get us to focus on Python.

Python material is so very wordy. I often try to restart from basics, and there's a lot of 'you have to reinstall it and use the pure python version, it's the only way you'll learn it properly' - but I find this way more confusing than using an IDE. I struggle to implement new libraries as well, in my existing IDE (i use spyder). Feels so clunky.

I want to be able to make things i can actually use, practice programming regularly, but I'm really not good at self directed stuff. Or even setting things up, as i tried to explain with the second paragraph. Any pointers towards relevant resources?

Trying to learn website development by developing my own from scratch.

I am learning website development on my own by developing a website using HTML, CSS, and JavaScript. Currently there is no JavaScript used, as I am still developing and learning new things related to HTML and CSS. I am just at the beginning stage. Actually, this is very interesting, as I am not learning a pre-designed textbook or YouTube videos. I am actively building a website and learning from it. I already used HTML templates and Hugo and Zola, like static website generators. So writing code was never harder, but implementing features or arranging screen space is a big pain. I know the site looks a lot uglier, but before it was more ugly and misaligned than this. At least I managed to make it like this. Note: The posts and contents on this website are converted from my Hugo site, which used Markdown format. The site link is provided at the footer, and the code is also on GitHub. The images are from Unsplash and Pixel sources.

habitant5830.github.io

From HTML and CSS to JavaScript

I recently posted about how I started to study web development by creating my own site. Even though at first it felt very hard and I was struggling, I managed to understand it well and designed the website well myself. Also, I managed to adjust the size on websites for different screens.

So after getting the decent amount of knowledge about HTML and CSS, I decided to learn JavaScript also. As a complete beginner planning to learn and write JavaScript. I thought it was the dead end to my website development journey. But the logic of Javascript was very identical and comparable to Python programming, as I already know Python basics very well. After learning some basics of JavaScript, I managed to implement a greeting message on my website using the if/else loop.

posting this update as a motivation to someone who easily gives up or feels overwhelmed on their web development. Also, I would like to inform you that I still didn't give up and am still trying to learn it by utilising my free time. I believe that my childish coding would help someone that can also do HTML, CSS and Javascript and improve themselves on it.

On the first day nothing will be perfect, but eventually it will be.

Is there a way to see if some variable is stored on the stack or the heap?

I believe I have a good understanding of what is stored on the stack(for example primitive data types) and what's stored on the heap(for example an instance of a class. But is there anyway to verify this for educational/verification of my expectations reasons?

It can be in a debugger(gdb or rad debugger or worst case vs) or directly code based(thinking something like gettype(variable) but like isstackstored(variable).

How do I get help with programming structure?

I'm quite new to programming and my projects getting big by my own standards. When I go to add a new feature im really struggling to evaluate the different options how/where to add it and im getting overwhelmed to the point of not progressing. I find myself wanting to seek some generic guidance from someone whos experienced but I dont know what the right question is to even ask. I want to ask things like "how should I structure a project" or "What kind of patterns can I use to keep my project manageable" "what do I put in code comments"

Practice and experience, but is there anything I can do to find the right direction to go to learn? I dont have the words to know what im even looking for at the moment I just have "pattern" like a design pattern and a notebook with a lot of boxes and arrows trying to plan out some kind of structure. I want to read something at least slightly relevant to game design and start trying to follow some tried and true guidance.

I made this post because I wanted to ask about when to expand a class vs. create a new one.

The example: I have a script (ResourceManager) that handles the resources on the game map it tracks loose items,items in storage, reserved items, delivery demand.

I want to add a crafting bills. These bills will want similar things(to reserve items, to making delivery requests, checking resource stockpile and once available the bill activates) and I can reuse a lot of the logic if I just put it in the same place. But its kind of different crafting and management of resources but them am I going to make a new script for every new thing at some point I just got to put similar things together right.

What kind of things should I be looking at when trying to evaluate these choices?

I have a kube file, now what?

I’m developing this tiny web app which I want to run on an old laptop and put it on my portfolio.

I used podman, I have a pod with 3 containers, local images and everything is working fine on my workstation.

I envisioned just copying the kubernetes yaml on the old laptop, run play and pat myself on the back. I guess it doesn’t work like that…? Do I need to publish the container images somewhere? And other things? How does it work in a company?

Thanks in advance 😊

Where can I find documentations on how to resolve a git conflict properly?

Today I did a git push --force, then I had to create a branch out of the old code, but other times I had to save the files I worked on, delete the local repository, git clone again, then reapply my fixes. I want to at least have a bookmark on how to fix things in the future. Yes, I've heard about VSCode plugins, that supposed to help. But no, I don't want to use a glorified webpage to do coding, regardless if it's directly tied to Micro$lop, or some of the slop was removed by 3rd parties. I tried KATE once, I cannot go back to some sluggish webpage, which only argument for use at the moment is "but it has plugins".

Any 3rd party tool that alerts me if I have accidentally uncommitted stuff on my local Git repository?

I often forget to push a few things depending on how Git decides to label my work. Today it labeled a move as a file deletion and add, and only the deletion is present on the upstream, and now the upstream doesn't even compile properly. And I don't want to pull out my hair to resolve yet another conflict, because the only help with Git I can get is jUsT reAD ThE WhoLE maNUaL.

One other thing is that I refuse to use VSCode, especially since they're pushing AI slop code generation so much, and I use KATE instead.

Help suggest a data structure to hold objects so I can quickly look for the object by Keys

I want to preface this by saying that I think I got cooked by AI here. I have a game where I am working on a job system. The job system has a job objects which I need to put into a data structure that can be searched via id, location, or work type. At first I was building with the mindset of "do whatever to solve this problem and make it work" but it became very hard to implement new features because I would break everything. So I started trying to think ahead and design ways of doing things that would handle all the different jobs and things. At first I put all jobs into an array and iterated through. Then I learned about dictionaries and started using them for way to many things and so i updated my job queue to be a dictionary with the Key as ID > JobObj Then I decided to plan out the job system before writing anything and "do it properly". I decided I needed to upgrade the data structure holding jobs because its a core part of the game and will be heavily interacted with. But I realized I only know array, dictionary and database, so I asked AI what data structure I should use and it suggested a nested dictionary. Now im using multiple dictionaries but im really hating it. Its hard for me to work with and conceptually im not sure I can visualize how its even working. How I am thinking about it is there is multiple layers of keys, 1st layer is work types, then once I find the work type it points to a dictionary of region IDs and that points to an array of jobs in the region. Job def is work type like Planting Region id: the map is broken down into region IDs so i dont have to check every tile and can limit seaching

 
#python
var job_pool: Dictionary = {}

func register(designation: DesignationObj) -> void:
	var job_def = designation.job
	var region_id = designation.region_id
	if not job_pool.has(job_def):
		job_pool[job_def] = {} 
	if not job_pool[job_def].has(region_id):
		job_pool[job_def][region_id] = []
	job_pool[job_def][region_id].append(designation)

Here is how I am picturing it in my head.

 
var job_pool {
	"plants": {
		"1": {
			"job1"
			"job2"
		}
		"2": {
			"job3"
		}
	}
	"mining": {
		"1": {
			"job4"
			"job5"
		}
	}
	"hunting": {
		"5":{
			"job12"
		}
	}
}

But now I want to add ID look up into this im stuck and im thinking the entire structure does not work for what it needs to do.

Beginner
C

If we can represent true/false with 1/0, why do we need the stdbool library and boolean variables?

I saw one example

 
int x = 10;
int y = 5;

bool isGreater = x > y;

printf("%d", isGreater);

But I could write this

 
int x = 10;
int y = 5;

printf("%d", x > y);

I am a complete beginner and I have no real reason why I would or would not want to deal with boolean variables, but I want to understand their raison d'être. Edit: typo city

Help with nandgame: stack machine function calls

cross-posted from: https://sopuli.xyz/post/45002077

If this isn't the right community for this post, let me know and I'll move it somewhere else. I'm working my way through nandgame, and I'm stuck on the "call" macro in the function calls section of the stack machine unit. These are the instructions: image image I was stuck on it for a while, so I looked up the solution and am going off the one given here (it's the only one I could find). So far, I haven't gotten it to work. At first, it was giving me syntax errors because the labels weren't defined, so I replaced A = [LABEL] with label [LABEL] followed by A = [CONST], according to the specified calling convention. It also gave me a similar syntax error for TEMP_ADDR, which is never specified in the instructions, so I assigned it 0x7f00. So here is what I end up with (all in Assembly): (note: the stack pointer, SP, is defined by a shared constant SP = 0) Test code:

 
init.stack
call functionName 0
stop

function FunctionName 0
push.value x42
return

Macro: call

 
# Assembler code
## Push the current ARGS and LOCALS on the stack
push.static ARGS
push.static LOCALS

## Push the return address.
push.value after

## Set ARGS to point to the start of the arguments
A = SP
D = *A
A = argumentCount
D = D - A
A = 3
D = D - A
label ARGS
A = 1
*A = D

## Jump to functionName.
goto functionName

## Set return address:
label after

## Restore ARGS and LOCALS from the stack
A = ARGS
D = *A
label TEMP_ADDR
A = 0x7f00
*A = D
pop.D
label LOCALS
A = 2
*A = D
pop.D
A = ARGS
*A = D

## Push RETVAL.
label RETVAL
A = 6
D = *A
push.D

Macro: function

 
# Assembler code
## Define a label functionName
label functionName

## Set LOCALS to the current SP
A = SP
D = *A
label LOCALS
A = 2
*A = D

## Advance SP by localsCount
A = localsCount
D = A
A = SP
D = D + *A
*A = D

Macro: return

 
# Assembler Code
## Pop the top value into RETVAL
pop.D
label RETVAL
A = 6
*A = D

## Set SP to LOCALS
label LOCALS
A = 2
D = *A
A = SP
*A = D

# Pop the return address and jump to it
pop.D
A = D
JMP

Note: functionName, argumentsCount, and localsCount are all listed as placeholders above the relevant macro, but it doesn't describe how to define these. I'm guessing that comes in a later unit. The code block for the call macro gives me a red bar for each line with a placeholder, but this doesn't happen for the function macro which also includes placeholders. In any case, this doesn't seem to get in the way of the program as it still runs smoothly. So as it is, when I run it, everything seems to work as intended. This is the result when it reaches the stop macro (infinite loop): image Which looks like it's doing everything it's supposed to do. But when I click "Check solution", this is what it says: image ("Expected SP (RAM address 0) to be hex 101. (Was 104)") Which is strange, because in the computer section you can clearly see that the SP content is hex 0101. So I don't know what's going wrong. I stepped through the program tick by tick, and the only place SP ever reaches 104 is after the function macro, when it runs push.value x42, after which it runs the return macro which begins with pop.D, reducing SP back to 103. Could it be the evaluator is assessing the value of SP at the end of the code block, instead of where it runs the stop macro? So perhaps I could try replacing stop with a jump to the end, followed by stop... Now that I think of that, I think it might work. I'm still going to post this though, because I already went through all the trouble. And in case it doesn't work, if anyone else has any ideas please share them! I can expand the rest of the macros if need be, but they already passed the evaluation so they're all working according to specs. Thanks in advance! Edit: I thought for sure that would work. I changed the test code block to this:

 
init.stack
call functionName 0
A = end
JMP

function FunctionName 0
push.value x42
return
label end
stop

The program runs exactly as it's supposed to, except now the stop loop is at the end of the code. The computer output still looks the same, except now the program counter loops between 60 and 61 at the end (as expected). But the evaluator is still giving me the same error! I'm stumped... Edit 2: added annotations to code blocks to make it easier to read