r/StackoverReddit • • Jul 10 '24

C Cheezee: ncurses chess client

Post image
18 Upvotes

Cheezee (pronounced as cheese) is my first ncurses project which I wrote in pure C. You can enjoy chess from the standard position or specify a custom position with the FEN notation when launching the program with the --fen argument or type out the FEN string when the program is already running.

You can play every single possible move in chess (including casteling and en-passant) and checkmate or stalemate your opponent.

The github repository is here: https://github.com/detectivekaktus/cheezee

It's my first big project in C that relies on something different than a standard C library, so I hope you find it interesting.

Vim users can enjoy the motions with hjkl keys. I'd also like you to share your thoughts about the project.


r/StackoverReddit • • Aug 07 '24

INFO!!! We are moving to r/stackoverflow !!!!

17 Upvotes

We want everybody to please be aware that all future posts and updates from us will from now on be on r/stackoverflow

We made an appeal to gain ownershift of r/stackoverflow because it has been abandoned, and it got granted!!

So please migrate with us to our new subreddit r/stackoverflow ;)


r/StackoverReddit • • Jun 26 '24

Introducing Our Wiki Page!

12 Upvotes

Whether you are a beginner, an expert, or simply looking to deepen your knowledge, this page is designed for you. Here, you can find information ranging from basic coding terms to the best certifications suited for your career path.

We welcome any feedback or additional information you would like to see on this wiki page. Please feel free to share your suggestions!

https://www.reddit.com/r/StackoverReddit/wiki/guide/


r/StackoverReddit • • Jun 20 '24

I beg of you, please help, I'm about to rip my hair out

8 Upvotes

I can't solve this problem and I have no idea why. I've been trying for ages. It consumes my very soul! This is all I can think about!!!

Please help me before I go bald ripping my hair out!

Problem: https://open.kattis.com/problems/safesecret

My current (not fully working) solution: https://www.online-cpp.com/ZPE3atKl7y


r/StackoverReddit • • Jul 29 '24

Service Seriously??

7 Upvotes

You can't even post just because you are new to platform and couldn't create good post. reddit is much better rather than reading whole term and policy kind of length guideline


r/StackoverReddit • • Jul 27 '24

Challenge Weekly challenge #1

7 Upvotes

Hello everyone!

As a way to raise the interaction levels of the sub the mod team has come up with the idea of having a weekly coding challenge where everyone can participate and comment on each other's projects.

The format, at least for the first couple of weeks, will be a simple challenge that can be completed in a single code file. As such, you can use pastebin or post the code directly in a comment as long as it's correctly formatted. For the time being no rewards will be offered since the goal of these challenges is to practice your skills and get feedback from others and if there's a compensation incentive we're afraid people will skip directly to using AI generated code. Please abstain from using tools such as Chat-GPT, Claude or Llama, the objective of the challenge is to showcase your skills and learn so it doesn't matter if you did something right or wrong.

Without much more to add this week's challenge will be A UNIT CONVERTOR.

As a way to assess the skill levels of the overall sub we've decided not to go with anything overly difficult. In this challenge you're tasked to make a unit convertor. You can work with any units, be it temperature, mass, velocity, volume, etc. Try and convert from one measurement system to another such as from imperial to metric or work within the same system such as meters to kilometers to centimeters. Bonus points for using more extravagant units! Any language can be used for this challenge.

We're also open to ideas for future challenges so anything you have in mind feel free to comment it...

Have fun and remember to give feedback to others!


r/StackoverReddit • • Jun 26 '24

Solved C++ variadic template situation absolutely vexing me.

7 Upvotes

Disclaimer: I'm self taught so my vocabulary may be lacking. I'm also on embedded and some of the platforms have a non-compliant and/or incomplete STL implementation so I'm not using it, because it's a lot of work to enumerate the platforms I'd need to fork for.

This is template metaprogramming territory. There be dragons.

I'm trying to extend this:

rgb_pixel<24> foo;    
foo.channel<channel_name::R>(63);

To take multiple channel_names at once, and allow you to set a number of channels at the same time.

rgb_pixel<24> foo;    
foo.channel<channel_name::R,channel_name::G,channel_name::B>(63,31,47);

The problem: In essence I need to filter certain values out of a parameter pack while it's being expanded OR I need to accept two parameter packs to a template. Since neither of those things are directly possible to my knowledge in C++17 (14 preferred) I need a clever workaround.

Lacking that workaround, I've created several overloads for channel<>() that take between 1 and 5 channel names, but this is less than ideal. I'd prefer it to be variadic, not the following:

// sets the integer channel value by name
template<typename Name>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name>::value>::int_type value) {
    constexpr const int index = channel_index_by_name<Name>::value;
    channel<index>(value);
}
// sets the integer channel values by name
template<typename Name1, typename Name2>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name1>::value>::int_type value1,
                                typename channel_by_index<channel_index_by_name<Name2>::value>::int_type value2) {
    constexpr const int index1 = channel_index_by_name<Name1>::value;
    channel<index1>(value1);
    constexpr const int index2 = channel_index_by_name<Name2>::value;
    channel<index2>(value2);
}
// sets the integer channel values by name
template<typename Name1, typename Name2, typename Name3>
constexpr inline void channel(typename channel_by_index<channel_index_by_name<Name1>::value>::int_type value1,
                                typename channel_by_index<channel_index_by_name<Name2>::value>::int_type value2,
                                typename channel_by_index<channel_index_by_name<Name3>::value>::int_type value3) {
    constexpr const int index1 = channel_index_by_name<Name1>::value;
    channel<index1>(value1);
    constexpr const int index2 = channel_index_by_name<Name2>::value;
    channel<index2>(value2);
    constexpr const int index3 = channel_index_by_name<Name3>::value;
    channel<index3>(value3);
}

These are several overloads of the channel<>() template method on my pixel<> template struct.

You'll note they are overloads that simply take an increasing number of Name template arguments (shown are 3, but I have 5)

I'd much rather use a variadic template here but I can't because I end up in a situation where I need to use two variadic templates at the same time.

Line 503 of this file is where my pixel template begins, and you'll see it takes a variadic template of "channel traits" (defined above that a ways)
https://github.com/codewitch-honey-crisis/gfx/blob/master/include/gfx_pixel.hpp

The problem is in order to resolve anything about a pixel channel - which is necessary to set it - I need these "channel traits" to be able to be unpacked because it's used by things like channel_index_by_name<>.

I wish I had the language to describe the problem better, or failing that, I wish I wasn't so far in the weeds here that I could describe the problem better. Any insight would be appreciated. I've already posted variations of this question on a couple of other places online, but I've had no luck.


r/StackoverReddit • • Jun 22 '24

advice on what to pick up as skill and knowledge next

7 Upvotes

Hello,

I study computer science and know a moderate amount about java and c and a bit about python and c++ when I say a bit I mean I solved leetcode problems with the language and followed along a tutorial on how to automate a process like webscraping with python and I (tried) to implement a neural network in c++.

I enjoy algorithmic/datastructures problems but probably software architecture as well and dont know how to continue picking up knowledge.

I am about to follow a tutorial on writing an interpreter in java and after that I want to learn Rust.

Should I revise my Software Engineering lecture because I forgot almost everything or read something related before doing more projects?

Thanks!


r/StackoverReddit • • Aug 04 '24

Challenge Weekly Challenge #2

6 Upvotes

This week's challenge will be a COLLECTION MANAGER.

Do you keep a collection of any kind, be it coins, figurine or baseball cards? Do you keep track of everything you have and how much it's all worth? Try and automate this process by tracking your entire collection. Try and store all objects you have, it's name, description and price. Make it so you can add and remove elements and calculate the total price of the collection.

You can do it in memory or try and implement a database. Same as before, you can use any language or framework you want. Please abstain from using any AI tools as the purpose of these challenges is to learn.

You can post the code directly in the comments, a pastebin or a repository.


r/StackoverReddit • • Jul 27 '24

C Brainfuck x86_64 execution toolset for Linux: interpreter and compiler

6 Upvotes

Hello, redditors! With a great joy I want to share my first toolset made of interpreter and compiler for x86_64 processor architecture that is able to produce ELF64 executables for Linux.

I always had a dream of implementing an interpreter or a compiler and I finally achieved this goal by creating both for the brainfuck programming language in C. To implement the compiler I learned some basics of the x86_64 NASM assembly from scratch.

You can find the source code at GitHub repo: https://github.com/detectivekaktus/brainc, it also has some examples you can run with the toolset.


r/StackoverReddit • • Jul 19 '24

Question How many network connections does the average cell phone have open at any given time?

6 Upvotes

Off the top of my head I'd count

  • GPS

  • Weather

  • News

  • Music

  • RSS feeds

  • Podcasts

  • Google/Microsoft/Apple account sync


r/StackoverReddit • • Jul 19 '24

Question Does anyone know about low cost API for TTS that are human like ?? or even an opensource model

6 Upvotes

I am trying to develop an app that will live transcrib the content onscreen (and it will be opensource !!)


r/StackoverReddit • • Jul 10 '24

Javascript Habit tracker: How can I create instances of habits for the next 30 days, so that the habit instances do not need to be created to infinity?

6 Upvotes

I'm currently developing a habit tracker application using MongoDB and Next.js, and I'm facing an issue with creating instances of habits for users. Here’s a brief overview of my current setup:

I have three collections in my MongoDB database:

  1. Users: Contains user information.

  2. Habits: Contains details about habits such as habit name, description, frequency (daily or specific days of the week), and time.

  3. HabitInstances: Contains instances of habits for specific dates, with fields for user ID, habit ID, date, and status (completed or not).

When a user adds a new habit, it is saved in the Habits collection. Here is an example of a habit:

The challenge I'm facing is efficiently generating instances of these habits for the next 30 days without creating them indefinitely. For instance, if a user wants to repeat a habit every Monday, Tuesday, and Wednesday, I need to create instances for the next 30 days so that when the user checks the app, they can see their habits scheduled for those specific days.

Creating these instances indefinitely would be inefficient and could lead to performance issues, especially with many users.

Could anyone provide a detailed explanation or example of how to generate these habit instances for the next 30 days based on the habit's frequency? Any guidance on implementing this in MongoDB and Next.js would be greatly appreciated.

Thank you!


r/StackoverReddit • • Jul 09 '24

Python Photoshop API - Read and Write PSD files with Python and C++

6 Upvotes

Hey,

Emil Dohne is creating a modern and performant C++20 read/write parser of Photoshop Files (*.psd and *.psb) with fully fledged Python bindings hosted on PyPi, completely on its own.

I just wanted to help him out trying to make his work known, so that more people can utilize this incredibily useful repo and in order to find someone incredibly talented and kind people that wanted to help him out collaborating in the development! At the moment Emil is occupied by another project that he will end by the end of July and he will then be back 100% on this project.

I reckon that the hierarchy of new features needed/really wanted are the following:

  1. Support for Smart Object Layers - replacing images inside of the smart object

  2. Support for Adjustment Layers

  3. Support for Vector Masks

  4. Support for Text Layers

  5. CMYK, Indexed, Duotone and Greyscale Color Modes

Thank you to whoever even takes the time to read this, let alone whoever shares this project and even more to incredibly smart people that will help Emil out.

Here's some more info about this project: https://github.com/EmilDohne/PhotoshopAPI

About

PhotoshopAPI is a C++20 Library with Python bindings for reading and writing of Photoshop Files (*.psd and *.psb) based on previous works from psd_sdk, pytoshop and psd-tools. As well as the official Photoshop File Format Specification, where applicable. The library is continuously tested for correctness in its core functionality. If you do find a bug please submit an issue to the github page.

The motivation to create another library despite all the other works present is that there isn't a library which has layer editing as a first class citizen while also supporting all bit-depths known to Photoshop (8-bits, 16-bits, 32-bits). This Library aims to create an abstraction between the raw binary file format and the structure that the user interfaces against to provide a more intuitive approach to the editing of Photoshop Files.

Why should you care?

Photoshop itself is unfortunately often slow to read/write files and the built-in tools for automatically/programmatically modifying files suffer this same issue. On top of this, due to the extensive history of the Photoshop File Format, Photoshop files written out by Photoshop itself are often unnecessarily bloated to add backwards compatibility or cross-software compatibility.

The PhotoshopAPI tries to address these issue by allowing the user to read/write/modify Photoshop Files without ever having to enter Photoshop itself which additionally means, no license is required. It is roughly 5-10x faster in reads and 20x faster in writes than photoshop while producing files that are consistently 20-50% lower in size (see the benchmarks section on readthedocs for details). The cost of parsing is paid up front either on read or on write so modifying the layer structure itself is almost instantaneous (except for adding new layers).

Features

Supported:

  • Read and write of *.psd and *.psb files

  • Creating and modifying simple and complex nested layer structures

  • Pixel Masks

  • Modifying layer attributes (name, blend mode etc.)

  • Setting the Display ICC Profile

  • Setting the DPI of the document

  • 8-, 16- and 32-bit files

  • RGB Color Mode

  • All compression modes known to Photoshop

Planned:

  • Support for Smart Object Layers

  • Support for Adjustment Layers

  • Support for Vector Masks

  • Support for Text Layers

  • CMYK, Indexed, Duotone and Greyscale Color Modes

Not Supported:

  • Files written by the PhotoshopAPI do not contain a valid merged image in order to save size meaning they will not behave properly when opened in third party apps requiring these (such as Lightroom)

  • Lab and Multichannel Color Modes

Python

The PhotoshopAPI comes with fully fledged Python bindings which can be simply installed using

$ py -m pip install PhotoshopAPI

alternatively the wheels can be downloaded from the Releases page. For examples on how to use the python bindings please refer to the Python Bindings section on Readthedocs or check out the PhotoshopExamples/ directory on the github page which includes examples for Python as well as C++.

For an even quicker way of getting started check out the Quickstart section!

Documentation

The full documentation with benchmarks, build instructions and code reference is hosted on the PhotoshopAPI readthedocs page.

Requirements

This goes over requirements for usage, for development requirements please visit the docs.

  • A CPU with AVX2 support (this is most CPUs after 2014) will greatly increase performance, if we detect this to not be there we disable this optimization

  • A 64-bit system

  • C++ Library: Linux, Windows or MacOS

  • Python Library1: Linux, Windows, MacOS

The python bindings support python >=3.7 (except for ARM-based MacOS machines which raise this to >=3.10)

Performance

The PhotoshopAPI is built with performance as one of its foremost concerns. Using it should enable you to optimize your pipeline rather than slow it down. It runs fully multithreaded with SIMD instructions to leverage all the computing power your computer can afford.

As the feature set increases this will keep being one of the key requirements. For detailed benchmarks running on a variety of different configurations please visit the docs

Below you can find some of the benchmarks comparing the PhotoshopAPI ('PSAPI') against Photoshop in read/write performance


r/StackoverReddit • • Jul 07 '24

Python Feedback on a noob's python code?

6 Upvotes

I'm a beginner and I don't know where else to post this. I'd like for people to help run through it, check it for possible bugs and unintended outputs?

I'd prefer not to use ChatGPT since I hear it's killing the ocean now.

I am mainly using Main While Loops, a for loop, Conditional Statements, and print. I haven't learned much beyond that yet.

https://pastebin.com/jMj30Tkw

https://pastebin.com/MVSmuSwW (Forgot the persistent While Loop, better link)


r/StackoverReddit • • Jul 06 '24

Question Is there a way to redirect standard input stream to a program to a file on the shebang line?

6 Upvotes

Given something like

#!/usr/bin/env -S program --option-to-program

is there a way to redirect all standard input to program to a file on the shebang line?


r/StackoverReddit • • Jul 04 '24

Question Need advice regarding scope for a C struct

6 Upvotes

Hi! I've put together a program that defines a struct of function pointers, that then gets passed to many functions in the program. The struct is not expected to get modified throughout the lifetime of the program. Would it be a good thing to make this struct global?

The package:
https://github.com/onyx-and-iris/vmrcli/blob/main/src/vmrcli.c

T_VBVMR_INTERFACE iVMR is the struct in question defined in main().

Here is a branch where I've made the struct global:

https://github.com/onyx-and-iris/vmrcli/blob/extern-ivmr/src/vmrcli.c

As you can see in vmr.c:

https://github.com/onyx-and-iris/vmrcli/blob/main/src/vmr.c

When the struct is defined in main(), I have to pass the struct around to every function. Would it be acceptable, or even a good thing, in this case to make the struct global?

Thanks for any advice you can offer.


r/StackoverReddit • • Jul 02 '24

C# what learning resources can you recommend for C# zero lvl?

6 Upvotes

r/StackoverReddit • • Jun 23 '24

Question What should I study next in backend development after learning the basics?

6 Upvotes

I'm new to backend development. So far, I've learned basics like node js, express js, and I've built a real-time chat app using sockets.io (Websockets). I understand the basics, but I want to get better. What should I learn next? Is it better to learn through projects or should I first learn the tech stack before starting projects? I'd appreciate any advice.


r/StackoverReddit • • Jun 11 '24

This sub has so much potential.

6 Upvotes

r/StackoverReddit • • Jul 30 '24

Python Python - Automation Query

5 Upvotes

Python - Automation Query

Hello Team,

I hope I am sharing my concern on right platform, any help or suggestion would be extremely helpful.

With the help of “copilot” I have setup a python script that helps me extract text from images from ppt files, the script works just as expected however here is a challenge -

The script first extracts images from ppt - converts those images into black and white or binary images - identifies the texts on it and extracts it into excel file.

The challenge is some texts have similar shade to background and when these images gets converted to binary those texts kind of get camouflaged & the script couldn’t read or extract texts from it.

How do I fix this?

FYI - I am using tesseract OCR

Any help here would be highly appreciated. Let me know if any other information might be needed.


r/StackoverReddit • • Jul 29 '24

Java How to easily migrate spring project to java project ?

5 Upvotes

Hello guys I need to migrate a spring boot project to java project. I mean remove all spring features and using java features instead.

Are there someone who done it before? Do you know how to do it quickly and efficiently? Thank you in advance


r/StackoverReddit • • Jul 26 '24

CSS I like the concept and have a couple of additional resources to add to the wiki, if you like.

5 Upvotes

flexboxfroggy.com

theodinproject.com

I'll add more as they come to mind. Thanks for making this sub.


r/StackoverReddit • • Jul 04 '24

Other Code Why sign up not working after form submission?

5 Upvotes

signup.ts :

 async onSubmit(): Promise<void> {
    if (this.signupForm.valid) {
      const name = this.signupForm.get('name')!.value;
      const email = this.signupForm.get('email')!.value;
      const password = this.signupForm.get('password')!.value;
      const confirmpassword = this.signupForm.get('confirmpassword')!.value;
      this.nomail=true;
      this.noname=true;
      this.nopwd=true;
      const userExists = await this.checkIfUserExists(email);
      if (userExists) {
        this.errorMessage = 'User already exists. Please use a different email.';
        this.userexist=true;
      } else {
        this.errorMessage = null;
        
        await this.addNewUser(name, email, password);
        await this.registeruser(name, email, password);
        this.router.navigate(['/dashboard']); 
      }
    } else {
      console.log('Form is invalid');
    }
  }
  

  async checkIfUserExists(email: string): Promise<boolean> {
    const db = getFirestore();
    const bundleRef = collection(db, "users");
    const q1 = query(bundleRef, where("email", "==", email));
    const nompr1 = await getDocs(q1);
    return !nompr1.empty;
  }

async addNewUser(name: string, email: string, password: string): Promise<void> {
    const db = getFirestore();
    await addDoc(collection(db, "users"), { name, email, password });
  }


  async registeruser(name: string, email: string, password: string): Promise<void> {
    try {
      await this.authservice.register(email, name, password).toPromise(); 
    } catch (error) {
      console.error('Error registering user:', error);
    }
  }

signup.html(doesn't matter the form content) :

<form [formGroup]="signupForm"  (ngsubmit)="onSubmit()" class="form-detail" action="#" method="post">
</form>

authservice.ts :

 login(email: string, password: string): Observable<any> {
    console.log('Logging in user:', email);
    const promise = signInWithEmailAndPassword(this.firebaseAuth, email, password)
      .then(response => {
        console.log('Login successful:', response);
        return response;
      })
      .catch(error => {
        console.error('Login error:', error);
        throw error; 
      });
  
    return from(promise);
  }                                       

errors in dev tools :
signup:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received