1
10
submitted 2 years ago* (last edited 2 years ago) by JaumeI@programming.dev to c/learn_programming@programming.dev

This community is aimed at two specific topics:

  • Support general programming questions, of any language, mainly for people beginning their journey in programming.
  • Give some advice on programming education or career.

What this community doesn't intend to do:

  • Give specific answers to very specific, non-beginners, problems of a particular language. You probably can go to a community of that language to get help with that.
  • Solve your programming assignments. You can ask for a specific issue, but it's essential that you learn to think and solve them, or you'll never progress.

As suggested by Captain Janeway, here are some rules specific to the posts:

  • Paste your code. Unless there's not any other way, please don't provide screenshots of the code, it's harder to review.
  • If possible, try to provide a runnable example of the code in question
  • Explain as much as you can: what you’ve tried, what the error is, what you think the problem is
  • As usual, be kind

The probability of getting an answer will increase dramatically if you follow these points.

This post will be updated periodically, with any new inputs considered necessary.-----

2
1

Currently I'm having an issue with WASAPI when using the format reported by the OS and it's WAVEFORMATEXTENSIBLE (which is needed for certain devices, or else the audio stream won't open with E_INVALIDARGS all for standard IEEE floating point format WITH NO CHANGES!!!), meaning I get no sound even though the stream is initialized and stuff.

However, every time I try to search any WASAPI related issues, all I get is either 10+ years old stackoverflow posts at best (I'd rather die a painful death than to re-register to that hellsite - I got a year long ban every time I posted there, once exactly due to asking about WASAPI, and all I got told to just use SDL, meanwhile SDL forums instead wanted me to use a 3rd party DLLs for live audio playback, by writing it first to a WAV file(!!!)), and otherwise my search result is instead flooded with general purpose Windows troubleshooting tips.

No, I also don't want to use AI slop. I don't know whether the sycophancy of AI or the elitism of stackoverflow users are worse.

3
6
submitted 1 day ago* (last edited 1 day ago) by gera@feddit.nu to c/learn_programming@programming.dev

I like writing the Game of Life as a helloworld program when learning graphics libraries because the naive algorithm is very easy to implement. It is however pretty slow. I want to try writing something more efficient than doing a whole pass through the board each frame, so I wonder which "fast" algorithm is more or less easy to understand and implement?

4
64

I don't need something practical. I just need something fun to keep me motivated.

5
10
submitted 1 week ago* (last edited 1 week ago) by andioop@programming.dev to c/learn_programming@programming.dev

I feel this post had pretty good answers in the replies, and figured it's a post people learning programming might want to see.

6
6
submitted 1 week ago* (last edited 1 day ago) by ZILtoid1991@lemmy.world to c/learn_programming@programming.dev

I need it to get low level access to some PlayStation Dualsense controller features, such as adaptive triggers and setting colors.

UPDATE: The function is missing from the VTables likely due to vibe coding, but I found a workaround. Opening the device's pnpPath as a file will grant you evdev-like access to the device.

7
9

This question comes mainly from curiosity. I'm not quite sure how to phrase it best. Especially in a title. But I'm wondering if say you have one thread writing to a variable of an essentially primitive type and one thread reading them at the same time if there's any likelihood of the read happening while the variable is half written causing either weird values or undefined behavior.

Take something like a value of 8 bits from 00010101 to 11101000.

I'm imagining if say 4 bits are written while we try to read it the result could be something like

11100101

To play around i made this small sample rust. It passed without making garbage. Printing at first a bunch of lines stating "String = Hello!" and second "String = Hi!" without weirdness or issues. I kind of half-expected something like "String = #æé¼¨A" or a segfault.

use std::thread::{self, JoinHandle, sleep};

const HELLO: &str = "Hello!";
const HI: &str = "Hi!";

struct ExemptSyncStringSlice<'a>(&'a str);

unsafe impl Sync for ExemptSyncStringSlice<'_> {}

fn print_ptr(pointer: *const ExemptSyncStringSlice)
{
	for _ in 1..500
	{
		unsafe
		{
			println!("String = {}", (*pointer).0);
		}
	}
}

fn main()
{
	
	static mut DESYNC_POINTER: ExemptSyncStringSlice = ExemptSyncStringSlice(HELLO);

	let join_handle: JoinHandle<()> = thread::spawn
	(
		|| {
			print_ptr(&raw const DESYNC_POINTER);
		}
	);
	sleep(time::Duration::from_millis(1));
	unsafe { DESYNC_POINTER.0 = HI; }
	
	join_handle.join().unwrap();
}
8
7
9
3
submitted 1 month ago* (last edited 1 month ago) by ZILtoid1991@lemmy.world to c/learn_programming@programming.dev
  • It tries its best to default to master.
  • it always creates a master branch.
  • it throws a bunch of errors when trying to push to main.
  • I always have to do some random fiddling to make it work with the main branch, but at least once I made master the main one instead.
  • it ruined a few releases of mine, by publishing the older branch.
  • apparently this is very abnormal, and no one saw things like this.
  • every time I initialize a new repo, I make sure to run a git clone to initialize it on my PC, which is called main, then it defaults to master for no known reason.
  • checked the .gitconfig file, and nothing unusual.
10
1

I have been taking a class called solve it this holiday to learn programming with LLM assisting. The result was fun. One of the projects I did was building platonic solids paper templates. I wish i had learnt these in my geometry class.

After hand building a template for each of the shapes, I thought I just want an LLM build one for me by giving it the shape that I wanted. Surprisingly this is really hard for them. They can't get a single one right. https://share.solve.it.com/d/c6ca11ce650450ab2bb38b5193dac44e

Then my teacher joined and help me make it better (but llm still cannot fo it): https://share.solve.it.com/d/cb0c3b8d182b040de1b20a078b04ec98

11
3

Problem is that when I use libevdev (which is needed for game controllers under Linux), it locks up x11 events until I produce an input on a game controller. Libevdev documentation is cryptic and incomplete, with many implementations using read() instead of libevdev_next_event() for some reason. Only help with it is how to configure it on various Linux distros, or that which library already solves this issue, except they would force me to use them for a lot of other things, and would still force me to write abstractions to make things looking nice.

12
5
JavaScript 30. (javascript30.com)

Build 30 things in 30 days with 30 tutorials

13
6

According to Microsoft documentations, I'd need to use nuget to load the GameInput library. Issue is that I'm only using the MSVC linker, not the whole MS toolchain, especially as my language of choice is D.

(I can also accept other alternatives to load the GameInputCreate function.)

14
4

JPlus is a modern programming language and compiler that acts as a superset of Java — bringing the benefits of null safety and powerful boilderplate code generation declarative features while remaining fully interoperable with existing Java code and libraries.

15
1

Null-pointer exceptions are a common error in Java, causing inconvenience for many developers. Preventing null pointer exceptions in advance is important, but for developers who want to focus solely on logic, handling them can be tedious. Moreover, it’s not always easy to account for every scenario. Typically, static analysis tools are used to detect potential null pointer issues, but developers still have to find and fix the code themselves. JPlus reduces that burden. Let’s write null-safe Java code with JPlus.

16
3
17
2
18
9

I'm looking to write a simple program which can run both on Win XP SP3 (ideally without added dependencies, if it all possible) and modern Linux. Really, it should be platform agnostic but XP and Linux are what I'm specifically interested in.

The program will be for managing my cd-keys for my XP games. It'll have a simple gui with a search box and an output box. It'll parse text files in it's subdir when searching via search box and output the cd-key string contained within.

From what I can see, it would be good/viable to use C++ so it runs on XP and Linux and use gtkmm3 for the UI for the same reason.

Does this make sense or am I missing something glaringly obvious? Any input would be much appreciated~

19
4
20
12
submitted 5 months ago* (last edited 5 months ago) by andioop@programming.dev to c/learn_programming@programming.dev

I looked for APIs to do something. I found a bunch of APIs that will do the job I want. How does one pick between them when all of them will do the job in the right language/framework?

This also made me think of another question. I've heard of interviews for tech jobs asking people what tools they'd use to solve a certain problem. I figure the way I'd do that is exactly how I tried to find an API. Just directly look for a tool that can do your job online, see what the options are, and only click the ones that actually do what you want. I am very entry-level (recent CS grad, wish me luck) in the learn-more-by-doing stage, and am wondering if you're expected to have a deep knowledge of most of the tools out there or what, and how one does that.

21
14
22
4

cross-posted from: https://gregtech.eu/post/16712875

Marshaling the field is fine, so using the tag json:"-" won't work. I could use the UnmarshalJSON method on the struct, but I have no idea how to implement it.

I'd rather not make a duplicate of the struct with that field removed, as it causes quite a bit of code duplication, and it's pretty chaotic.

23
6

cross-posted from: https://gregtech.eu/post/16416819

Hi, what's the best way for testing a gin route?

I currently have one function where the routes are defined. Here it is:

package router

import (
	"github.com/gin-gonic/gin"
	"github.com/gragorther/epigo/handlers"
	"github.com/gragorther/epigo/middlewares"
)

func Setup(userUserStore handlers.UserUserStore, groupGroupStore handlers.GroupGroupStore, groupAuthStore handlers.GroupAuthStore, messageAuthStore handlers.MessageAuthStore, messageMessageStore handlers.MessageMessageStore, middlewareUserStore middlewares.UserStore) *gin.Engine {
	r := gin.Default()
	r.Use(middlewares.ErrorHandler())

	userHandler := handlers.NewUserHandler(userUserStore)
	authHandler := middlewares.NewAuthMiddleware(middlewareUserStore)
	groupHandler := handlers.NewGroupHandler(groupGroupStore, groupAuthStore)
	messageHandler := handlers.NewMessageHandler(messageMessageStore, messageAuthStore)

	// user stuff
	r.POST("/user/register", userHandler.RegisterUser)
	r.POST("/user/login", userHandler.LoginUser)
	r.GET("/user/profile", authHandler.CheckAuth, userHandler.GetUserProfile)
	r.PUT("/user/setEmailInterval", authHandler.CheckAuth, userHandler.SetEmailInterval)

	// groups
	r.DELETE("/user/groups/delete/:id", authHandler.CheckAuth, groupHandler.DeleteGroup)
	r.POST("/user/groups/add", authHandler.CheckAuth, groupHandler.AddGroup)
	r.GET("/user/groups", authHandler.CheckAuth, groupHandler.ListGroups) // list groups
	r.PATCH("/user/groups/edit/:id", authHandler.CheckAuth, groupHandler.EditGroup)

	// lastMessages
	r.POST("/user/lastMessages/add", authHandler.CheckAuth, messageHandler.AddLastMessage)
	r.GET("/user/lastMessages", authHandler.CheckAuth, messageHandler.ListLastMessages)
	r.PATCH("/user/lastMessages/edit/:id", authHandler.CheckAuth, messageHandler.EditLastMessage)
	r.DELETE("/user/lastMessages/delete/:id", authHandler.CheckAuth, messageHandler.DeleteLastMessage)
	return r
}

so, my question is, how can I test just one route? should I run this function in every test and send a request to a route with httptest? Or should I set up my handlers like it's described at https://gin-gonic.com/en/docs/testing/

(like this)

func postUser(router *gin.Engine) *gin.Engine {
  router.POST("/user/add", func(c *gin.Context) {
    var user User
    c.BindJSON(&user)
    c.JSON(200, user)
  })
  return router
}

let me know if you have any other questions about my code.

It's available on github: https://github.com/gragorther/epigo

24
7

Basically, I'm trying to figure out how I could allow a user to send a schedule in the cron syntax to some API, store it into the database and then send an email to them at that interval. The code is at gragorther/epigo. I'd use go-mail to send the mails.

I found stuff like River or Asynq to schedule tasks, but that is quite complex and I have absolutely no idea what the best way to implement it would be, so help with that is appreciated <3

25
12

I use Gorm. This is the current code:

package main

import (
	"fmt"
	"log"

	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

type Env struct {
	DB     *gorm.DB
	Logger *log.Logger
}

type User struct {
	ID           uint
	Username     string
	Name         string
	Email        string
	PasswordHash string
	Country      string //should probably be a foreign key of another table
}

func initDB() {
	env := &Env{}
	db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
	if err != nil {
		fmt.Printf("Error opening database: %v", err)
		return
	}
	env.DB = db
	env.DB.AutoMigrate(&User{})

}

func main() {
	initDB()
}

As you can see in the comment in the code, I assume the best way would be to have a table of countries and then assign each user to one via a foreign key. However, it seems a bit cumbersome to manually create a list of all countries. Is there a better way to do this?

view more: next ›

Learn Programming

2086 readers
8 users here now

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

founded 2 years ago
MODERATORS