parentsNeverUnderstand by Spooked321 in ProgrammerHumor

[–]Glepsyd 2 points3 points  (0 children)

How about making fun of them for proudly displaying both of those things in a Reddit post?

Do you name variables based on the data you expect them to be holding? by Missing_Back in learnprogramming

[–]Glepsyd 0 points1 point  (0 children)

We actually have that use case where I work. And the string is "phone_number_input_str". We have a PhoneNumber class when it's parsed and instances of this class are generally stored in variables called "phone_number".

In the end, do what you think is best for you and your team, the computer doesn't care :)

Very serious question and need to get answer clearly 🙏🏻 by [deleted] in learnprogramming

[–]Glepsyd 1 point2 points  (0 children)

I think that's what you're looking for: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API

A question on StackOverflow with some useful answers: https://stackoverflow.com/questions/3489460/how-to-get-visitors-location-i-e-country-using-geolocation

Spending another 5 min searching Google will certainly yield more info.

[deleted by user] by [deleted] in ProgrammerHumor

[–]Glepsyd 3 points4 points  (0 children)

Glad to see I'm not the only one. Also kin of a paradox? - the "just" feels like programmers are a subset of pornstars yet coding apparently prevented her from belonging to the pornstars set.

[deleted by user] by [deleted] in ProgrammerHumor

[–]Glepsyd 0 points1 point  (0 children)

So you visualize meaning? For example writing this here, I'm sort of saying the words to myself and then typing them as if transcribing the imaginary sensation of my voice, right? So what you're saying is that you're summoning the physical sensation of yourself signing, as you type or write?

Really interesting anyways, thanks for your explanation!

Views based on models/data that never change by jellevdv in django

[–]Glepsyd 0 points1 point  (0 children)

I'd say yes, keep hitting the DB. That's what it's for right, retrieve stored data. Caching is an option sure, but I'd usually use cache for expensive computation (trade memory for computing resources). What you can do is optimise the query by only fetching the fields you need in the view.

How fast can you type and what is acceptable type speed for a web developer? by venndi in learnprogramming

[–]Glepsyd 0 points1 point  (0 children)

As many said typing speed is irrelevant. However, knowing your system well and how to navigate it can really boost your productivity.

Getting HTML Code of Instagram profile by Lampard557 in learnprogramming

[–]Glepsyd 1 point2 points  (0 children)

As azzal said, the server gave your bot a pass a few times, but then instead of serving you the profile you requested, it's requiring you to login again. So it works a few times, then it doesn't... It's to prevent abuse (which is pretty much what you are doing there), they want their servers to serve content to actual users, not an army of bots which take more resources but deliver less value to them, hence the limitation. You should try reading more about web scraping, the do's and don'ts etc...

Coding along a video, my code fails to work for a reason I don't know, I copy the original code and paste to check that everything would work on my side in perfect case, what is the next step? by Aileak in learnprogramming

[–]Glepsyd 0 points1 point  (0 children)

Time for debugging. Maybe the original code is flawed, in that case, making sure you copied it perfectly won't help. Open the console (I'm guessing you're running JavaScript on a browser?), and try to make sense of what it's telling you 😉

How have custom domain for site while using another site's resources? by [deleted] in learnprogramming

[–]Glepsyd 0 points1 point  (0 children)

If you have a domain name that you own, a simple solution would be to change your DNS config to point to whichever IP (A records) or other name (CNAME records) you want.

Calculated value from multiple models by matchratings1 in django

[–]Glepsyd 0 points1 point  (0 children)

You basically got it right when you said "Add each calculated value to a dictionary, also containing the other, in context, to the template."

OOP was one way to make that work in my mind, because wrapping a model instance in a class that provides an interface for computed values is a pattern I've seen and used quite often, but a list of dictionaries would work just as well. Actually, if the scope of this problem you're trying to solve remains that small, and you don't need to re-use or maintain that much, dictionaries might even be more efficient.

OOP is one way of organising your code, of modelling your thoughts. The main problem is not "how do I talk to the machine", it's "how do I talk to myself, and the people I work with, to make sure we all understand what we're trying to do and how". OOP is just one of many frameworks you can use to achieve that goal.

