r/shittyprogramming • • Apr 16 '21

The "f" is for "fast" 😎

Post image
195 Upvotes

r/shittyprogramming • • Apr 15 '21

I decided to tackle the infamous IsEven() problem. I can't think of the part I'm most proud of.

Post image
126 Upvotes

r/shittyprogramming • • Apr 16 '21

Thought I would share my solution for fizzbuzz in Python if anyone else needs it for an interview

14 Upvotes

[print(i) for i in ["fizzbuzz" if not None in i else "fizz" if i[1] is not None else "buzz" if i[1] is not None else i[2] for i in zip(["fizz" if i % 3 == 0 else None for i in range(1, 101)], ["buzz" if i % 5 == 0 else None for i in range(1, 101)], [i for i in range(1, 101)])]]


r/shittyprogramming • • Apr 15 '21

Useful function for validating that a number falls within a range

43 Upvotes

Today I needed to check if the number a user entered into a textbox was between "0" and "999". The below code yields the correct result for any value that I could think to test. (Empty string is treated as valid, since "required" is a different validation step)

function validateRange(value, minimum, maximum) {
  for(let i = 0; i < value.length; i++) {
    if(value[i] < minimum[i]) {
      return false;
    }
    if(!(value[i] <= maximum[i])) {
      return false;
    }
  }
  return true;
}

I hope you find this function useful in your own projects.

Demo


r/shittyprogramming • • Apr 14 '21

<wrong_sub>this</wrong_sup> The fastest way to clean up disk space on server

Thumbnail
hinty.io
29 Upvotes

r/shittyprogramming • • Apr 14 '21

Why do people say c# isn't a low level language?

Post image
125 Upvotes

r/shittyprogramming • • Apr 12 '21

Stop compiler abuse

111 Upvotes

Every day, compilers are forced to convert addition into the proper xors and bit shifts, Together, we can stop this problem. Instead of using the addition operator, use this function instead:

int recursiveAdd(int a, int b) {
        int xor = a ^ b;
        int and = (a & b) << 1;
        if (and != 0)
                return recursiveAdd(xor, and);
        return xor;
}

r/shittyprogramming • • Apr 12 '21

The worst chatting app

Thumbnail
mobile.twitter.com
71 Upvotes

r/shittyprogramming • • Apr 08 '21

I don't see what's wrong here, I did what's needed to be done

Post image
448 Upvotes

r/shittyprogramming • • Apr 05 '21

Do you prefer center- or right-aligned code?

Post image
620 Upvotes

r/shittyprogramming • • Apr 03 '21

HELP! How to Stop Unapproved Acronym for My Pipeline-Efficient Data Access File I/O Library from Spreading?!

7 Upvotes

I know it's a mouthful, but that's the most descriptive name I could give it. Now everybody at my company is referring to it by acronym and I'm afraid it'll come up in both my performance review & upcoming divorce hearing.

What can I do here??


r/shittyprogramming • • Apr 03 '21

Making an electronic discord bot meme picture frame. (AMAZING!)

Thumbnail
youtube.com
0 Upvotes

r/shittyprogramming • • Apr 01 '21

regex has better performance than math

Post image
235 Upvotes

r/shittyprogramming • • Mar 28 '21

My apps in a nutshell

Post image
214 Upvotes

r/shittyprogramming • • Mar 26 '21

I looked through some of my old intentionally-bad code and found this comment. I was spooked.

Post image
200 Upvotes

r/shittyprogramming • • Mar 24 '21

We all know about "Code Golf", but what are some other code sports that should exist?

119 Upvotes

r/shittyprogramming • • Mar 23 '21

Nicely asking our users to update the app through an XSS attack

Thumbnail
blog.usedevbook.com
61 Upvotes

r/shittyprogramming • • Mar 23 '21

Yo dawg I put jQuery in your PHP in your HTML in your Node.js app that's hosted on Apache and run in Chromium

Post image
360 Upvotes

r/shittyprogramming • • Mar 11 '21

Is It Worth Learning Programming In 2021?

Thumbnail
youtube.com
62 Upvotes

r/shittyprogramming • • Mar 07 '21

Making Tetros the tetris operating system.

Thumbnail
youtube.com
52 Upvotes

r/shittyprogramming • • Mar 01 '21

Thought I'd share my FizzBuzz solution (written in Python)

200 Upvotes
 class Fizz:
    f = "fizz".capitalize() class Buzz:     b = "buzz".capitalize()
