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
double sulk
Jul 2, 2010

Deus Rex posted:

http://peej.github.com/tonic/

Annotate routes and method conditions in comments!

PHP code:
<?php
  
/**
 * @uri /hello
 * @uri /hello/:name
 */
class Hello extends Tonic\Resource {

    /**
     * @method GET
     * @provides text/html
     */
    function sayHello($name = 'World') {
        return 'Hello '.$name;
    }
}

Adbot
ADBOT LOVES YOU

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance

Deus Rex posted:

http://peej.github.com/tonic/

Annotate routes and method conditions in comments!

PHP code:
<?php
  
/**
 * @uri /hello
 * @uri /hello/:name
 */
class Hello extends Tonic\Resource {

    /**
     * @method GET
     * @provides text/html
     */
    function sayHello($name = 'World') {
        return 'Hello '.$name;
    }
}

What's wrong with this? Looks like a JAX-RS clone for PHP. It's unfortunate that the annotations have to be inside a comment but I'm guessing that has more to do with PHP sucking than anything else.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Stuffing things in comments is not a terribly uncommon way to extend languages, since it doesn't break all the other tools for the language and is usually easier to implement. The end result nearly always is terrible, though.

nielsm
Jun 1, 2009



Plorkyeran posted:

Stuffing things in comments is not a terribly uncommon way to extend languages, since it doesn't break all the other tools for the language and is usually easier to implement. The end result nearly always is terrible, though.

I would probably have gone with only overloading shell-style # comments to at least make it reminiscent of C pre-processor.
But really, putting anything semantic into comments is retarded. (Now I think about it, Wordpress uses magical comments to identify plugins too. Sigh.)

Optimus Prime Ribs
Jul 25, 2007


I like how in the description the word RESTful links to a non-responding webpage.
And I really wanted to learn what RESTful meant too. :(

The Gripper
Sep 14, 2004
i am winner

Optimus Prime Ribs posted:

I like how in the description the word RESTful links to a non-responding webpage.
And I really wanted to learn what RESTful meant too. :(
RESTful just means your website can have a rest every once in a while.

Deus Rex
Mar 5, 2005

nielsm posted:

I would probably have gone with only overloading shell-style # comments to at least make it reminiscent of C pre-processor.
But really, putting anything semantic into comments is retarded. (Now I think about it, Wordpress uses magical comments to identify plugins too. Sigh.)

I'm ok with comment annotations for generating documentation or even for tests but using comments as a demented metaprogramming construct to generate your application is nasty as hell.

Progressive JPEG
Feb 19, 2003

code:
bool result;
(x == 2) ? result = true : result = false;
return result;
This was in a job candidate's code submission.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

The Gripper posted:

RESTful just means your website can have a rest every once in a while.

I was about to say, how much more restful can you get?

Room Temperature
Oct 16, 2007

mildly amusing

Progressive JPEG posted:

code:
bool result;
(x == 2) ? result = true : result = false;
return result;
This was in a job candidate's code submission.

Hmm, yeah, I see the problem.

code:
bool lt = false, is = false, smaller = true;
bool tmp = (x < 2) ? lt = true : (x > 2) ? smaller = false : is = true;
if (lt != false) {
   return !smaller;
}
if (!tmp) {
   return smaller && true;
}
if (is == true) {
    return tmp;
}
return false;
Much better.

Optimus Prime Ribs
Jul 25, 2007

edit: I'm an idiot

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Deus Rex posted:

http://peej.github.com/tonic/

Annotate routes and method conditions in comments!

PHP code:
<?php
  
/**
 * @uri /hello
 * @uri /hello/:name
 */
class Hello extends Tonic\Resource {

    /**
     * @method GET
     * @provides text/html
     */
    function sayHello($name = 'World') {
        return 'Hello '.$name;
    }
}

This is a standard thing called "Underwater Aspect Weaving"

http://net.tutsplus.com/tutorials/php/aspect-oriented-programming-in-php/

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Still hard to get over a loving backslash being used for namespaces :laugh:

Frozen Peach
Aug 25, 2004

garbage man from a garbage can
Here's a double horror for you. One of which is mine, and one of which is 10 years before I started here when the company was transitioning from their mainframe/COBOL to MSSQL2000 and VB6.

code:
SELECT CAST(price AS INT(10,0)) * 0.01 as price FROM products
The ancient horror? Our product DB is all CHAR(X) fields, because rather than redesign the database structure with support for actual data types, they kept everything in the char only, byte length required format that all the old mainframe/COBOL apps used. This way, they could literally SELECT * FROM TABLE and get a byte-for-byte identical entry as the old mainframe would spit out. This means things like prices are stored as "1899" instead of "18.99"

Thankfully that is changing soon.

My horror is the "CAST(price AS INT(10,0)) * 0.01 as price" part

Apparently 3 years ago when I wrote this, I really wanted that INT to be 10 digits long with no decimal places. :downs: Also the fact that this ran on SQL2000 without complaint is a pretty hilarious horror. It's throwing errors in 2008, which is why I caught it.

Zamujasa
Oct 27, 2010



Bread Liar

Frozen-Solid posted:

My horror is the "CAST(price AS INT(10,0)) * 0.01 as price" part

Apparently 3 years ago when I wrote this, I really wanted that INT to be 10 digits long with no decimal places. :downs: Also the fact that this ran on SQL2000 without complaint is a pretty hilarious horror. It's throwing errors in 2008, which is why I caught it.

Using integers for monetary values isn't always a horror, especially if you can't be sure your system won't mangle floating points. :)

raminasi
Jan 25, 2005

a last drink with no ice
Not using integers for monetary values is more often a horror.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat
PHP code:
$is_image = array('gif','jpg','tif','tiff','jp2');
$is_basic_image = array('gif','jpg');
$is_popup = array('slideshow.php','compare.php','clip.php','clipped.php','page_text.php','side_side.php','cliparticle.php','subset.php');
$login = false;
$protocol = ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == 'on'))?"https":"http";
$url = $protocol."://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.@$_SERVER['QUERY_STRING'];
$u = parse_url($url);
$thisfile = ltrim(strtok(strrchr($u['path'],'/'), '?'),'/');
$self = $_SERVER["PHP_SELF"];
$querystr = (isset($_SERVER['QUERY_STRING']))?$_SERVER['QUERY_STRING']:'';

if((strpos(urldecode($url),"<") !== false) || (strpos(urldecode($url),"..") !== false)){
header("Location: {$protocol}://{$_SERVER['HTTP_HOST']}");
exit();
}

$args = explode("&",$querystr);
        foreach($args as $q){
        $v = explode("=",urldecode($q));
                if((!empty($v[2])) && (strpos($v[0],"PARAMBOX") === false) && (strpos($v[0],"PARAMPARM") === false)){
                header("Location: {$protocol}://{$_SERVER['HTTP_HOST']}");
                exit();
                } elseif((!empty($v[1])) && ($v[0] == "PARAMPTR") && (!is_numeric($v[1]))){
                header("Location: {$protocol}://{$_SERVER['HTTP_HOST']}");
                exit();         
                }
        }

$foo_dir = (isset($extPath))?"/foo/":($protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'] == $protocol.'://'.$_SERVER['HTTP_HOST'].'/index.php')?"/foo/":"";
$foo_diag = (dirname($_SERVER['PHP_SELF']) != 'foo-debug')?'/index.php':'#';

$bchars = array('?^?^?','?^?^?','?^?^?','â?^¬','«','»',' ');
$gchars = array('"','"','\'','','','','&nbsp;');

Novo fucked around with this message at 02:28 on Feb 2, 2013

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



trace.log posted:

---------------------------------------------------------------------------------------------------------
2/1/2013 9:29:14 PM (UTC): Important Process Failed, see trace.log for details
2/1/2013 9:29:14 PM (UTC): Completed Important Process
---------------------------------------------------------------------------------------------------------

sigh

What happened to the emote of the little guy chucking the book over his shoulder because that seems just about perfect for this.

Zamujasa
Oct 27, 2010



Bread Liar

Munkeymon posted:

sigh

What happened to the emote of the little guy chucking the book over his shoulder because that seems just about perfect for this.

:dawkins101:

Novo posted:

This software costs more than I make in a year.

Is that manually parsing the query string, too? :psypop:

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
It identifies jp2 files as images, but not pngs? :stare:

Edit: A quick google search reveals what the software is, and holy crap, does it poo poo gold or something because I'm not understanding the pricetag.

Golbez fucked around with this message at 23:17 on Feb 1, 2013

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.




I swear that wasn't there when I looked. Must just be too much moving poo poo.

quote:

Is that manually parsing the query string, too? :psypop:

They have to justify the price tag somehow :v:

nielsm
Jun 1, 2009



Novo posted:

This software costs more than I make in a year.

Does it pay your wage?

SwimNurd
Oct 28, 2007

mememememe

Novo posted:

This software costs more than I make in a year.

gently caress CONTENTDM. Goddamn do I hate that product so much. Every product the OCLC ships is a horror.

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat
Thankfully supporting CONTENTdm is only a small part of my job, and we are going to be phasing it out. Here is another gem:

PHP code:
switch($this_file){     
    case "browse.php":
    case "results.php":
    case "results_TEMPLATE.php":
        include(CLIENT_PATH."BAR_results.php");
        require(SCRIPT_PATH."FOOSystem.php");
        require(SCRIPT_PATH."FOOImage.php");
    break;
    case "preferences.php":
        include(CLIENT_PATH."BAR_preferences.php");
        require(SCRIPT_PATH."FOOSystem.php");
    break;   
    case "viewer.php":
    case "doc_view.php":    
    case "pdf_view.php": 
    case "subset_view.php": 
    case "subset.php":
    case "subset_obj.php":       
    case "pdftext_view.php":
    case "item_view.php":
    case "item_view_TEMPLATE.php":
         case "thumb_view.php":    
         case "toolbar.php":    
        include(CLIENT_PATH."BAR_view.php");
        require(SCRIPT_PATH."FOOSystem.php");
        require(SCRIPT_PATH."FOOImage.php");
    break;
    case "fav_meta_view.php":
    case "clip.php":
         case "clipped.php":        
    case "cliparticle.php":
        include(CLIENT_PATH."BAR_view.php");
        require(SCRIPT_PATH."FOOSystem.php");
        require(SCRIPT_PATH."FOOImage.php");

That's only about half of the switch statement; it goes on and on like that and it's always the same three files being included/required. SwimNurd knows my pain. Literally every line in this thing is a horror.

Zamujasa posted:

:dawkins101:


Is that manually parsing the query string, too? :psypop:


PHP code:
function strip_url_var($u,$a){
$p = strpos($u,"$a=");
    if($p){
        if($u[$p-1] == "&"){
        $p--;
        }
    $ep = strpos($u,"&",$p+1);
        if ($ep === false){
        $u = substr($u,0,$p);
        } else {
        $u = str_replace(substr($u,$p,$ep-$p),'',$u);
        }
    }
return $u;
}

Novo fucked around with this message at 02:23 on Feb 2, 2013

Shy
Mar 20, 2010

GrumpyDoctor posted:

Not using integers for monetary values is more often a horror.

I thought SQL Server has monetary types, are they worse?

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer
So I found a gem in some intern Javascript we dusted off:

code:
function processAPIResponse( someData ) {
	for( i = 0; i < number; i++ )
	{
		vat item = someData[i]
		...
	}
So first of all, lets address "number", which is a variable representing how many items they're going to try to request from the API. This number is arbitrarily set to 10,000 despite the fact that the server is never going to return that many items. Now, rather than getting the actual number of items returned, we're just going let the out of range exception take care of exiting the loop!

If you're astute, you'll also notice that i wasn't declared in the function, so it has global scope. They noticed it too, apparently, and solved it like so:

code:
function processAPIResponse( someData ) {
	for( i = 0; i < number; i++ )
	{
		vat item = someData[i]
		...
	}
}
function processAPIResponsePart( someData ) {
	for( j = 0; j < 20; j++ )
	{
		vat item = someData[j]
		...
	}
}
They got all the way up to L... Which means, though what I'm sure was some awesome trial and error, they realized that looping with i in function A affects sub-function B, but rather than asking about how scope worked..they just worked around it. The 20 is also another arbitrary count based on what I'm guessing was the maximum length they ever came across, plus about 5 to be safe. It's like they discovered all the stuff about Javascript and took away entirely the wrong lesson every time.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Suspicious Dish posted:

This is a standard thing called "Underwater Aspect Weaving"

That does not sound like a merit badge I'm interested in getting.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Golbez posted:

It identifies jp2 files as images, but not pngs? :stare:

Edit: A quick google search reveals what the software is, and holy crap, does it poo poo gold or something because I'm not understanding the pricetag.

I'm not surprised it's poo poo at that price. They're nearly giving it away.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
Oh God, there are others like me out there? CONTENTdm has been ruining my life for going on six years now. I believe I've shared select bits of code from it in this thread before.

We're currently making an in-house front end for it. Actually just me. Nobody else will get involved, I've been perhaps too transparent with my impressions of it.

Thel
Apr 28, 2010

Shy posted:

I thought SQL Server has monetary types, are they worse?

Has issues with accuracy: http://stackoverflow.com/questions/582797/should-you-choose-the-money-or-decimalx-y-datatypes-in-sql-server (contrived example, yes, but it can be a massive headache)

Performance isn't great: http://sqlblog.com/blogs/aaron_bertrand/archive/2008/04/27/performance-storage-comparisons-money-vs-decimal.aspx

Plus, precision is fixed at 4 digits (after the decimal point). Normally that's sufficient, but sometimes it will bite you in the rear end. You're better off just using DECIMAL(x,y) and making sure you choose non-retarded values of x and y. Also more portable too. (DECIMAL is ANSI-standard, MONEY is SQL Server specific.)

raminasi
Jan 25, 2005

a last drink with no ice

Shy posted:

I thought SQL Server has monetary types, are they worse?

I don't know anything about SQL server but I suppose I should have said "using floating-point types."

Shy
Mar 20, 2010

Informative, thanks guys.

Scaevolus
Apr 16, 2007

Deus Rex posted:

http://peej.github.com/tonic/

Annotate routes and method conditions in comments!

PHP code:
<?php
  
/**
 * @uri /hello
 * @uri /hello/:name
 */
class Hello extends Tonic\Resource {

I did something like this for annotating functions as plugins for my IRC bot, then I remembered that Python has decorators.

Scaevolus fucked around with this message at 05:29 on Feb 2, 2013

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
php:
<?
        while (!feof($configFile)) {
            $s = fgets($configFile, 512);
            $s = str_replace("\r", "", $s);
            $s = str_replace("\n", "", $s);

            if (strlen($s) > 0) {
                if (substr($s, 0, 1) != "#") {
                    if (substr($s, 0, 17) == "EnableImageViewer") {
                           $temp = TrimValue($s, 18);
                        if (strcasecmp($temp, "Yes") == 0) {
                            $enabled = 1;
                           }
                    } elseif (substr($s, 0, 16) == "MinJPEGDimension") {
                           $minjpegdim = TrimValue($s, 17);
                    } elseif (substr($s, 0, 20) == "MaxDerivedImageWidth") {
                           $maxderivedimg["width"] = TrimValue($s, 21);
                    } elseif (substr($s, 0, 21) == "MaxDerivedImageHeight") {
                           $maxderivedimg["height"] = TrimValue($s, 22);
                    } elseif (substr($s, 0, 10) == "ZoomLevels") {
                           $temp = TrimValue($s, 11);
                           $temp = $temp . " ";
                           $len = strlen($temp);
                           $start = 0;
                           $n = 0;
                        while ($start < $len) { /* parse out the zoom levels */
                            $p = strpos($temp, " ", $start);
                            if ($p > 0) {
                                   $val = substr($temp, $start, $p - $start);
                                if (strlen($val) > 0) {
                                    $zoomlevels[$n] = $val;
                                    $n++;
                                   }
                            } else {
                                break;
                            }
                            $start = $p + 1;
                           }
                    } elseif (substr($s, 0, 11) == "ViewerWidth") {
?>
... it goes on and on, but you might wonder what TrimValue() is:
php:
<?
/* Strip off leading and trailing whitespace and trailing comment */

function TrimValue($s, $i) {
    $temp = trim(substr($s, $i));
    $p = strpos($temp, ";");
    if ($p > 0) {
        $temp = trim(substr($temp, 0, $p - 1));
    }
    return($temp);
}
?>
More quality code brought to you by the OCLC.

Frozen Peach
Aug 25, 2004

garbage man from a garbage can

Zamujasa posted:

Using integers for monetary values isn't always a horror, especially if you can't be sure your system won't mangle floating points. :)

We aren't using an int. We're using a char(5), that I then have to cast to an int.

nielsm
Jun 1, 2009



Frozen-Solid posted:

We aren't using an int. We're using a char(5), that I then have to cast to an int.

Char(5)? So you don't support amounts larger than $999.99 ?

Frozen Peach
Aug 25, 2004

garbage man from a garbage can

nielsm posted:

Char(5)? So you don't support amounts larger than $999.99 ?

Correct. But we also don't sell products that expensive.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
So this may or may not count as a horror:

http://openradar.appspot.com/13128709

checkDataDetectors routes any file:// uris (regardless of case) to DDResultCopyExtractedURL.
DDResultCopyExtractedURL asserts that the string it gets starts with the exact characters "file://".


At the very least, someone needs to write more comprehensive unit tests.

pigdog
Apr 23, 2004

by Smythe

Frozen-Solid posted:

Correct. But we also don't sell products that expensive.

:psyduck: What could possibly go wrong with a presumption like that?

Adbot
ADBOT LOVES YOU

kitten smoothie
Dec 29, 2001

pigdog posted:

:psyduck: What could possibly go wrong with a presumption like that?

"Everything's A Dollar" store acquired by "Everything's A Grand," database conversion claims six lives

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