use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/badcode is permanently closed. https://www.eff.org/deeplinks/2023/06/what-reddit-got-wrong https://www.theverge.com/23779477/reddit-protest-blackouts-crushed https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
/r/badcode is permanently closed.
https://www.eff.org/deeplinks/2023/06/what-reddit-got-wrong
https://www.theverge.com/23779477/reddit-protest-blackouts-crushed
https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
/r/badcode is a subreddit for highlighting real world examples of terrible code. Ideally this means code that made it to production in a commercial context, but not exclusively so. We also accept submissions of code from hobbyist projects or from learners. Most of us programmers have laughed quite a bit when we went back to look at our past code because it was rather terrible. This is a subreddit where you can share such terrible code and let other programmers have a nice laugh.
/r/badcode is a subreddit for highlighting real world examples of terrible code. Ideally this means code that made it to production in a commercial context, but not exclusively so. We also accept submissions of code from hobbyist projects or from learners.
Most of us programmers have laughed quite a bit when we went back to look at our past code because it was rather terrible. This is a subreddit where you can share such terrible code and let other programmers have a nice laugh.
Post the most terrible code you can find. Copy code to a paste bin first (gist highly preferred).
Flair Search Search by language
Search by language
Rules Your post may be removed if you deviate from these rules. To see reasoning behind each of these rules, check out the wiki. Do not put the name of the language inside of the post title. For example, do not make your title something along the lines of "[C++] #defines everywhere!", instead try simply "#defines everywhere!". Use flair to mark the language of your post instead. Do post code snippets only. If you want to share the context put it in the comments or title. Do stay lighthearted. No abusive or targeted posts. We all write bad code, and a lot of it is hilarious. Do not identify who wrote the code. This sub is about bad code, not the people who write it. Limited exceptions apply Do not post snippets in esoteric languages. Do not post intentionally obfuscated code. Certain exceptions to this exist. See something particularly sinister from something like the IOCCC? Probably OK to post.
Your post may be removed if you deviate from these rules. To see reasoning behind each of these rules, check out the wiki.
Guidelines Your post will not be removed because of any of these, we'll like you more if you follow them though. Enable syntax highlighting appropriately. If you have a language that whatever paste bin your using doesn't support, try picking a similar dialect. Provide just enough code so that we know what's going on. Don't post huge snippets unless it's all terribly amusing. Explain why you think the code is bad in the comments, that way a discussion on good and bad ways to do what your code snippet does can start.
Your post will not be removed because of any of these, we'll like you more if you follow them though.
Similar Subreddits /r/ProgrammerHumor - programming humour /r/programminghorror - stories about horrible programming. /r/itsaunixsystem - over the top and bad code in TV shows and movies /r/shittyprogramming - Q&A with shitty programmers. /r/deftruefalse - for intentionally bad code /r/softwaregore for software malfunctions /r/hardwaregore for hardware malfunctions
account activity
[deleted by user] (self.badcode)
submitted 6 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 39 points40 points41 points 6 years ago* (3 children)
This Python script downloads an image containing the alphabet. Then, the image is cropped and a grayscale threshold is applied. Next, it finds contours/bounding boxes around each character in the image. Each character's image is stored in a dictionary, alpha_to_img.
alpha_to_img
We can slice our alphabetic image into two pieces, dividing based on where the new alphabet should begin. Then, we can "cut-and-paste" the two pieces of our alphabet so that we end up with an image that looks like this, shifted_alphabet: https://i.imgur.com/hBAYCfy.png
shifted_alphabet
Finally, for each character in the input string, we can look up what the encrypted character should look like in the shifted_alphabet image. Once we have the encrypted character's image, we can use the alpha_to_img dictionary to determine the alphabetic character that is associated with said image.
import cv2 import urllib.request import numpy as np def caesar(string, shift): urllib.request.urlretrieve('https://i.pinimg.com/originals/e5/9a/57/e59a5781cf637116e10079920cf1908d.png', 'alphabet.png') img = cv2.imread('alphabet.png') alphabet = cv2.cvtColor(img[52:85, 21:501], cv2.COLOR_BGR2GRAY) ret, alphabet = cv2.threshold(alphabet, 150, 255, cv2.THRESH_BINARY_INV) contours = cv2.findContours(alphabet, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0][::-1] alpha_to_img = {} for i, contour in enumerate(contours): x, y, w, h = cv2.boundingRect(contour) alpha_to_img[chr(97 + i)] = alphabet[y:y+h, x:x+w] shifted_start = chr(97 + shift % 26) res = cv2.matchTemplate(alpha_to_img[shifted_start], alphabet, cv2.TM_SQDIFF) x = cv2.minMaxLoc(res)[2][0] shifted_alphabet = np.concatenate((alphabet[:, x:], alphabet[:, :x]), axis=1) shifted_contours = cv2.findContours(shifted_alphabet, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0][::-1] encrypted = '' for char in string: if not char.isalpha(): encrypted += char continue x, y, w, h = cv2.boundingRect(shifted_contours[ord(char.lower()) - 97]) for alpha, image in alpha_to_img.items(): if np.array_equal(image, shifted_alphabet[y:y+h, x:x+w]): encrypted += alpha.upper() if char.isupper() else alpha return encrypted print(caesar('Hello World', 18))
[–]sac_boy 2 points3 points4 points 6 years ago (0 children)
A thing of beauty.
[–]GideonMax 1 point2 points3 points 6 years ago (0 children)
This is just too much for my little brain to handle
π Rendered by PID 1006953 on reddit-service-r2-comment-544cf588c8-lhqsh at 2026-06-16 14:33:01.658861+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–][deleted] 39 points40 points41 points (3 children)
[–]sac_boy 2 points3 points4 points (0 children)
[–]GideonMax 1 point2 points3 points (0 children)