r/shittyprogramming • u/amphetamachine • Sep 25 '14
Yeah, that'll stop em
http://imgur.com/tWScguW80
53
Sep 25 '14
Better make that array a little bigger
restrictWords.push('bewbs');
restrictWords.push('b00bs');
restrictWords.push('b00bs');26
u/MeowMeowWoofWoof Sep 25 '14
Yes. Bigger is better.
22
Sep 25 '14 edited Sep 25 '14
var str = 'oo'; setInterval(function() { restrictWords.push('b' + str + 'bies'); str += 'o'; }, 10);14
9
u/FuckFuckingKarma Sep 25 '14
That's a lovely loop you have going.
I always knew for loops were stupid.
16
Sep 25 '14
Loops are for the small-minded. This sucker will happily tick along until the sun goes cold.
2
51
u/ILoveWubWubs Sep 25 '14
Eh I am just curious here - out of all XXX websites out there, why amateurmatch(dot)com?
110
42
u/michaelpb Sep 25 '14
Gonna guess his code was being hotlinked by that site, so he put that in there to harass them.
81
u/_Wolfos Sep 25 '14
if(badword==true)cringe
13
u/Protuhj Sep 25 '14
What's wrong with that?
I know that our coding style at work prefers to be explicit in boolean expressions. Of course, javascript is different than C++...
19
u/yasth Sep 26 '14
Well partly you should === in javascript code, as == will do some magical stuff that is often wrong (it won't happen here, but coding style wise you should avoid it). Stuff like:
"a" == true is false
"1" == true is true
0 == '' is true
Just makes most seasoned devs use === to avoid the possibility.
-3
u/Dragon_Slayer_Hunter Sep 26 '14
When you say magical you make it seem like it does it for no reason or no known purpose. That's not true. == has its purposes.
Basically, == doesn't care about type and allows "truthy" and "falsey" comparisons, and === cares about type. This also makes === a bit faster since it doesn't need to worry about truthy/falsey stuff.
0, empty string, empty array, false, null, undefined, and some other things are falsey, so they will == false. Everything thing not falsey is truthy, so it will == true.
1
u/yasth Sep 26 '14
No obviously it has purposes, magical in the concept of programing languages generally involves "automagic" type stuff. It just is (for a lot of developers) surprisingly magical, as they are used to languages where == is a lot more like ===. (Though === has weird things of its own like "a"===new String("a") being false)
It isn't the speed that is an issue (almost all the time, especially with modern javascript implementations which will effectively write === when things are type controlled like here), it is the subtle weirdness that gets in there, and can cause bugs, especially when == is used for user input.
(Also the more fun one is "0" is false )
6
Sep 28 '14 edited Sep 28 '14
'a' === new String('a')beingfalseThis is because
new String(x)is functionally equal toObject(String(x))and creates a new String object instead of a String primitive (typeof new String('a') === 'object'istrue).For simple typecasting drop the
new.
'a' === String('a')will correctly evaluate totrueTested on Spidermonkey (Firefox 32.0.3) and V8 (Node.js v0.10.29)
Differences between String objects and String primitives
String primitives:
◄ var a = 'a';
► undefined
◄ a.b = 5;
► 5
◄ a;
► "a"
◄ a.b;
► undefinedTested on Spidermonkey (Firefox 32.0.3) and V8 (Node.js v0.10.29)
String objects:
◄ var a = new String('a');
► undefined
◄ a.b = 5;
► 5
◄ a;
► "a"(► { '0': 'a', b: 5 }in V8 (Node.js v0.10.29))
◄ a.b;
► 5Tested on Spidermonkey (Firefox 32.0.3) and V8 (Node.js v0.10.29)
0
Sep 25 '14
[deleted]
10
u/Protuhj Sep 25 '14
It's just a coding style. If someone changes the type of the variable (for whatever reason), to let's say, an int,
if (variable) {...}now works for any value that is non-zero.
if (variable == true) {...}just shows the intention of the original code. They aren't functionally different, it's just a style.
It also gets easier to read if the if statement has multiple clauses, and when you have multiple contractors viewing/modifying the code, clarity is preferred over brevity.
33
Sep 26 '14
Good:
if (variable) { ... }Better:
if (variable == true) { ... }Best:
if ((variable == true) == true) { ... }11
u/XL_ARES_IX Sep 26 '14
Besterer:
if((((variable == true) == true) == true) == true)) //just to be safe <|:^) { ... }5
u/RunasSudo Sep 26 '14
Most besterest:
var code = "variable == true";while (true) {code = "(" + code + ") == true";}eval("if (" + code + ") { ... }");3
u/pimp-bangin Sep 27 '14
This seems much more intuitive:
function isTrue(expr) { return expr == true && isTrue(expr); }1
u/XL_ARES_IX Sep 26 '14
this code is OK, but the while loop needs to terminate... I suggest this
while ((((variable == true) == true) == true) == true)) { ... }4
5
u/Steve_the_Scout Sep 26 '14
Just adding on, maybe they actually meant
===in which case it is actually pretty different. IIRC ifvariableis1,variable == trueis true in JavaScript. On the other hand,variable === truewould be false.This is why I stick to more statically typed languages.
1
u/IMMENSELY_BRAVE Sep 26 '14
They aren't functionally different
Yes they are.
#include <iostream> int main() { int i = 123; if (i ) std::cout << "if (i)\n"; if (i == true) std::cout << "if (i == true)\n"; return 0; }Will only print
if (i), but notif (i == true), becausetruegets converted to 1.So if you compare stuff to true and change your boolean to an integer, you will most likely get the wrong result.
1
u/Protuhj Sep 26 '14
I meant in the case that variable was a boolean, that it wasn't functionally different.
My example of saying if someone changed the type of variable to an int, if (variable) would be true for all non-zero values, whereas if (variable == true) would show that the original design meant for it to be a boolean, so whoever changed the code needs to be sure they handle that properly.
2
2
u/ObscureCulturalMeme Sep 26 '14
In Lua, just to give a counter-example, sometimes I really need to know whether a value is an actual boolean false, or is merely nil (which is coerced to false when evaluated in a boolean expression). That's about the only times you'll see me write code like
if foo == false thenThe rest of the time, I'm right there with you.
7
u/hatsune_aru Sep 25 '14
not to mention... the function loops through the entire array even if it finds a match. putting
!badwordin the for loop guardian would make it a little better...6
2
u/ChrissiQ Sep 25 '14
And that check happens after badword was just set to true. They could have just added the document.location into the previous block.
So much fuck I don't even.
1
u/Tyler11223344 Sep 25 '14
Well I'm not particularly involved in scripting, but that statement's after the for loop ends, so I don't know if it'd cause problems to run that line for every bad word found, but that may be why. Although, if he'd just end the loop as soon as one word was found he wouldn't have to do this in the first place.....
1
u/ChrissiQ Sep 26 '14
That's partly true but the thing is, it will only ever be true once. Because after it's true, you get an alert and get redirected.
1
14
13
8
7
Sep 25 '14
Oh shit it even calls FBI.com
5
u/ekolis Sep 26 '14
Had to check if they actually redirected to fbi.com instead of fbi.gov after reading this...
5
u/inconspicuous_male Sep 25 '14
What about websites that ask you to pay for porn?
14
1
Sep 25 '14
I get it, this would pop up an alert over and over again for every time this detects a bad word.
8
u/amphetamachine Sep 25 '14
Only until it redirected you to the FBI.
6
Sep 25 '14
indeed, that is outside of the for loop.
at least it doesn't run for every word in the document - assuming he is populating 'word' correctly.
It bothered me that 'free sex' is considered a word, and not 'words'.
7
5
u/ekolis Sep 26 '14
Odd that he put a specific site in there... sounds like they were linking directly to his script on his server, as opposed to using a local copy! Otherwise what's the point of changing the script, unless he planned on them getting it? Or maybe he's just paranoid...
3
1
u/zman0900 Sep 25 '14
WTF is going on with that last for loop? Doesn't look like this thing will even call the function with any data.
16
u/TugOnYourWinky Sep 25 '14
Damn son, where'd you find this?