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

Add ?censor and ?safe params #270

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

odinhb
Copy link

@odinhb odinhb commented Jul 7, 2023

Closes #264

odinhb added 5 commits June 28, 2023 01:00
i wanna be in the messages! :D
i don't have poor eyesight but staring at the page for long enough
i noticed that the link was really hard to see
enabling everyone to shit up their workplaces :D
@odinhb odinhb force-pushed the second-try-safe-for-work branch from 7ba5ccc to 61f715b Compare July 7, 2023 21:29
@ngerakines
Copy link
Owner

Really like the direction this is going on. I have some small changes and feedback that I'll get to next week.

@odinhb
Copy link
Author

odinhb commented Jan 30, 2024

I'm still curious about the feedback on this one. I'm not a python developer by day so it would be appreciated.

Copy link

@ferdnyc ferdnyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts, all take-it-or-leave-it stuff of course. Some bikeshedding, but not too much (I hope).

GRAWLIX = "!@#$%&*"

def _censor_swearing(txt, censor=False):
grawlix_chars = censor if type(censor) == str else GRAWLIX
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
grawlix_chars = censor if type(censor) == str else GRAWLIX
grawlix_chars = censor if isinstance(censor, str) else GRAWLIX

Comment on lines +40 to +43
safe_f = open("commit_messages/safe.txt", "w")
unsafe_f = open("commit_messages/unsafe.txt", "w")

with open("./commit_messages.txt") as original_f:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, for the future, this can be done in one statement as:

with (
    open("commit_messages/safe.txt", "w") as safe_f,
    open("commit_messages/unsafe.txt", "w") as unsafe_f,
    open("./commit_messages.txt") as original_f,
):

...And then you don't need any explicit .close()es.

(Python 3.10+ is required to surround the open()s with ()s, otherwise they all need to be on one line.)

Comment on lines -35 to +48
<p class="permalink">
<p class="link-wrapper">
[<a href="/{{ message_hash }}">permalink</a>]
</p>
<p class="link-wrapper">
[<a href="/">unsafe</a>]
</p>
<p class="link-wrapper">
[<a href="/?safe">safe only</a>]
</p>
<p class="link-wrapper">
[<a href="/?censor">censored</a>]
</p>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having all these links just... kind of "dumped" here might be confusing, especially since the permalink and the others are completely different animals. (The other three links are completely unconnected to the current commit reason being shown.) Having them all together feels sort of like it's implying that the link goes to a "safe only or "censored" version of the current message. At least, it could be misinterpreted that way.

I wonder if it would look cleaner (and be clearer to users) to separate the site-links out a bit from the current output, and maybe add some sort of heading? e.g:

<h3>Get another</h3>
<ul class="link-list">
  <li class="link-wrapper"><a href="/">unsafe</a></li>
  <li class="link-wrapper"><a href="/?safe">safe only</a></li>
  <li class="link-wrapper"><a href="/?censor">censored</a></li>
</ul>

(The UL can always be styled to remove the bullets:)

.link-list { list-style: none; }

@@ -82,6 +82,7 @@ Name: github:KneeNinetySeven
Name: Rafael Reis (github:reisraff)
Name: github:ShanTulshi
Name: Jonatha Daguerre (github:jonathadv)
Name: Odin Heggvold Bekkelund (github: odinhb)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Name: Odin Heggvold Bekkelund (github: odinhb)
Name: Odin Heggvold Bekkelund (github:odinhb)

😉

Comment on lines +69 to +76
with open(humans_file, 'r', encoding='utf-8') as f:
for line in f:
if "Name:" in line:
data = line[6:].rstrip()
if data.find("github:") == 0:
names.append(data[7:])
else:
names.append(data.split(" ")[0])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with open(humans_file, 'r', encoding='utf-8') as f:
for line in f:
if "Name:" in line:
data = line[6:].rstrip()
if data.find("github:") == 0:
names.append(data[7:])
else:
names.append(data.split(" ")[0])
def _extract_name(name):
if name.startswith("github:"):
return name.removeprefix("github:")
return name.split(" ")[0]
with open(humans_file, 'r', encoding='utf-8') as f:
names = [
_extract_name(line.rstrip().removeprefix("Name: "))
for line in f
if line.startswith("Name: ")
]

List comprehensions are much faster than looping .append()s, as they avoid repeated list reallocations. And then you don't need to create the empty list variable in advance.

(Though IMHO the code to extract the names should be in a function that returns the list, and names should be defined in one go with names = _read_name_list(humans_file).)

str.removeprefix is Python 3.9+, if that's too high a minimum version the string-index math is still an option.

Comment on lines +51 to +59
with open(safe_templates_file, 'r', encoding='utf-8') as f:
for line in f:
_hash_and_store(line, safe_templates)
with open(unsafe_templates_file, 'r', encoding='utf-8') as f:
for line in f:
_hash_and_store(line, unsafe_templates)
with open(censorable_templates_file, 'r', encoding='utf-8') as f:
for line in f:
_hash_and_store(line, censorable_templates)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto:

Suggested change
with open(safe_templates_file, 'r', encoding='utf-8') as f:
for line in f:
_hash_and_store(line, safe_templates)
with open(unsafe_templates_file, 'r', encoding='utf-8') as f:
for line in f:
_hash_and_store(line, unsafe_templates)
with open(censorable_templates_file, 'r', encoding='utf-8') as f:
for line in f:
_hash_and_store(line, censorable_templates)
with open(safe_templates_file, 'r', encoding='utf-8') as f:
safe_templates = {
_hash_template(line): line
for line in f
}
with open(unsafe_templates_file, 'r', encoding='utf-8') as f:
unsafe_templates = {
_hash_template(line): line
for line in f
}
with open(censorable_templates_file, 'r', encoding='utf-8') as f:
censorable_templates = {
_hash_template(line): line
for line in f
}

...And you can get rid of _hash_and_store() completely.

list(censorable_templates.keys()))
if len(all_template_digests) != len(set(all_template_digests)):
raise Exception("uniqueness problem with source data")
check_for_collisions()
Copy link

@ferdnyc ferdnyc May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line before this call, please. (black and safepep8 will actually tell you they want two blank lines on either side of it. But at least one.)

Comment on lines +83 to +95
def _fill_template(txt, censor=False):
txt = txt.replace('XNAMEX', random.choice(names))
txt = txt.replace('XUPPERNAMEX', random.choice(names).upper())
txt = txt.replace('XLOWERNAMEX', random.choice(names).lower())
if censor:
txt = _censor_swearing(txt, censor=censor)

nums = num_re.findall(txt)

while nums:
start = 1
end = 999
value = nums.pop(0) or str(end)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A documentation comment would be helpful here, because I have no idea what this function is doing.

@@ -387,7 +360,6 @@ Updated framework to the lattest version
Use a real JS construct, WTF knows why this works in chromium.
Useful text
Version control is awful
WHO THE FUCK CAME UP WITH MAKE?
WIP, always
WIPTF
WTF is this.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some argument to be made that all of the *TF messages also belong in the unsafe file. They're not really usefully censorable, but they're not really censored per se, either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider a page for non explicit commits ?
3 participants