Learn Programming

1773 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
1
1
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 
 

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
 
 

I’m versed enough in SQL and RDBMS that I can put things in the third normal form with relative ease. But the meta seems to be NoSQL. Backends often don’t even provide a SQL interface.

So, as far as I know, NoSQL is essentially a collection of files, usually JSON, paired with some querying capacity.

  1. What problem is it trying to solve?
  2. What advantages over traditional RDBMS?
  3. Where are its weaknesses?
  4. Can I make queries with complex WHERE clauses?
3
 
 

Learning by doing is hard to beat when it comes to building software.

I am starting a home lab to have a safe environment to try things out. Any ideas on what I could run that is completely useless but fun to set up?

@learn_programming
@homelabs

4
9
dynamic tables? (moist.catsweat.com)
submitted 1 month ago by [email protected] to c/[email protected]
 
 

im trying to understand 'dynamic tables' [snowflake] and they kiiinda just sound like materialized views + automation on cache results?

5
 
 

How can I define lines so when I click on the screen, my program knows whether I clicked on A B or C?

6
 
 

Besides some of the very, very obvious (don't copy/paste 100 lines of code, make it a function! Write comments for your future self who has forgotten this codebase 3 years from now!), I'm not sure how to write clean, efficient code that follows good practices.

In other words, I'm always privating my repos because I'm not sure if I'm doing some horrible beginner inefficiency/bad practice where I should be embarrassed for having written it, let alone for letting other people see it. Aside from https://refactoring.guru, where should I be learning and what should I be learning?

7
 
 

The project home page.

The Github

Looks just like VS Code and I think it's still built on electron so take that as you will.

8
 
 

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.

9
 
 

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.

10
 
 

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?

11
1
submitted 10 months ago* (last edited 10 months ago) by [email protected] to c/[email protected]
 
 

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()
12
13
 
 

I have created this app for javascript beginners. Users can attempt daily quiz and see the explanation after each answer. Also providing the frequently used code snippets, you can download beautiful images of code snippets and quiz. Please provide your feedback.

14
 
 

Does anyone else find javascript/electron-based code editors confusing? I can never understand the organization/hierarchies of menus, buttons, windows, tabs. All my time is spent hunting through the interface. My kingdom for a normal dialogue box!

I've tried and failed to use VSCodium on a bunch of occasions for this reason. And a couple other ones. It's like the UI got left in the InstaPot waaaay too long and now it's just a soggy stewy mess.

Today I finally thought I'd take the first step toward android development. Completing a very simple hello world tutorial is proving to be challenging just because the window I see doesn't precisely correspond to the screenshots. Trying to find the buttons/menus/tools is very slow as I am constantly getting lost. I only ever have this in applications with javascript-based UIs

Questions:

  1. Am I the only one who faces this challenge?

  2. Do I have to use Android Studio or it there some kind of native linux alternative?

edited to reflect correction that Android Studio is not electron

15
1
Node Authentication With Passport.Js (javascript.withcodeexample.com)
submitted 11 months ago by [email protected] to c/[email protected]
16
 
 

Hi, I'm looking to open-source a small CLI application I wrote and I'm struggling with how to provide the built app since just providing the binary will not work. I had a friend test it and he had to compile from source due to glibc version differences.

My first thought was providing it as a flatpak but that isn't really suitable for CLI software.

I've googled around a bit and most guides I find just mention packaging separately for multiple package managers/formats (rpm, apt etc.). This seems really inefficient/hard to maintain. What is the industry standard for packaging a Linux software for multi-distro use?

17
1
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

Hi everyone,

TL;DR Completely new to coding and programming, but I want to learn enough to be able to run a home server, my own website and tinker a bit with Arduino. Is there any programming language or path that you could recommend?

I don't know if those things are related or not. I've been looking at books a bout Arduino, but it's just following instructions to do xyz, but not explanation of the basics.

About the server and website, I've wanted to try it out since I stumbled upon the Low tech magazine. Many of the projects there and the philosophy behind it speak to me, so I would like to be more knowledgeable about it and be able to do some stuff myself.

EDIT. You guys are awesome! Thank you so much for the replies. It’s so cool to see Lemmy populated with cool people willing to chat and put knowledge in common :) I might be updating this post when I get to do something about… well all the resources you gave me!

18
 
 

cross-posted from: https://lemmy.ml/post/13353225

Quick little confusion or even foot-gun I ran into (while working on the challenge I posed earlier).

TLDR

My understanding of what I ran into here:

  • Matching on multiple variables simultaneously requires assigning them to a tuple (?),
  • which happens more or less implicitly (?),
  • and which takes ownership of said variables.
  • This ownership doesn't occur when matching against a single variable (?)
  • Depending on the variables and what's happening in the match arms this difference can be the difference between compiling and not.

Anyone got insights they're willing to share??

Intro

I had some logic that entailed matching on two variables. Instead of having two match statements, one nested in the other, I figured it'd be more elegant to match on both simultaneously.

An inline tuple seemed the obvious way to do so and it works, but it seems that the tuple creates some ownership problems I didn't anticipate, mostly because I was thinking of it as essentially syntax and not an actual tuple variable.

As you'll see below, the same logic with nested match statements each on a single variable doesn't suffer from the same issues.

Demo Code

fn main() {

    // # Data structures
    enum Kind {
        A,
        B
    }
    struct Data {
        kind: Kind
    }

    // # Implementation
    let data = vec![Data{kind: Kind::A}];

    // ## Basic idea: process two adjacent data points
    let prev_data = data.last().unwrap();
    let new_data = Data{kind: Kind::B};

    //

MATCH STATEMENTS


// ## This works: match on one then the other
let next_data = match prev_data.kind {
    Kind::A => match new_data.kind {
        Kind::A => 1,
        Kind::B => 2,
    },
    Kind::B => match new_data.kind {
        Kind::A => 3,
        Kind::B => 4,
    },
};

// ## This does NOT work: match on both
let next_data2 = match (prev_data.kind, new_data.kind) {
    (Kind::A, Kind::A) => 1,
    (Kind::A, Kind::B) => 2,
    (Kind::B, Kind::A) => 3,
    (Kind::B, Kind::B) => 4,
};

}


### The Error

The error is on the line `let next_data = match (prev_data.kind, new_data.kind)`, specifically the tuple and its first element `prev_data.kind`, with the error:

error[E0507]: cannot move out of prev_data.kind which is behind a shared reference

move occurs because prev_data.kind has type Kind, which does not implement the Copy trait


### The Confusion

So `prev_data.kind` needs to be moved.  That's ok.  Borrowing it with `(&prev_data.kind, ...)` fixes the problem just fine, though that can cause issues if I then want to move the variable within the match statement, which was generally the idea of the logic I was trying to write.

What got me was that the same logic but with nested match statements works just fine.

I'm still not clear on this, but it seems that the inline tuple in the second tuple-based approach is a variable that takes ownership of the variables assigned to it.  Which makes perfect sense ... my simple mind just thought of it as syntax for interleaving multiple match statements I suppose. In the case of nested match statements however, I'm guessing that each match statement is its own scope.

**The main thing I haven't been able to clarify is what are the ownership dynamics/behaviours of match statements??**  It seems that there's maybe a bit happening implicitly here??  I haven't looked super hard but it does seem like something that's readily glossed over in the materials I've seen thus far??

### General Implications

AFAICT:
* if you want to match on two or more variables simultaneously, you'll probably need borrow them in the match statement if they're anything but directly owned variables.
* If you want to then use or move them in the match arms you may have to wrangle with ownership or just use nested match statements instead (or refactor your logic/implementation).
* **So probably don't do multi-variable matching unless the tuple of variables is a variable native to the logic**?
19
20
 
 

hello guys. i am trying to match one or more digit from end of string

import re

print(re.match(r'\d+$', "hello001"))
print(re.match(r'[0-9]+$', "hello001"))

output None from both print statement. I've tried my regex on regex101.com and it seems working probably.

21
 
 

cross-posted from: https://discuss.online/post/5803977

About this Book

The Rust programming language is extremely well suited for concurrency, and its ecosystem has many libraries that include lots of concurrent data structures, locks, and more. But implementing those structures correctly can be difficult. Even in the most well-used libraries, memory ordering bugs are not uncommon.

In this practical book, Mara Bos, team lead of the Rust library team, helps Rust programmers of all levels gain a clear understanding of low-level concurrency. You’ll learn everything about atomics and memory ordering and how they're combined with basic operating system APIs to build common primitives like mutexes and condition variables. Once you’re done, you’ll have a firm grasp of how Rust’s memory model, the processor, and the role of the operating system all fit together.

With this guide, you’ll learn:

  • How Rust's type system works exceptionally well for programming concurrency correctly
  • All about mutexes, condition variables, atomics, and memory ordering
  • What happens in practice with atomic operations on Intel and ARM processors
  • How locks are implemented with support from the operating system
  • How to write correct code that includes concurrency, atomics, and locks
  • How to build your own locking and synchronization primitives correctly

Available free of charge. But I doubt I'll ever read it. Never enough time and energy for everything.

22
 
 

What are some tips and tricks and best practices with rust?

Also, I'm used to clearly defined classes and implementation files with C++. Are there any tips and tricks on that with Rust? I haven't found any decent commentary/ documentation on figuring this out correctly with Rust. Yes, I know Rust is not an oop language, but I'm having issues creating clear separation of files so they don't become a scrolling dungeon.

23
 
 

See [email protected] for future updates.

cross-posted from: https://jlai.lu/post/4802347

Hi all!

What?

I will be starting a secondary slot/sessions for the Reading Club, also on "The Book" ("The Rust Programming Language"). We will, also, very likely use the Brown University online edition (that has some added quizzes & interactive elements).

Why?

This slot is primarily to offer an alternative to the main reading club's streams that caters to a different set of time zone preferences and/or availability.

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time). Effectively, this is 6 hours "earlier in the day" than when the main sessions start, as of writing this post.

The first stream will happen on the coming Monday (2023-03-04).

Please comment if you are interested in joining because you can't make the main sessions but would prefer a different start time (and include a time that works best for you in your comment!). Caveat: I live in central/western Europe; I can't myself cater to absolutely any preference.

How ?

We will start from the beginning of "The Book".

There are 2 options:

  1. mirror the main sessions' pace (once every week), remaining ~4 sessions "behind" them in terms of progression through "The Book"
  2. attempt to catch up to the main sessions' progression

I am personally interested in trying out 2 sessions each week, until we are caught up. This should effectively result in 2-3 weeks of biweekly sessions before we slow back down. I'm not doing this just for me, however, so if most people joining these sessions prefer the first option I'm happy to oblige.

I will be hosting the session from my own twitch channel, https://www.twitch.tv/jayjader . I'll be recording the session as well; this post should be edited to contain the url for the recording, once I have uploaded it.

Who ?

You! (if you're interested). And, of course, me.

24
1
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

I want to learn how to build integrations, such as how to connect two systems made by different companies that have different structures.

For example: To cut down on redundant data entry, I want to build an integration where the data is pushed from one software to another software. The integration would put the data from the source software into the correct fields in the destination software.

How do I go about learning how to build integrations? What classes to even start with?

I appreciate any guidance you can provide.

Edit: Thanks a bunch for the suggestions. I'm checking out those tools suggested in the comments and looking up classes to learn the skills needed.

25
 
 

I get postman exports from students which I use to check their work. The authorisation of those requests now often contain hardcoded jwt tokens that are invalid by the time I get to checking them and I have to change every individual request with a global variable.

I do instruct my students to use variables, but there's always a couple who just don't, but that's a whole different issue.

Right now I'm using a regex find and replace to remove the Request authorization header in the json export file (which than defaults to 'inherit from parent'). This sort of works, but isn't ideal.

Do any of you know if postman offers an easier solution for this?

view more: next ›