My Python-based Code Smells Catalog Paper was finally published in Springer! 🎉
Hey! Some time ago, I posted here my Code Smells Catalog website, which has a big pile of aggregated general Code Smells with examples & solutions written in Python.
Since then, the website is still reporting a daily activity of at least \~50 users and has an all-time peak of 8500, which is incredible! People seem to be using it both as a knowledge source and as a pointer for Code Reviews (referring to a particular Code Smell page).
Last month, my paper finally got published in Springer, which means a lot to me, and because of the occasion, I wanted to re-share the website catalog and paper (*pre-print* is free!) for those who missed it around a year ago.
Thank you all for your appreciation! It is so lovely that it brings at least a tiny bit of value to some of you! ❤️
/r/Python
https://redd.it/138u9yf
Hey! Some time ago, I posted here my Code Smells Catalog website, which has a big pile of aggregated general Code Smells with examples & solutions written in Python.
Since then, the website is still reporting a daily activity of at least \~50 users and has an all-time peak of 8500, which is incredible! People seem to be using it both as a knowledge source and as a pointer for Code Reviews (referring to a particular Code Smell page).
Last month, my paper finally got published in Springer, which means a lot to me, and because of the occasion, I wanted to re-share the website catalog and paper (*pre-print* is free!) for those who missed it around a year ago.
Thank you all for your appreciation! It is so lovely that it brings at least a tiny bit of value to some of you! ❤️
/r/Python
https://redd.it/138u9yf
luzkan.github.io
Code Smells Catalog
A collection of Bad Code Smells in a Catalog form for Developers & Researchers. Code Smell is a typical bad code implementation, and learning these concepts immiedietly makes you a better developer!
[P] The first RedPajama models are here! The 3B and 7B models are now available under Apache 2.0, including instruction-tuned and chat versions. These models aim replicate LLaMA as closely as possible.
https://www.together.xyz/blog/redpajama-models-v1
/r/MachineLearning
https://redd.it/13965sq
https://www.together.xyz/blog/redpajama-models-v1
/r/MachineLearning
https://redd.it/13965sq
www.together.ai
Releasing 3B and 7B RedPajama-INCITE family of models including base, instruction-tuned & chat models
Checkout the tool I coded to generate a multiple choice quizz from the content of any uploaded PDF.
It’s a Streamlit Python App.The langchain GPT template is in French so make sure you translate it in your language for better result!
https://github.com/fbellame/pdf-to-quizz
/r/Python
https://redd.it/139l9da
It’s a Streamlit Python App.The langchain GPT template is in French so make sure you translate it in your language for better result!
https://github.com/fbellame/pdf-to-quizz
/r/Python
https://redd.it/139l9da
GitHub
GitHub - fbellame/pdf-to-quizz: Upload a PDF and generate a quizz
Upload a PDF and generate a quizz. Contribute to fbellame/pdf-to-quizz development by creating an account on GitHub.
Context Managers And The 'with' Statement In Python: A Comprehensive Guide With Examples
​
https://preview.redd.it/u6xczndjw7ya1.png?width=1600&format=png&auto=webp&v=enabled&s=373ea2365d45780156dd6d63bc86b70864513bce
Resource management is critical in any programming language, and the use of system resources in programs is common.
Assume we are working on a project where we need to establish a database connection or perform file operations; these operations consume resources that are limited in supply, so they must be released after use; otherwise, issues such as running out of memory or file descriptors, or exceeding the maximum number of connections or network bandwidth can arise.
**Context managers** come to the rescue in these situations; they are used to prepare resources for use by the program and then free resources when the resources are no longer required, even if exceptions have occurred.
Context managers provide a mechanism for the setup and teardown of the resources associated with the program. It improves the readability, conciseness, and maintainability of the code.
The context managers can be used with Python's `with` statement to handle the **setup** and **teardown** of resources in the program. However, we can create our own custom context manager by implementing the **enter(setup)** logic and **exit(teardown)** logic within a Python class.
In this article, we'll learn:
* **What is context manager and why they are used**
* **Using context manager with the** `with` **statement**
* **Implementing context management
/r/Python
https://redd.it/139prq4
​
https://preview.redd.it/u6xczndjw7ya1.png?width=1600&format=png&auto=webp&v=enabled&s=373ea2365d45780156dd6d63bc86b70864513bce
Resource management is critical in any programming language, and the use of system resources in programs is common.
Assume we are working on a project where we need to establish a database connection or perform file operations; these operations consume resources that are limited in supply, so they must be released after use; otherwise, issues such as running out of memory or file descriptors, or exceeding the maximum number of connections or network bandwidth can arise.
**Context managers** come to the rescue in these situations; they are used to prepare resources for use by the program and then free resources when the resources are no longer required, even if exceptions have occurred.
Context managers provide a mechanism for the setup and teardown of the resources associated with the program. It improves the readability, conciseness, and maintainability of the code.
The context managers can be used with Python's `with` statement to handle the **setup** and **teardown** of resources in the program. However, we can create our own custom context manager by implementing the **enter(setup)** logic and **exit(teardown)** logic within a Python class.
In this article, we'll learn:
* **What is context manager and why they are used**
* **Using context manager with the** `with` **statement**
* **Implementing context management
/r/Python
https://redd.it/139prq4
I recorded a crash course on Polars library of Python (Great library for working with big data) and uploaded it on Youtube
Hello everyone, I created a crash course of Polars library of Python and talked about data types in Polars, reading and writing operations, file handling, and powerful data manipulation techniques. I am leaving the link, have a great day!
https://www.youtube.com/watch?v=aiHSMYvoqYE
/r/Python
https://redd.it/139wsvp
Hello everyone, I created a crash course of Polars library of Python and talked about data types in Polars, reading and writing operations, file handling, and powerful data manipulation techniques. I am leaving the link, have a great day!
https://www.youtube.com/watch?v=aiHSMYvoqYE
/r/Python
https://redd.it/139wsvp
YouTube
Master Python Polars for Efficient Big Data Handling: 22-Minute Crash Course!
Unlock the power of Python Polars for efficient big data handling in this 22-minute crash course. Dive into practical techniques and real-world examples to streamline your data processing workflows and maximize performance. Perfect for data enthusiasts and…
How to handle the return code of the confirm() javascript result?
Hi, so this is probably a very simple question but I don't know where to start looking (well, google obviously but I need the right terms to look for).
I want to show a little javascript popup where the user needs to press OK or cancel and confirm() seems like the easiest way to do that but I don't understand how to handle the return code in Flask/Python. The w3schools site gives a nice example of how to handle it in plain HTML but I need to execute 'actual' code instead of just show some text and I have no idea how start as it seems there's no real communication back to the server and it's only client-side..
/r/flask
https://redd.it/139hov9
Hi, so this is probably a very simple question but I don't know where to start looking (well, google obviously but I need the right terms to look for).
I want to show a little javascript popup where the user needs to press OK or cancel and confirm() seems like the easiest way to do that but I don't understand how to handle the return code in Flask/Python. The w3schools site gives a nice example of how to handle it in plain HTML but I need to execute 'actual' code instead of just show some text and I have no idea how start as it seems there's no real communication back to the server and it's only client-side..
/r/flask
https://redd.it/139hov9
W3Schools
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
FrontEngine can play videos, GIFs, webpages, and more on your screen foreground.
I create this side project that can play videos, GIFs, webpages, and more on your screen foreground.
FrontEngine can draw below type on front of your screen.
You can use your computer as usual without being disturbed.
Video.
Website.
GIF & WEBP.
Image.
Play sound.
Text
GitHub repo: Intergration-Automation-Testing/FrontEngine (github.com)
Youtube showcase: https://youtu.be/fewogcb3b8Y
/r/Python
https://redd.it/139vgm7
I create this side project that can play videos, GIFs, webpages, and more on your screen foreground.
FrontEngine can draw below type on front of your screen.
You can use your computer as usual without being disturbed.
Video.
Website.
GIF & WEBP.
Image.
Play sound.
Text
GitHub repo: Intergration-Automation-Testing/FrontEngine (github.com)
Youtube showcase: https://youtu.be/fewogcb3b8Y
/r/Python
https://redd.it/139vgm7
GitHub
GitHub - Intergration-Automation-Testing/FrontEngine
Contribute to Intergration-Automation-Testing/FrontEngine development by creating an account on GitHub.
Is it possible pickle a function with its dependencies?
I am trying to pickle Python functions with their dependencies (e.g. numpy, etc) and execute the pickled function on worker nodes without installing dependencies on the worker node. Is this possible?
If not, what are some other approaches to accomplish this task?
/r/Python
https://redd.it/139vz41
I am trying to pickle Python functions with their dependencies (e.g. numpy, etc) and execute the pickled function on worker nodes without installing dependencies on the worker node. Is this possible?
If not, what are some other approaches to accomplish this task?
/r/Python
https://redd.it/139vz41
Reddit
r/Python on Reddit: Is it possible pickle a function with its dependencies?
Posted by u/FourSigma - 7 votes and 17 comments
Redirect with token in header using href
I'm trying to include an auth header that includes a token using a href in a link like below:
<a href="/some/route/{{ data }}"></a>
Because I want this route to only be available to users with a valid auth token, but I can't figure out how to include the token in the header from here. I've tried using a GET request with AJAX like below:
$.ajax(
{
type: "GET",
url: "/some/route/" + data,
headers: {
Authorization: get_token()
},
async: true,
success: function()
{
console.log("worked");
},
error: function(xhr, status, error)
{
/r/flask
https://redd.it/13a2f7f
I'm trying to include an auth header that includes a token using a href in a link like below:
<a href="/some/route/{{ data }}"></a>
Because I want this route to only be available to users with a valid auth token, but I can't figure out how to include the token in the header from here. I've tried using a GET request with AJAX like below:
$.ajax(
{
type: "GET",
url: "/some/route/" + data,
headers: {
Authorization: get_token()
},
async: true,
success: function()
{
console.log("worked");
},
error: function(xhr, status, error)
{
/r/flask
https://redd.it/13a2f7f
Reddit
r/flask on Reddit: Redirect with token in header using href
Posted by u/Zalosath - 1 vote and 7 comments
What do you think about this solution? (signal field change detection)
Hello guys,
I have been working on a feature that requires detecting changes in a specific field of a model. I saw multiple ways to do that but never this. This implementation is using the
​
signals.py
oldvalue = None
@receiver(presave, sender=Model)
def storeoldvalue(sender, instance, **kwargs):
global oldvalue
if instance.pk:
oldvalue = Model.objects.get(pk=instance.pk).myfield
@receiver(postsave, sender=Model)
def checkfieldchange(sender, instance, created, kwargs):
global oldvalue
if oldvalue is not None and instance.myfield != oldvalue:
# Perform additional operations here
pass
What do you think about this approach, is there anything that you would do differently or are there any risks?
There are at least two alternative approaches:
1. detect change in
/r/djangolearning
https://redd.it/139m1hf
Hello guys,
I have been working on a feature that requires detecting changes in a specific field of a model. I saw multiple ways to do that but never this. This implementation is using the
pre_save and post_save signals in Django. What do you think about it?​
signals.py
oldvalue = None
@receiver(presave, sender=Model)
def storeoldvalue(sender, instance, **kwargs):
global oldvalue
if instance.pk:
oldvalue = Model.objects.get(pk=instance.pk).myfield
@receiver(postsave, sender=Model)
def checkfieldchange(sender, instance, created, kwargs):
global oldvalue
if oldvalue is not None and instance.myfield != oldvalue:
# Perform additional operations here
pass
What do you think about this approach, is there anything that you would do differently or are there any risks?
There are at least two alternative approaches:
1. detect change in
/r/djangolearning
https://redd.it/139m1hf
Reddit
r/djangolearning on Reddit: What do you think about this solution? (signal field change detection)
Posted by u/milwoukee - 2 votes and 9 comments
Sunday Daily Thread: What's everyone working on this week?
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/13a6lif
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/13a6lif
Reddit
r/Python on Reddit: Sunday Daily Thread: What's everyone working on this week?
Posted by u/Im__Joseph - 1 vote and 2 comments
Companies using DRF
Are any companies choosing Django Rest Framework over other Node.js and Java Spring frameworks in recent times? And why should they?
/r/django
https://redd.it/13aeky6
Are any companies choosing Django Rest Framework over other Node.js and Java Spring frameworks in recent times? And why should they?
/r/django
https://redd.it/13aeky6
Reddit
r/django on Reddit: Companies using DRF
Posted by u/tushar8sk - 16 votes and 25 comments
Password protect any URL using Flask
I wrote this front end authentication application using Flask, Python3, JavaScript, Bootstrap, HTML, CSS and Replit DB.
User's email and password combined then hashed in SHA256 format. The users password is never transmitted over the internet, ever. The hash is saved and then compared to the hash on file with each login and they must match to achieve successful login.
You can password protect ANY url (for the demo) but it has numerous applications. I would love to read your comments, constructive criticisms and trash talk.
Python 3 Source
Thanks for checking it out.
/r/flask
https://redd.it/138rpjx
I wrote this front end authentication application using Flask, Python3, JavaScript, Bootstrap, HTML, CSS and Replit DB.
User's email and password combined then hashed in SHA256 format. The users password is never transmitted over the internet, ever. The hash is saved and then compared to the hash on file with each login and they must match to achieve successful login.
You can password protect ANY url (for the demo) but it has numerous applications. I would love to read your comments, constructive criticisms and trash talk.
Python 3 Source
Thanks for checking it out.
/r/flask
https://redd.it/138rpjx
Django bootstrap5 htmx leafletjs marker to popup form click event issue
Sorry it's a wordy topic :) But it summarizes what I'm using in our project. My buddy setup our Django project with leaflet and it displays with various pin markers on the map. When the user clicks on a pin, we have a popup #dialog appear (using htmx). I've been tasked with adding a button to this popup so that the user can click it and go to a /url. The issue I'm having is that once the popup appears, it ignores any click events specific to the form. I can click ANYWHERE on the browser tab, on the popup, on the map and the popup closes. There is no button click occurring. I'm pretty new to leaflet and still learning my Django ropes. So I've been trying to figure this out for a few days now. It's like there is a blanket click event overlaying the entire window and the popup is under it. I'll post some code here and perhaps someone has an idea or research I can look into..
This is the template code for the main window which shows the map. You can see the htmx placeholder for the popup. You can also see the
/r/django
https://redd.it/13avwnv
Sorry it's a wordy topic :) But it summarizes what I'm using in our project. My buddy setup our Django project with leaflet and it displays with various pin markers on the map. When the user clicks on a pin, we have a popup #dialog appear (using htmx). I've been tasked with adding a button to this popup so that the user can click it and go to a /url. The issue I'm having is that once the popup appears, it ignores any click events specific to the form. I can click ANYWHERE on the browser tab, on the popup, on the map and the popup closes. There is no button click occurring. I'm pretty new to leaflet and still learning my Django ropes. So I've been trying to figure this out for a few days now. It's like there is a blanket click event overlaying the entire window and the popup is under it. I'll post some code here and perhaps someone has an idea or research I can look into..
This is the template code for the main window which shows the map. You can see the htmx placeholder for the popup. You can also see the
/r/django
https://redd.it/13avwnv
Reddit
r/django on Reddit: Django bootstrap5 htmx leafletjs marker to popup form click event issue
Posted by u/TerminatedProccess - No votes and no comments
I can't deploy celery-beat
In my application users are scheduling events, and I have to send emails an hour before. here's what the model looks like:
class Mail(models.Model):
eventId = models.ForeignKey(Event, on_delete=models.CASCADE)
sentMail = models.BooleanField(default=False)
Every 15 minutes I have to check if an email is sent and if it's not, I have to send it. The main problem that I can't solve is deploying celery-beat. I tried deploying it on a railway server with Redis, but I could only interact with it locally. Plus, I'm on Windows, so I can't use systemd, and celery & celery-beat are also not friendly with Windows. Haven't used Docker ever. Can someone give me advice that's actually good and had worked?
/r/django
https://redd.it/13b062g
In my application users are scheduling events, and I have to send emails an hour before. here's what the model looks like:
class Mail(models.Model):
eventId = models.ForeignKey(Event, on_delete=models.CASCADE)
sentMail = models.BooleanField(default=False)
Every 15 minutes I have to check if an email is sent and if it's not, I have to send it. The main problem that I can't solve is deploying celery-beat. I tried deploying it on a railway server with Redis, but I could only interact with it locally. Plus, I'm on Windows, so I can't use systemd, and celery & celery-beat are also not friendly with Windows. Haven't used Docker ever. Can someone give me advice that's actually good and had worked?
/r/django
https://redd.it/13b062g
Reddit
r/django on Reddit: I can't deploy celery-beat
Posted by u/Mishka1234567 - No votes and 2 comments
Optimizing a query for an analytics page
Hello. I've got a query that's running too slow and would like any input on how to speed it up. It is a utility function that aggregates a bunch of data for an analytics view. Each of the tables has on the order of a million rows, but I would only run it on a small subset of the User objects. Right now, it's pretty slow but tolerable (several seconds) when I pass in a queryset of about 5 users. I need it to be able to process 50 or 100 users.
Here is what I tried first, along with the relevant models.
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import OuterRef, Subquery, Count, Value, Q
from django.db.models.fields import IntegerField
from django.db.models.functions import Coalesce
from datetime import datetime, timedelta
class UserProfile(models.Model):
user = models.OneToOneField('auth.User', related_name='profile', on_delete=models.PROTECT)
country = models.CharField(max_length=100, blank=True, null=True)
/r/django
https://redd.it/13az64v
Hello. I've got a query that's running too slow and would like any input on how to speed it up. It is a utility function that aggregates a bunch of data for an analytics view. Each of the tables has on the order of a million rows, but I would only run it on a small subset of the User objects. Right now, it's pretty slow but tolerable (several seconds) when I pass in a queryset of about 5 users. I need it to be able to process 50 or 100 users.
Here is what I tried first, along with the relevant models.
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import OuterRef, Subquery, Count, Value, Q
from django.db.models.fields import IntegerField
from django.db.models.functions import Coalesce
from datetime import datetime, timedelta
class UserProfile(models.Model):
user = models.OneToOneField('auth.User', related_name='profile', on_delete=models.PROTECT)
country = models.CharField(max_length=100, blank=True, null=True)
/r/django
https://redd.it/13az64v
Reddit
r/django on Reddit: Optimizing a query for an analytics page
Posted by u/BumbleSpork - 2 votes and 1 comment
Made a program for year 12 to detect sign language via the webcam and translate it to text and audio
Github: https://github.com/4Tsuki4/Handy-Sign-Language-Detection
gif of the program in use
/r/Python
https://redd.it/13alyc2
Github: https://github.com/4Tsuki4/Handy-Sign-Language-Detection
gif of the program in use
/r/Python
https://redd.it/13alyc2
GitHub
GitHub - 4Tsuki4/Handy-Sign-Language-Detection: A program to detect sign language hand signs in real-time via the webcam and output…
A program to detect sign language hand signs in real-time via the webcam and output the translation of the signs in text and audio form. - GitHub - 4Tsuki4/Handy-Sign-Language-Detection: A program ...
Monday Daily Thread: Project ideas!
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.
/r/Python
https://redd.it/13b7gml
Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.
/r/Python
https://redd.it/13b7gml
Reddit
r/Python on Reddit: Monday Daily Thread: Project ideas!
Posted by u/Im__Joseph - No votes and no comments