Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » What's the funniest code we can think of?
- Maximouse
-
Scratcher
1000+ posts
What's the funniest code we can think of?
This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:your code is vulnerable to code injection, if i run the below, all your files are gone foreverthe worst part of this is that a variable is named “bool”import os def print(something): os.system(f"echo {something}") print("mybearworld")use the subprocess module insteadprint("'bye bye lol'; rm -rf ~/*")from subprocess import run def print(something): run(["echo", something]) print("mybearworld")
run(["/usr/bin/echo", something])
- mybearworld
-
Scratcher
1000+ posts
What's the funniest code we can think of?
(#1422)This is still vulnerable – an attacker can put a file named “subprocess.py” in the working directory. Not doing it like that is safer:This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:your code is vulnerable to code injection, if i run the below, all your files are gone foreverthe worst part of this is that a variable is named “bool”import os def print(something): os.system(f"echo {something}") print("mybearworld")use the subprocess module insteadprint("'bye bye lol'; rm -rf ~/*")from subprocess import run def print(something): run(["echo", something]) print("mybearworld")run(["/usr/bin/echo", something])
print(something)
Last edited by mybearworld (Sept. 21, 2022 15:51:35)
- CST1229
-
Scratcher
1000+ posts
What's the funniest code we can think of?
(#1423)But then it loses all its funniness!(#1422)This is still vulnerable – an attacker can put a file named “subprocess.py” in the working directory. Not doing it like that is safer:This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:your code is vulnerable to code injection, if i run the below, all your files are gone foreverthe worst part of this is that a variable is named “bool”import os def print(something): os.system(f"echo {something}") print("mybearworld")use the subprocess module insteadprint("'bye bye lol'; rm -rf ~/*")from subprocess import run def print(something): run(["echo", something]) print("mybearworld")run(["/usr/bin/echo", something])print(something)
- Vaibhs11
-
Scratcher
1000+ posts
What's the funniest code we can think of?
I wish we had a forum nerd emoji

cough cough ahem lets get back to topic shall we
- Chiroyce
-
Scratcher
1000+ posts
What's the funniest code we can think of?
This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:Ah I said that because in case the print function takes user input it would be a problem. Also what mybearworld makes sense, if you anyways have access to the filesystem then this is pointless and my point still stands.
also i think i posted this before but this is still funny lol
try { throw "ball"; } catch (ball) { console.log("I caught a " + ball); }
Last edited by Chiroyce (Sept. 21, 2022 16:13:14)
- mybearworld
-
Scratcher
1000+ posts
What's the funniest code we can think of?
(#1426)Such bad exception handling!This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:Ah I said that because in case the print function takes user input it would be a problem. Also what mybearworld makes sense, if you anyways have access to the filesystem then this is pointless and my point still stands.
also i think i posted this before but this is still funny lolno template strings as djangobb formatter doesnt support ittry { throw "ball"; } catch (ball) { console.log("I caught a " + ball); }
This is how it's supposed to be:
try { throw Math.random() <= 0.5 ? "ball" : Error(); } catch (ball) { console.log("I caught " + (String(ball).toLowerCase().startsWith("a") || String(ball).toLowerCase().startsWith("e") || String(ball).toLowerCase().startsWith("i") || String(ball).toLowerCase().startsWith("o") || String(ball).toLowerCase().startsWith("u") ? "an" : "a") + " " + ball); }
- gosoccerboy5
-
Scratcher
1000+ posts
What's the funniest code we can think of?
yes ik about forumoji but who the * wants to use that every time they want an emoji lmao(#1420)
I wish we had a forum nerd emoji
[offtopic]why do people always use [code=python] instead of [code py3]? it actually has correct syntax highlighting![/offtopic]my reaction to this:






- gosoccerboy5
-
Scratcher
1000+ posts
What's the funniest code we can think of?
also, `exec` and `input` are safe together right?
should be fine right?
exec(input("What code you want to run today?"))
- mybearworld
-
Scratcher
1000+ posts
What's the funniest code we can think of?
yes ik about forumoji but who the * wants to use that every time they want an emoji lmaoyeahh

who would do that
seriously
how come people actually do that 


- mybearworld
-
Scratcher
1000+ posts
What's the funniest code we can think of?
(#1429)Yes of course! Noone would input anything like __import__(“os”).system(“rem whatever the code for deleting everything is”)!
also, `exec` and `input` are safe together right?should be fine right?exec(input("What code you want to run today?"))
edit: fixed py to py3
Last edited by mybearworld (Sept. 21, 2022 18:15:37)
- NanoRook
-
Scratcher
1000+ posts
What's the funniest code we can think of?
(#1426)Such bad exception handling!This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:Ah I said that because in case the print function takes user input it would be a problem. Also what mybearworld makes sense, if you anyways have access to the filesystem then this is pointless and my point still stands.
also i think i posted this before but this is still funny lolno template strings as djangobb formatter doesnt support ittry { throw "ball"; } catch (ball) { console.log("I caught a " + ball); }
This is how it's supposed to be:try { throw Math.random() <= 0.5 ? "ball" : Error(); } catch (ball) { console.log("I caught " + (String(ball).toLowerCase().startsWith("a") || String(ball).toLowerCase().startsWith("e") || String(ball).toLowerCase().startsWith("i") || String(ball).toLowerCase().startsWith("o") || String(ball).toLowerCase().startsWith("u") ? "an" : "a") + " " + ball); }
least boilerplate filled java code
- Maximouse
-
Scratcher
1000+ posts
What's the funniest code we can think of?
Python imports modules from the directory where the script is located, not the current directory.This is still vulnerable – an attacker can put a file named “echo” in the working directory. Using an absolute path is safer:This is still vulnerable – an attacker can put a file named “subprocess.py” in the working directory. Not doing it like that is safer:run(["/usr/bin/echo", something])print(something)
- mybearworld
-
Scratcher
1000+ posts
What's the funniest code we can think of?
least boilerplate filled java codeleast boilerplate filled java code
- DifferentDance8
-
Scratcher
1000+ posts
What's the funniest code we can think of?
int main() { // statistically proven to be random int x; std::cout << x << '\n' return 0; }
- ajskateboarder
-
Scratcher
1000+ posts
What's the funniest code we can think of?
Silly code that actually works
This is also some useless code:
def main(): { print("Hello world") } if __name__ == "__main__": main()
This is also some useless code:
pass; import sys; import os; from win32con import TRUE; print;(1);Warning;();'a\a';rnd=exec.__eq__(repr);''.__format__('');pass;xy=['1', 2, 't{}'.format('he. what')], property.__format__;sys.__dict__;x=1;print('...', end='{}'.format(''.format('\n...')));'//._.\\';y=""" what is actually going on!""";print(x);del sys; sys='what i just deleted sys'; print(sys); 'lmao nothing gets printed anymore'; sys.replace('\n\n\n', f'{bool.__class__}'.format(True)); print(str(xy).replace('(', '').replace(')', '') .replace(", <method '__format__' of 'object' objects>", '').replace("'", '').replace('[', '').replace(']', '').split(' ')[2], str(xy).replace('(', '').replace(')', '').replace(", <method '__format__' of 'object' objects>", '').replace("'", '') .replace('[', '').replace(']', '').split(' ')[3]); os.chdir(os.getcwd()); del x; x = 1;pass;pass;pass;pass;pass;
- TheSecondGilbert
-
Scratcher
100+ posts
What's the funniest code we can think of?
Email addresses can be valid expressions in python, it just takes a bit of preparation.It could be “better”:class Before: def __init__(self): self.smith = After() self.com = After() class After: def __matmul__(self,other): return "Python email address" john = Before() example = Before() print(john.smith@example.com)
class Name(list): def __init__(self, name): super().__init__(name.split(".")) def __getattr__(self, name): self.append(name) return self def __str__(self): return ".".join(iter(self)) def __repr__(self): return f"Name({str(self)!r})" def __matmul__(self, domain): return Email(self, domain) class Email(tuple): def __new__(self, name, domain): return super().__new__(Email, (name, domain)) def __str__(self): return f"{self[0]}@{self[1]}" def __repr__(self): return f"Email{super().__repr__()}" john = Name("john") example = Name("example") email = john.smith@example.com print(email) print(repr(email))
- BreadcatGames
-
Scratcher
1000+ posts
What's the funniest code we can think of?
This one is from C++, another macro:That’s actually genius#include <iostream> #define System S s;s #define public #define static #define void int #define main(x) main() struct F{void println(char* s){std::cout << s << std::endl;}}; struct S{F out;}; /* this guy's a genius... */ public static void main(String[] args) { System.out.println("Hello World!"); }