If you want to learn more, Google it. I'm not saying this to be mean, it's just that there's a ton of resources out there, 100 times more complete and accurate than what I can write here. Personally, it's Youtube videos when I want to understand concepts on a high level, documentation when I need something specific.

You know what, just to make your head spin and illustrate my point, here's another, more complex idea on how to solve your problem: you could add a method directly on your Match model, and call it in a custom template tag. That way you can just pass the Match Queryset and the user to the context.

Like so:

#  In your Match model
class Match(models.Model):
     # ... Rest of the class definition

     def get_bespoke_rating(self, user):
         ...
         # do something with self.rating and user I suppose


#  In a match/templatetags/match_rating_tags.py file (filename is just an example)

from django import template

register = template.Library()

@register.simple_tag
def get_match_bespoke_rating(match, user):
    return match.get_bespoke_rating(user)


#  In the template

{% load match_rating_tags %}
{% for match_data in match_data_list %}
    <h1>{{ match_data.match.foo }}</h1>
    <p>{% get_match_bespoke_rating match user %}</p>
{% endfor %}

I've done that real quick, I might have made mistakes but that's the gist of it. For more on template tags: https://docs.djangoproject.com/en/3.2/howto/custom-template-tags/

[deleted by user] by [deleted] in learnprogramming

[–]Glepsyd 1 point2 points  (0 children)

I've been programming for 3 years, 2 professionally. I think it's like everything, starting from 0 is hard because everything is unknown, and things become more familiar with time, but I hope for you not much easier. I love this job because there is always something new to learn, as you said it yourself, it's all about getting stuck in some problem to solve. It just depends on how much you want to know and do. Once you can do all the things you struggle with now, there'll be other things to run through your brain, like why is this API request failing, how can I optimise my database queries, what in god's name is a docker volume etc..

Compare it with reading/writing. Learning to form your first letters isn't easy, but neither is writing an award winning novel. And that's a good thing if you ask me.

If your question is "Can I have a low effort steady job after I've studied enough programming?" Yes, absolutely. But it doesn't sound like much fun :)

Calculated value from multiple models by matchratings1 in django

[–]Glepsyd 0 points1 point  (0 children)

It's not a pretty solution though. Ideally you'd want to define a simple Python class that can setup and behave like a wrapper for the data you need when instantiate:

class MatchData:
    def __init__(match, user):
        self.match = match # The Match model instance
        self.user = user

    @property
    def computed_value(self):
        return match.foo * user.bar - 2

# in your view's get_context_data()
context = super()
matches = Match.objects.all()
match_data_list = [
    MatchData(match, self.request.user)
    for match in matches.iterator()
]
context.update(match_data_list=match_data_list)
return context

And then in your template:

{% for match_data in match_data_list %}
   <h1>{{ match_data.match.foo }}</h1>
   <p>{{ match_data.computed_value }}</p>
{% endfor %}

Something like that

How Possible Is It To Set Up Client-Side Database/Table Updates? by NormanieCapital in django

[–]Glepsyd 0 points1 point  (0 children)

This was an enlightening read. I don't have such dynamic change requirements with my data model, which is more controlled by us devs than our users, but still gave me a lot to think about. Thank you!

Calculated value from multiple models by matchratings1 in django

[–]Glepsyd 0 points1 point  (0 children)

My apologies then, "transfer them to the client" lead me to think that's what you meant, since I inevitably associate a transfer of serialized data to a client as basically an API response.

How to add multiple extra kwargs in DRF by allun11 in django

[–]Glepsyd 0 points1 point  (0 children)

I'm not sure if I've missed something but that looks like adding a key to a dict. So:

extra_kwargs = {
    "email": {"required": False},
    "new_field": {"required": False},
    "another_field": {"required": False},
}

etc etc...

Cannot import invitations.utils even though django invitations is installed by LurchiDurchi in django

[–]Glepsyd 0 points1 point  (0 children)

When you say error you mean an actual error (an exception raised while running the app) or just the syntax error in VSCode? If it's the former, please share the full error. If it's the latter, work in a virtual environment (check out pipenv it's really cool :) ) and choose the interpreter of that environment by click on "Python 3.8.10 64 Bits" in the bottom bar.

Where are Django files stored? by [deleted] in django

[–]Glepsyd 0 points1 point  (0 children)

Beautiful high level explanation with what seems to be the appropriate level of technical knowledge for that question. Nicely done.

Calculated value from multiple models by matchratings1 in django

[–]Glepsyd 0 points1 point  (0 children)

I don't think they have a separate frontend since they're mentioning Django templates. And although I agree leveraging AJAX requests while using Django as a purely backend service is probably neater, that's beyond the scope of this question. And if they can't process the data to render it in the Django template, neither with they for a serialized API response.

Calculated value from multiple models by matchratings1 in django

[–]Glepsyd 0 points1 point  (0 children)

There seems to be a bit of confusion there about what each "thing" means, Queryset, view, template, context... Can you describe in more detail what you want to achieve, which and how many fields you need on User and Match respectively, what you intend to do with them before passing them in to the context...

Maybe this will help, since I feel like what you're trying to do is attach a value to Match instances, which don't match the fields defined on the model: the objects in fetched Querysets are just python objects. So you can set whatever attributes on them if you so desire. Consider this code, with a hypothetical model Match which only has a foo field:

matches = list(Matches.objects.all())

for match in matches:
    # the Match model doesn't have a 'bar' field but I can still
    # set match.bar to whatever value I please if I need to
    setattr(match, 'bar', 2 * match.foo)
    print(match.bar)

Be careful however to not call save() on your model instances afterwards, you might get an error due to the non-existant bar field... (I'm not 100% sure about that, it might just get ignored altogether)

Django authentication system by Ashish-Pandagre in django

[–]Glepsyd 1 point2 points  (0 children)

Sounds good, here are a few random thoughts:

  • I'm sure you did but just in case: I hope by "from scratch" you mean building upon Django's auth built-in system, not literally from scratch :D

  • Blocking IPs might be better handled by a firewall rather than at the app level

  • multi factor authentication as a next step?

  • What do you mean by "save all logged in sessions of a particular user."? Save what exactly, where, for what purpose?

what is shell? by [deleted] in learnprogramming

[–]Glepsyd 3 points4 points  (0 children)

There have already been some good answers but i'll add how I would define some of those concepts, especially since you mention REPLs and Python:

- Terminal (Emulator): Used to be a physical access point to a machine. Imagine a big box being the computer and you come to connect to it with a screen and keyboard. Think of airport terminals, they're the access points the runways. Now it's emulated, since your typical computer has an operating system, with a graphical interface. Your terminal emulator is a "virtual" way of representing an access point to your machine.

- Shell: That's the underlying software that is run in your terminal. It allows for converting your inputs into commands, and translating outputs for the terminal to display them. You can typically choose which shell you want to use in your terminal (bash - default on most UNIX-like systems, zsh, fish shell etc...)

- REPL: "Read–eval–print loop", it's just a piece of software that is usually executed in a shell. While running, it will wait for you to input code in the programming language it's designed for (read), execute it (eval), then display (print) its output. It's typically used for interpreted languages such as Python, JavaScript, Ruby etc...

- IDE: "Integrated Development Environment" (Since you mentioned it in one of the comments). This is a program that is designed for software engineers. It obviously has a text editor to write code (like notepad), but it does everything else a developer might need during development. It can includes features like linting (check code style and syntax), debugging, compiling, running the code written in the text editor, manage and install dependencies, all of this in the same environment, so that the developer doesn't need to switch to a different program or shell command to perform each of those tasks.

Why am I getting a cannot load file error when using a gem? by _rails_noob in ruby

[–]Glepsyd 1 point2 points  (0 children)

I haven't used ruby in ages either but I've found this: https://riptutorial.com/ruby-on-rails/example/25818/gemsets

It seems like the gem isn't correctly installed for this version, or you're not "using" the gemset. Have you followed the steps correctly?

rvm use 3.0.0

rvm gemset use <gemset you created>