Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Optimus Prime Ribs
Jul 25, 2007

Found this in the backend for our CMS:
php:
<?
$current_event_id = "";
if(file_exists("../site/config/config.txt")){
    $config_file_lines = file("config/config.txt");
    foreach( $config_file_lines as $config_file_line ){
        if( trim($config_file_line) != "" ){
            $current_event_id = trim($config_file_line);
        }
    }
}?>
All that "config.txt" contains is a single number. Nothing else. Ever.
This was written by the dudes who manage my work's servers. Those same guys also wouldn't give me the source code to something they wrote (just so I figure out which objects it was referencing and replicate easily) because they didn't want me stealing their code.

And the way these files our laid out that bit of code actually gets called like 4 times per page.

And then there's this gem on the same file as above (this is the way they had it formatted as well):
php:
<?
if( $row['field_options'] != "" ){

            $field_item['field_options'] = array();

            $field_item['field_options'] = explode("|", trim($row['field_options']));

        }?>
I need to talk to my boss and get us running our own servers. :(

Optimus Prime Ribs fucked around with this message at 22:37 on Oct 17, 2011

Adbot
ADBOT LOVES YOU

Optimus Prime Ribs
Jul 25, 2007

Doc Hawkins posted:

Or claim you think you can optimize the site if some overtime will get approved. Remove 10-20% of the blank lines, goof off for the rest of the time, collect money, repeat as needed.

Too bad I can't pull that ruse. I get paid by the year. :(
I'll just stick to fixing up all this horrible code I've been running in to.

Optimus Prime Ribs
Jul 25, 2007

nielsm posted:

VC10 still has a compiler option to allow that broken scoping

Why would you want to do this? :confused:

Optimus Prime Ribs
Jul 25, 2007

tractor fanatic posted:

well you HAD to do that in VC6.0 since

code:
for(int i=0;;);
for(int i=0;;);
was a compile time error.

Well isn't that cute.

Optimus Prime Ribs
Jul 25, 2007

rjmccall posted:

There is a camp that claims that modifying const objects should be okay as long as you put them back the way you found them. It's not completely irrational, but it's obviously something to be very careful about, and it's still not a great idea.

Why would someone make something const if the value isn't constant?
What purpose could that possibly serve?

Seems pretty stupid to me.

Optimus Prime Ribs
Jul 25, 2007

BP posted:

It would allow you to modify the memory storing the object, as long as you can reverse the changes, rather than making a copy of the memory and mutating the copy. This could lead to some memory savings in some cases.

Makes sense and all but from a practical stand-point I just don't get why someone would want to write their code that way.
Whenever I use const it's for things which I know will never change (e.g. if I wanted to store pi in a variable for some reason).

Oh well. People will always be doin' dumb things. v:shobon:v

Optimus Prime Ribs
Jul 25, 2007

I'm not really sure what this was supposed to be used for. Written by some dude a year ago, who left where I work before I got there.
This is all that was in the file. :iiam:

php:
<?
$gConfig = array();
require "../../../config/config.php";

$db_connection_str = "host=" . $gConfig['db']['event']['host'] . " dbname=" . $gConfig['db']['event']['name'] . " user=" . $gConfig['db']['event']['user'] . " password=" . $gConfig['db']['event']['password'];
$db_connection = pg_pconnect($db_connection_str);

$stmt = "select * from _event where event_id = " . $_POST['event_id'];

$result = pg_query($db_connection, $stmt);
if( pg_num_rows($result) > 0 ){
    $handle = fopen("../site/config/config.txt", "w");
    fwrite($handle, $_POST['event_id']);
    fclose($handle);
    $url = "index.php";
}
else{
    $url = "index.php?error=event_id_error&&event_id=" . $_POST['event_id'];
}

header( "Location: $url" );
?>

Optimus Prime Ribs
Jul 25, 2007

SlightlyMadman posted:

How quickly you forget! Clearly it's there to write out this config file:

Well I know what it's doing. I just don't know what purpose it serves.
Maybe the dude really badly wanted to assign an event id to the text file using POST data, and do literally nothing else.

Makes me wonder why he didn't just use a GET variable in the URL for the id.

Optimus Prime Ribs
Jul 25, 2007

Why not just respond with "It sure is" and then call it a day.

Optimus Prime Ribs
Jul 25, 2007

quote:

Sometimes you want to know both the value of a variable being passed to a function and its name.
Well I guess if you were doing something really esoteric, or just hacking...
php:
<?php
$theVarStem="emailName";

$theVarValue=eval("return \$$theVarStem;");
?> 
Wait. What are you doing...
php:
<?php
myFunction(compact("emailName"))

function myFunction($theInfo)
{
$theVarStem=key($theInfo);
$theVarValue=current($theInfo);
//...
}
?>
Why...? :psyduck:

Optimus Prime Ribs
Jul 25, 2007

OriginalPseudonym posted:

It boils down to people coding and not knowing what a key => value hash looks like.

These are probably the same people that will do something like this:

php:
<?
$myVar1 = 1;
$myVar2 = 2;
$myVar3 = 4; //;)
?>
Instead of using an array.
But I don't really want to think about coding like that.

e:

Boy do I wish I could look at the source code for my work's CMS.
One of our clients decided that they were going to write their own PHP/JavaScript for their pages and then give all that to us and we'd plug it into our system. It turns out if you escape a string when inserting into our SQL database it causes our reports to display incorrectly.
So whoever wrote that beast didn't bother with small things like preventing SQL injections.

Optimus Prime Ribs fucked around with this message at 23:06 on Oct 31, 2011

Optimus Prime Ribs
Jul 25, 2007

OriginalPseudonym posted:

Who uses PDO, anyways. Real PHP coders roll strings into mysql_query.

The PHP version on our server doesn't even support PDOs. :downs:

Optimus Prime Ribs
Jul 25, 2007

NotShadowStar posted:

Yep, you can still do that. mysql_* has an implicit, invisible connection if you don't specify a connection handler on mysql_connect. Ramsus Lerdorf, stealing a bunch of poo poo from Perl but didn't really understand what Perl was doing.

I have to wonder: is Ramsus just a gigantic meat-head or is PHP an elaborate troll?

Optimus Prime Ribs
Jul 25, 2007

Rasmus Lerdof posted:

I'm not a real programmer. I throw together things until it works then I move on. The real programmers will say "Yeah it works but you're leaking memory everywhere. Perhaps we should fix that." I’ll just restart Apache every 10 requests.

Did he seriously say this? :stare:

Optimus Prime Ribs
Jul 25, 2007

For better or worse.

Optimus Prime Ribs
Jul 25, 2007

code:
public float removeGreen(float color, int green) {
      return color;
   }
:psyduck:

Does this make as little sense as I think it does?

Optimus Prime Ribs
Jul 25, 2007

Well that certainly is something.

Optimus Prime Ribs
Jul 25, 2007

mjau posted:

Can you center vertically with that? "margin-top: auto; margin-bottom: auto;" doesn't seem to do anything.

The margin:0px auto trick only works for horizontal centering, and in my experience vertical centering can be a bitch.

The best way I've found to do it, where the containing element's height is not known, is: display:table-cell; vertical-align:middle;.
I feel dirty every time I use that though. :(

Optimus Prime Ribs
Jul 25, 2007

Hammerite posted:

Here's an entertaining one: Assigning values inside an array (yes I know that PHP + Stack Overflow is the lowest of low-hanging fruit).

I've never seen that goofy "more than one dollar sign" poo poo in PHP before, but just what the hell is it supposed to do?
Like, this makes no sense:

http://codepad.org/tMhOK1dO
http://codepad.org/3xDgPwrA
http://codepad.org/1IxeJDDO

:psyduck:

Optimus Prime Ribs
Jul 25, 2007

Look Around You posted:

Apparently they are "variable variables":

Ah, that makes sense. I just had the perfect storm of variable names for extra confusion.
Not surprising at all that this feature exists in PHP though.

Optimus Prime Ribs
Jul 25, 2007

Hammerite posted:

But on thinking about it, it is consistent with PHP's treatment of unknown bare words in other contexts, so I'm not sure why I was surprised.

Every time I learn a new horror regarding PHP I am amazed for a few seconds and then remember that it's PHP.

Optimus Prime Ribs
Jul 25, 2007

pigdog posted:

Correct me if I'm wrong (I never actually got around to learning C), but isn't the answer "either way you like"?

I've never heard "pass by value" be referred to as "pass by copy" before, but yes.
In C and C++ you could pass an int (for example) by value by doing void foo(int butts), or by reference by doing void bar(int& boobs).

You could even pass a pointer! void baz(int* ohgod) :toot:

Optimus Prime Ribs
Jul 25, 2007

Look Around You posted:

There's no references in C.

Oh derp. Well I'm not a C programmer, so there you go. :downs:

Optimus Prime Ribs
Jul 25, 2007

Right now my work has our servers hosted by absolutely incompetent morons. Case in point: over 3 weeks ago we requested to have an SQL database created for us, so that I can create some new tools to make my job easier. They're charging $500.00 for this, and so far haven't done anything.
Don't ask me why we're with them; I do not know.

Well, unsurprisingly, the PHP scripts that they wrote for us (these were written before I started working here) don't work very well.

I was having issues with one script that generates ASX meta-info so that Windows Media Player and Silverlight players can dynamically load streams. Of course said script is hosted on a part of the FTP that I do not have access to. Our server host has stated that we don't have access because they do not want us stealing their code.

Turns out that they didn't bother setting any CHMOD permissions, since I was able to use the PHP copy() function to copy the PHP scripts into the part of the FTP that I do have access, and what I found was a sight to behold.

This is what I had waiting for me: http://codepad.org/4rquhM3M

This is the code that they were afraid I was going to steal.

Seriously, who the gently caress thought this was a good idea:
php:
<?
$event_res = $db->Query(sprintf( $stmt, "/" . $gConfig['module']['data'], $event_id, $event_id, "/" . $gConfig['module']['data'],  
"/" . $gConfig['module']['data'], $event_id, $event_id, $event_id, $event_id, $event_id, $event_id, $event_id, $event_id, $event_id, $event_id, 
"/" . $gConfig['module']['data'], "/" . $gConfig['module']['data'], "/" . $gConfig['module']['data'], $event_id, $event_id ));?>
(modified for table breakage)

The ASX generating script that wasn't working is including like 4 other files.
I'm afraid to look at them. :ohdear:

Optimus Prime Ribs fucked around with this message at 18:23 on Feb 15, 2012

Optimus Prime Ribs
Jul 25, 2007

darthbob88 posted:

in a final product that would, he assures me, make us zillions of dollars if I just do the backend work for him.

He wanted you to work for free, and only compensate you after its success, didn't he?

Optimus Prime Ribs
Jul 25, 2007

yaoi prophet posted:

php is the worst loving language oh my god
code:
$ php
<?
echo 0x0 +2, "\n", 0x0 +3.5, "\n", 0x0 +2e1;
?>
code:
4
6.5
757

What version of PHP causes this?

I tried that here, and it works as it should:
http://ideone.com/OaHC4
http://codepad.org/HfFKOjed

Then I tried the it on my work's server (PHP 5.3.3, newer than Ideone's PHP 5.2.11), and it got the same, incorrect, 4/6.5/757 crap.

The hell is going on here? :psyduck:

Optimus Prime Ribs
Jul 25, 2007

Saw this posted on a different message board:
code:
if (_root.pic_1.hitTest(_root.hit_1) == true)
{
    if (_root.pic_2.hitTest(_root.hit_2) == true)
    {
        if (_root.pic_3.hitTest(_root.hit_3) == true)
        {
            if (_root.pic_4.hitTest(_root.hit_4) == true)
            {
                if (_root.pic_5.hitTest(_root.hit_5) == true)
                {
                    if (_root.pic_6.hitTest(_root.hit_6) == true)
   {
                        if (_root.pic_7.hitTest(_root.hit_7) == true)
                        {
                            if (_root.pic_8.hitTest(_root.hit_8) == true)
                            {
                                if (_root.pic_9.hitTest(_root.hit_9) == true)
                                {
                                    if (_root.pic_10.hitTest(_root.hit_10) == true)
                                    {
                                        if (_root.pic_11.hitTest(_root.hit_11) == true)
                                        {
                                            if (_root.pic_12.hitTest(_root.hit_12) == true)
                                            {
                                                if (_root.pic_13.hitTest(_root.hit_13) == true)
                                                {
                                                    if (_root.pic_14.hitTest(_root.hit_14) == true)
                                                    {
                                                        if (_root.pic_15.hitTest(_root.hit_15) == true)
                                                        {
                                                            if (_root.pic_16.hitTest(_root.hit_16) == true)
                                                            {
                                                                if (_root.pic_17.hitTest(_root.hit_17) == true)
                                                                {
                                                                    if (_root.pic_18.hitTest(_root.hit_18) == true)
                                                                    {
                                                                        if (_root.pic_19.hitTest(_root.hit_19) == true)
                                                                        {
                                                                            if (_root.pic_20.hitTest(_root.hit_20) == true)
                                                                            {
                                                                                if (_root.pic_21.hitTest(_root.hit_21) == true)
                                                                                {
                                                                                    if (_root.pic_22.hitTest(_root.hit_22) == true)
                                                                                    {
                                                                                        if (_root.pic_23.hitTest(_root.hit_23) == true)
                                                                                        {
                                                                                            if (_root.pic_24.hitTest(_root.hit_24) == true)
                                                                                            {
                                                                                                if (_root.pic_25.hitTest(_root.hit_25) == true)
                                                                                                {
                                                                                                    if (_root.pic_26.hitTest(_root.hit_26) == true)
                                                                                                    {
                                                                                                        if (_root.pic_27.hitTest(_root.hit_27) == true)
                                                                                                        {
                                                                                                            if (_root.pic_28.hitTest(_root.hit_28) == true)
                                                                                                            {
                                                                                                                if (_root.pic_29.hitTest(_root.hit_29) == true)
                                                                                                                {
                                                                                                                    if (_root.pic_30.hitTest(_root.hit_30) == true)
                                                                                                                    {
                                                                                                                        if (_root.pic_31.hitTest(_root.hit_31) == true)
                                                                                                                        {
                                                                                                                            if (_root.pic_32.hitTest(_root.hit_32) == true)
                                                                                                                            {
                                                                                                                                if (_root.pic_33.hitTest(_root.hit_33) == true)
                                                                                                                                {
                                                                                                                                    if (_root.pic_34.hitTest(_root.hit_34) == true)
                                                                                                                                    {
                                                                                                                                        if (_root.pic_35.hitTest(_root.hit_35) == true)
                                                                                                                                        {
                                                                                                                                            gotoAndStop(6);
                                                                                                                                        } // end if
                                                                                                                                    } // end if
                                                                                                                                } // end if
                                                                                                                            } // end if
                                                                                                                        } // end if
                                                                                                                    } // end if
                                                                                                                } // end if
                                                                                                            } // end if
                                                                                                        } // end if
                                                                                                    } // end if
I... :stare:

Optimus Prime Ribs
Jul 25, 2007

senrath posted:

Those comments make me wonder if it was auto-generated code.

I want to believe that a person didn't willingly type that out.
But I'm too cynical. :(

Optimus Prime Ribs
Jul 25, 2007

Strong Sauce posted:

Do you think those programmers ever wonder, "drat I wish there was an easier way to do this. If only there were some sort of thingy that can hold all these similar items!"

Funny thing is that in AS2 (which that is written in) the _root variable is essentially an array.
He could have written that like this:
code:
success = true;

for (i = 1; i < 36; i++)
{
	if (_root["pic_"+String(i)].hitTest(_root["hit_"+String(i)]) == false)
	{
		success = false;
		break;
	}
}

if (success)
{
	gotoAndStop(6);
}

Optimus Prime Ribs
Jul 25, 2007

Carthag posted:

^^^ I'd start with success = false though, much cleaner that way. ^^^

I definitely agree with that, but then the for loop would need something like this:
code:
if (_root["pic_"+String(i)].hitTest(_root["hit_"+String(i)]))
{
	success = true;
}
else
{
	success = false;
	break;
}
Which just seems silly to me.
Not that it matters since this is a coding horror no matter how you write it.

Optimus Prime Ribs
Jul 25, 2007

yaoi prophet posted:

I've never even touched PHP, what's the proper way to do this?

The only horror that I can see is that the input fields are being named field_1, field_2, field_3, field_4, et cetera.
Though doing this:
code:
echo "Field " . $i . "<input name='field_" . $i . "'> ";
Is really redundant since variables are automatically inserted into strings when double quotes are used:
code:
echo "Field $i<input name='field_$i'> ";
There's also no checking being done if the elements even exist in $_GET:
code:
if ($_GET['field_'.$i] == "BLAH")
In the end, as usual, the real horror is PHP.

Optimus Prime Ribs
Jul 25, 2007

AlsoD posted:

In one of my first year programming courses we lost marks if we didn't comment each of our closing braces. Needless to say I saw a lot of
code:
} // end block

Wonder what would have happened if you did this:
code:
} //this is a curly brace that is closing a block that I started at least one line above this one, because if I didn't this program wouldn't work and then I would get a zero. :(
Though speaking of stupid requirements in school, one of my professors said we were not allowed to do while(1) or while(true) when a constant loop was required.
We had to create a variable instead:
code:
bool someStupidBool = true;

while (someStupidBool)
{
    // bleh
}
And a different professor would take off marks if we didn't use curly braces with if statements that only had one line in them:
code:
if (someVariable)
    bool gonnaLoseMarks = true;

if (someOtherVariable)
{
    bool gonnaLoseMarks = false;
}
I do not miss college at all.

Optimus Prime Ribs
Jul 25, 2007

shrughes posted:

If you had to deal with all the stupid poo poo mistakes students would make, you'd have those rules too.

That is a fair argument, but I didn't like writing code a way that I wouldn't have normally without being given a reason as to why I should.

Optimus Prime Ribs
Jul 25, 2007

baquerd posted:

Come on, I bet you have at least one little thing that doesn't effect functionality that you greater prefer. Braces style? White space? Variable or function name convention?

I'd go as far to say that if you don't have something like that you're weird.

Everyone has their preferred way to write code.
But why should I be penalised for not conforming to the professor's preference?

Optimus Prime Ribs
Jul 25, 2007

feedmegin posted:

In the real world, whether open source or commercial, you'll generally be expected to conform to the existing style of any large body of code to which you contribute. Doing otherwise is aggressively antisocial. I suggest you get used to it.

Admittedly I had not thought of that perspective when I made my post, but I don't think my frustration over the situation is entirely unreasonable.
For what it's worth if I am writing code for a project that is not entirely my own I completely conform to the style of said project.

Optimus Prime Ribs
Jul 25, 2007

Strong Sauce posted:

The fact that it chugs on a x120e while seemingly not doing anything processor/graphic intensive is pretty frustrating.

I always found it pretty funny that Minecraft runs worse on my computer than Skyrim does.
Not sure how Notch pulled that one off, but he found a way.

Optimus Prime Ribs
Jul 25, 2007

As much as I hate having to work with PHP, I love learning about the dumb poo poo that it does.
It's the gift that keeps on giving. :3:

Optimus Prime Ribs
Jul 25, 2007

code:
thisLocation = "http://www.****.com/custom_events/****-20120209/site/";
function facebook () 
{
	var randomnumber=Math.floor(Math.random()*9999);
	window.open ("http://www.facebook.com/sharer.php?u=" + thisLocation );

}

function twitter () 
{
	mylink = thisLocation;	
	window.open ("http://twitter.com/home?status=Currently watching : " + mylink);

}
I'm not really sure what this person was thinking...

Optimus Prime Ribs
Jul 25, 2007

Well I got tasked with figuring out how code (which was written by a guy who doesn't work here anymore) works.
This is what some of it looks like (formatting preserved):

code:
var slide_contents = param.split("&&");
		
			
			
			if(slide_contents[0].indexOf('/photo/') > -1){

			 if( slide_contents[0].indexOf('.php') == -1 && slide_contents[0].indexOf('.swf') == -1){
				  window.parent.document.getElementById('photoContainer').innerHTML = "<img src='" + slide_contents[0] + "'>";
			 }
			 else{
				  window.parent.document.getElementById('photoContainer').innerHTML = "<iframe frameborder='0' scrolling='auto' width='400' height='300' name='slideframe' id='slideframe' src='" + slide_contents[0] + "' marginheight='0' marginwidth='0'></iframe>";
			 }
			}
      else{
				if( slide_contents[0].indexOf('.php') == -1 && slide_contents[0].indexOf('.swf') == -1){
				  window.parent.document.getElementById('slidesContainer').innerHTML = "<img src='" + slide_contents[0] + "'>";
				  document.getElementById('checkpoints_div').innerHTML = "<iframe src='update_checkpoints.php?url=" + slide_contents[0] + "' width='0' height='0'></iframe>";			   
        }
			 else{
				window.parent.document.getElementById('slidesContainer').innerHTML = "<iframe frameborder='0' scrolling='auto' width='600' height='450' name='slideframe' id='slideframe' src='" + slide_contents[0] + "' marginheight='0' marginwidth='0'></iframe>";
			 }
			}
And yep, this is all running in an iframe, modifying HTML elements in its parent window.

:smith:

Adbot
ADBOT LOVES YOU

Optimus Prime Ribs
Jul 25, 2007

Zombywuf posted:

idgi

What does the fact that the Derived has a Base as a private member have to do with operator overloading?

Maybe I'm missing something, but:

code:
...
operator Base&() { return _derived; }
...
bases.push_back(&static_cast<Base&>(wrapper));

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply