Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Recommendations #27

Open
Farhaduneci opened this issue Jul 24, 2022 · 2 comments
Open

General Recommendations #27

Farhaduneci opened this issue Jul 24, 2022 · 2 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers

Comments

@Farhaduneci
Copy link
Collaborator

Hey Sadra,
I wish you doing well, thank you for this great project, PasteMe has become one of my favorite online tools for sure.

I've viewed the project codebase and like to share my opinions on a couple of things that caught my 👀, so we share ideas about them here. I hope these make everything a little better and make the project to move forward.

None of my recommindations would have any affects on the core website functionality, they are more related to back-end enhancments and visual aspects of the project.

1. Snippet UUID Alphabet,

You have used 12 characters abcdefg12345 as ShortUUIDField in Snippet model file, here is the code.

id = ShortUUIDField(
length=5,
max_length=40,
alphabet="abcdefg12345",
primary_key=True,
)

These characters will make $12^5$ unique combinations based on your desired 5 char length UUIDs, that will have the capacity to produce $28K$ pastes in the application. I believe that's not a huge number for a pastebin service, I think this can simply be solved by using the built-in string module character groups and extending the alphabet to English letters and digits!

from string import ascii_letters, digits
alphabet = ascii_letters + digits

This way, the system will be able to create $62^5$ UUIDs (pastes), which is $\approx 916M$ possibilities.

This number can be shrinked by using smaller, but big-enouph, character groups like ascii_lowercase or ascii_uppercase. They will support $\approx 11M$ UUIDs.

I've done this in my 🍴, would be happy to open a PR if you're intrested.

2. Using Code Formatters,

After cloning the codebase on my machine, I've noticed that every file I visit is marked as edited via Git! It happens because of the Final new line that my code editor appends to each file, There are also Not Trimmed Trailing White spaces in the code and some random Extra new lines.

class HomeView(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["stats"] = Statistic.objects.last()
return context
class SnippetView(DetailView):
model = Snippet
template_name = 'snippet.html'
context_object_name = 'snippet'

All together, they make the codebase a little dirty and might make the pycodestyle and even some people 😒 about formatting.

I recommend using the “Black Formatter” in the project!

By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from 😒 faces. You will save time and mental energy for more important matters.

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while, and you can focus on the content instead.

This can be achieved by using black locally as formatter on save, and checking the code style by GitHub Actions integration on every push to make sure everything is OK.

I've created an action file that does the job in my 🍴, would be happy to open a PR if you're intrested.

3. The Footer,

IDK why, but I believe all footers need to be sticky, They are called footers anyway 😆. This made me to feel out of comfort-zone and I think it's better that the footer be sticky, So it stocks down there now.

Before:

image

After:

image

I've made the footer sticky in my 🍴, would be happy to open a PR if you're intrested.

4. Endpoints Rate Limit,

Pastebin websites are usually tasty 🍰 for new hackers, I'm not a security specialist, but rate-limiting end-points are always a good practice. Django Ratelimit is a rate-limiting decorator for Django views, storing rate data in the configured Django cache backend. I recommend using this package in the project.

@lnxpy
Copy link
Member

lnxpy commented Jul 26, 2022

Hi Farhad,

Your thoughts and notes are so noticeable, to be honest. Since the deployed version is more likely to be a simple MVP competing in the Hackathon, it definitely needs improvements and that's why it's open source!! I will work on the CI-related workflows (probably working with Github Actions) and dev-based tools to make a quick guide for those who are willing to have contributions to PasteMe.

I'll label this issue and keep it open till I finished writing the CONTRIBUTING doc and improve the tests. Once I'm done, feel free to make PRs.

Would you please trunk that "footer sticky part" commits to another PR and open it now? It looks to be something related to the templates and static files. We'll work on the codebase later. :)

Much appreciate your love for opening this issue and sharing your opinion. 👍🏻 ❤️

@lnxpy lnxpy added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers labels Jul 26, 2022
@lnxpy lnxpy pinned this issue Jul 26, 2022
@lnxpy lnxpy closed this as completed in 12eec4e Jul 27, 2022
@lnxpy lnxpy unpinned this issue Jul 27, 2022
@lnxpy lnxpy reopened this Jul 29, 2022
@lnxpy
Copy link
Member

lnxpy commented Jul 29, 2022

  • Sticky template footer
  • Snippet model ID field range needs a change
  • Security optimizations
  • Linter & formatter setup (using pre-commit)

@lnxpy lnxpy pinned this issue Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants