Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 461 462 [463] 464 465 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 815667 times)

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6930 on: January 30, 2015, 09:43:11 pm »

Yep. Alt + Drag is pretty much what separates a programmer from an amateurgrammer. It is the best.
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6931 on: January 31, 2015, 06:12:50 am »

Haha, welp.
I wrote this. Try to see what's wrong.


Spoiler (click to show/hide)
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6932 on: January 31, 2015, 06:23:15 am »

And that's why you sanitize your inputs :P
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6933 on: January 31, 2015, 06:34:10 am »

And that's why you sanitize your inputs :P
It IS an input sanitization function, there are no builtin sanitization functions except for html_decode() and html_encode() :c
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6934 on: January 31, 2015, 08:12:30 am »

What's wrong with HTML_encode? Won't that just make anything they enter into displayable text, no tag injection exploits?
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6935 on: January 31, 2015, 08:54:05 am »

What's wrong with HTML_encode? Won't that just make anything they enter into displayable text, no tag injection exploits?
Yeah, but sometimes you want to strip all the tags.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6936 on: January 31, 2015, 06:25:13 pm »

In Python, you would use string.strip(thing_to_be_stripped) and be done with it.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6937 on: January 31, 2015, 06:28:39 pm »

The DM language looks like something I would prefer not to use. I might even subject myself to PHP given the choice.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6938 on: January 31, 2015, 06:43:27 pm »

Haha, welp.
I wrote this. Try to see what's wrong.


Spoiler (click to show/hide)

You might be able to fix your one by constraining the search for the ">" token to after the start of the "<". But the basic way to do it is to copy all chars to from the input one at a time to your output, and basically throw away characters found after you find a "<". Then, if you're in that state and find a ">" you switch back to state 1.

So your have two states, which can be represented as two nested while loops. The most basic form of the algorithm is thus:

While (not end-of-input)
    scan char
    if (char <> "<")
         append char to output
    else
          while (char <> ">" AND not end-of-input)
               scan char
          end while
    end if
end while

Both algorithms would have a problem if e.g. there was a string inside a tag with a greater-than symbol in it, e.g. javascript on an element which adds a tag, or a comparison which uses the > symbol. So to be totally legit you'd need to also scan the inside of each tag for strings delimited with ' and ", and ignore ">" symbols if they're inside a pair of quotes:

While (not end-of-input)
    scan char
    if (char <> "<")
         append char to output
    else
          while (char <> ">" AND not end-of-input)
               scan char
               if (char == single-quotes)
                    do
                         scan char
                    while (char <> single-quotes AND not end-of-input)
               else if (char == double-quotes)
                    do
                         scan char
                    while (char <> double-quotes AND not end-of-input)
               end if
          end while
    end if
end while

should work perfectly even for cases where there was a tag or > inside a string in a tag.
« Last Edit: January 31, 2015, 07:09:40 pm by Reelya »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6940 on: February 01, 2015, 04:49:10 am »

The DM language looks like something I would prefer not to use. I might even subject myself to PHP given the choice.
TBH, it's not that bad once you get the hang of it. PHP still sounds worse.
The biggest shittiness isn't in the language, it's in the fact that it's built on mountains of undocumented C++ spaghetti enclosing a shitcode rainforest inhabited by braindamaged code monkeys.

BYOND could be quite good, if it weren't for the fact that the underlying code is really, really bad. The function call overhead is huge, you can't fit more than 256 icons in one file because they're scared about what happens byond that point, you can't get a stack trace without crashing the current procedure, etc, etc.

It certainly doesn't help that it's usually beginners using this language, so shitcode naturally arises.

Also, somebody else already made a fix while I was doing other things, it seems.
« Last Edit: February 01, 2015, 04:50:45 am by miauw62 »
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6941 on: February 01, 2015, 04:51:31 am »

Quote
because they're scared about what happens byond that point
I see what you did there...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6943 on: February 02, 2015, 07:24:21 pm »

So for a couple of hours I've been trying to create a RNG that would create a bell curve, the peak at 1, that I could also affect the spread of with a parameter.
So far I've tried doing what are essentially a bunch of dice rolls, but it seems no matter how many "dice" I have the result can vary massively. I've also tried pissing around a bit with powers but nothing much has come of that.

I'm sure there must be a better way but for the life of my can't think what it is, and I really can't progress until I've worked this out.
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6944 on: February 02, 2015, 07:34:36 pm »

What language and RNG are you using to generate your "dice"?  Whatever it is, it probably has a lot of bias in the name of being fast, which is going to show up in the results.  Aside from implementing a known algorithm like the Mersenne Twister, I'm not sure really what you can do about that.  A statistician might have a better answer.
Logged
Through pain, I find wisdom.
Pages: 1 ... 461 462 [463] 464 465 ... 795