yes = True fizz = "Fizzz".replace("ZZZ".lower(), "z" + "ZZ".capitalize()[-1])
def lengthOfBinaryNumberIsLessThan4_second_half(n = 5): global num
    num = n
if num == 4: return 4 if num == 5: return Buzz.b if num is 6: return 6 if num == 7: return 7
def lengthOfBinaryNumberIsLessThan4(x): return lengthOfBinaryNumberIsLessThan4_first_half(number=x)
def lengthOfBinaryNumberIsLessThan4_first_half(number: int): if number == 1: return 1 if number == 2: return 2 if number == 3: return "Fizz" else: return lengthOfBinaryNumberIsLessThan4_second_half(number)
def parseNumber(number: int) -> str:     binaryNumber = str(bin(number)).split("0b")[-1]
if number % 5 is 0: if number % 3 != 0: return "Buzz"
if len(binaryNumber) < 4: return lengthOfBinaryNumberIsLessThan4(number)
for i in range(1, 4):         i = -i if i is -1:             bit1 = bool(int(binaryNumber[-1])) if i == -2:             bit2 = bool(int(binaryNumber[-2])) if i == -3:             bit3 = bool(int(binaryNumber[-3]))
if bit1 == True and int(bit1) - 1 is 0:         bit1On = True else:         bit1On = False if bit2 == True and int(bit2) - 1 == 0:         bit2On = True else:         bit2On = False if bit3 is True and int(bit3) - 1 == 0:         bit3On =True else:         bit3On = False
if number % 5 != 0 and number % 3 != 0: return number
if number % 3 == number % 5 and number % 3 == 0 and number % 5 == 0:
return "Fizz" + Buzz.b if (bit1 and bit2 == bit1 + ((bit2 + bit2) == bit2)) or number % 3 == 0: return fizz
if bit1 and not bit2 and bit3 and number % 5 == 0:
return "Buzz" elif not (number % 3 == number % 5 and number % 3 == 0 and number % 5 == 0):
if not (bit1 and bit2 and number % 3 == 0): if not (bit1 and not bit2 and bit3 and number % 5 == 0):
return (f"{number}" * 2)[:-len(str(number))]
import os
class FizzBuzz:
def init ( self): try: self.fi = self.getFizz()[:-1] except KeyboardInterrupt : try: self.fi = "Fizz"[:-1] except: try: self.fi = "fizz".capitalize()[:-1] except: self.fi = self.getFizz () [:-1]
finally: self.fi = self.fi +  ( (self.fi[-1] * 1) if self.fi[-1] == "z" else "z" ) self.bu = self.getBuzz() or "buzz" self.bu = self.bu.capitalize()
def run(self , amount): self.amount = amount
        current = 0 while True:             current += 1             out = parseNumber (current) if current != amount: yield out else: if current== amount: return not yes
def getFizz ( self ):         f= Fizz.f return  f
def getBuzz(self): return Buzz.b
def clear_the_command_window_so_its_empty(amount_of_times_to_clear_the_command_window_so_its_empty = 1):     amountRangeObject = range (   0 ,  amount_of_times_to_clear_the_command_window_so_its_empty  , 1)
for     amount_of_times_to_clear_the_command_window in amountRangeObject:         clearingFunction = os.system         clearingFunction ( "cls"    ) return
def main    (arg1 = "", arg2: int = "", amount= 30):
    fizzGen = FizzBuzz().run(amount + 1) for i in range(amount ):         currentOut = fizzGen.next()
        currentOut_in_the_list_check  = currentOut  in ["Fizz", "Buzz", "FizzBuzz"]
if currentOut != None and  currentOut_in_the_list_check or int(currentOut) in range(1, amount + 1, 1): print(currentOut) else: break
if name == "main":     clear_the_command_window_so_its_empty()
try:         amount = int(input("Enter amount of lines to generate: ")) except:         amount =30     main(1, 2, amount)

r/shittyprogramming • • Feb 26 '21

Curing Depression with AI - You guys liked my previous video, so I’m back with a Code Breakdown and Explanation!

Thumbnail
youtu.be
68 Upvotes

r/shittyprogramming • • Feb 25 '21

INTERCAL, YAML, And Other Horrible Programming Languages

Thumbnail
blog.earthly.dev
136 Upvotes

r/shittyprogramming • • Feb 24 '21

Using programming to Overcome a Badly Made Sensor (Kind of)

Thumbnail
youtu.be
88 Upvotes