Dilbert





The Daily WTF

Error'd: The Parameter was NOT Set;

"Spotted this in front of a retro-looking record player in an Italian tech shop. I don't think anybody had any idea how to categorize it so they just left it up to the system," Marco D. writes.

 

George C. wrote, "Never thought it would come to this, but it looks like LinkedIn can't keep up with all of my connections!"

 

"Apparently opening a particular SharePoint link using anything else other than Internet Explorer made Excel absolutely lose its mind," wrote Arno P.

 

Dima R. writes, "OH! My bad, Edge, I only tried to access a file:// URL while I was offline."

 

"This display at the Vancouver airport doesn't have a lot of fans," Bruce R. wrote.

 

"Woo hoo! This is what I'm talking about! A septillion percentage gain!!" John G. writes.

 

[Advertisement] ProGet supports your applications, Docker containers, and third-party packages, allowing you to enforce quality standards across all components. Download and see how!


The Hardware Virus;

Dvi-cable

Jen was a few weeks into her new helpdesk job. Unlike past jobs, she started getting her own support tickets quickly—but a more veteran employee, Stanley, had been tasked with showing her the ropes. He also got notification of Jen's tickets, and they worked on them together. A new ticket had just come in, asking for someone to replace the DVI cable that'd gone missing from Conference Room 3. Such cables were the means by which coworkers connected their laptops to projectors for presentations.

Easy enough. Jen left her cube to head for the hardware "closet"—really, more of a room crammed full of cables, peripherals, and computer parts. On a dusty shelf in a remote corner, she spotted what she was looking for. The coiled cable was a bit grimy with age, but looked serviceable. She picked it up and headed to Stanley's cube, leaning against the threshold when she got there.

"That ticket that just came in? I found the cable they want. I'll go walk it down." Jen held it up and waggled it.

Stanley was seated, facing away from her at first. He swiveled to face her, eyed the cable, then went pale. "Where did you find that?"

"In the closet. What, is it—?"

"I thought they'd been purged." Stanley beckoned her forward. "Get in here!"

Jen inched deeper into the cube. As soon as he could reach it, Stanley snatched the cable out of her hand, threw it into the trash can sitting on the floor beside him, and dumped out his full mug of coffee on it for good measure.

"What the hell are you doing?" Jen blurted.

Stanley looked up at her desperately. "Have you used it already?"

"Uh, no?"

"Thank the gods!" He collapsed back in his swivel chair with relief, then feebly kicked at the trash can. The contents sloshed around inside, but the bin remained upright.

"What's this about?" Jen demanded. "What's wrong with the cable?"

Under the harsh office lighting, Stanley seemed to have aged thirty years. He motioned for Jen to take the empty chair across from his. Once she'd sat down, he continued nervously and quietly. "I don't know if you'll believe me. The powers-that-be would be angry if word were to spread. But, you've seen it. You very nearly fell victim to it. I must relate the tale, no matter how vile."

Jen frowned. "Of what?"

Stanley hesitated. "I need more coffee."

He picked up his mug and walked out, literally leaving Jen at the edge of her seat. She managed to sit back, but her mind was restless, wondering just what had her mentor so upset.

Eventually, Stanley returned with a fresh mug of coffee. Once he'd returned to his chair, he placed the mug on his desk and seemed to forget all about it. With clear reluctance, he focused on Jen. "I don't know where to start. The beginning, I suppose. It fell upon us from out of nowhere. Some say it's the spawn of a Sales meeting; others blame a code review gone horribly wrong. In the end, it matters little. It came alive and spread like fire, leaving destruction and chaos in its wake."

Jen's heart thumped with apprehension. "What? What came alive?"

Stanley's voice dropped to a whisper. "The hardware virus."

"Hardware virus?" Jen repeated, eyes wide.

Stanley glared. "You're going to tell me there's no such thing, but I tell you, I've seen it! The DVI cables ..."

He trailed off helplessly, reclining in his chair. When he straightened and resumed, his demeanor was calmer, but weary.

"At some godforsaken point in space and time, a single pin on one of our DVI cables was irrevocably bent. This was the source of the contagion," he explained. "Whenever the cable was plugged into a laptop, it cracked the plastic composing the laptop's DVI port, contorting it in a way that resisted all mortal attempt at repair. Any time another DVI cable was plugged into that laptop, its pin was bent in just the same way as with the original cable.

"That was how it spread. Cable infected laptop, laptop infected cable, all with vicious speed. There was no hope for the infected. We ... we were forced to round up and replace every single victim. I was knee-deep in the carnage, Jen. I see it in my nightmares. The waste, the despair, the endless reimaging!"

Stanley buried his head in his hands. It was a while before he raised his haunted gaze again. "I don't know how long it took, but it ran its course; the support tickets stopped coming in. Our superiors consider the matter resolved ... but I've never been able to let my guard down." He glanced warily at the trash can, then made eye contact with Jen. "Take no chances with any DVI cables you find within this building. Buy your own, and keep them with you at all times. If you see any more of those—" he pointed an accusing finger at the bin "—don't go near them, don't try taking a paperclip to them. There's everything to lose, and nothing to gain. Do you understand?"

Unable to manage words, Jen nodded instead.

"Good." The haunted expression vanished in favor of grim determination. Stanley stood, then rummaged through a desk drawer loaded with office supplies. He handed Jen a pair of scissors, and armed himself with a brassy letter opener.

"Our job now is to track down the missing cable that resulted in your support ticket," he continued. "If we're lucky, someone's absent-mindedly walked off with it. If we're not, we may find that this is step one in the virus' plan to re-invade. Off we go!"

Jen's mind reeled, but she sprang to her feet and followed Stanley out of the cubicle, telling herself to be ready for anything.

[Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!


Announcements: Meetup in Kansas City: Dinner and a Pint after KCDC;

The Kansas City Developer Conference is this week, followed by PubConf. Between these two events on Friday evening is plenty of time for a TDWTF dinner, and that's exactly what we're planning!

If you find yourself in Kansas City Missouri this Friday, for KCDC, PubConf, or perhaps because you live here, please come out to the Dubliner at 5:30 PM for dinner and a pint. I'll be there along with Martine Dowden and some TDWTF swag to give away. We'll talk software, discuss what we took away from the conference, and can head over to PubConf together.

If you would like to join us at 5:30 PM CT on Friday, July 19 please contact me at @mrdowden (Twitter) or drop me an email: Michael (at) Andromeda16.com

[Advertisement] Ensure your software is built only once and then deployed consistently across environments, by packaging your applications and components. Learn how today!


CodeSOD: Nothing Direct About directAddCartEntry;

It’s old hat, but every function, every class, every code unit you write, should all have a single, well-defined purpose. “Do one thing, and do it well,” as it were.

Of course, sometimes, it’s easier said that done, and mindlessly following that advice can lead to premature abstraction, and then you’ll have quite a mess on your hands. Still, it’s good advice, and a great design goal, even if you don’t head straight there.

Marigold found some code which, well, has a long way to go. A looooooong way to go.

directAddCartEntry = function (matnr, menge,updateByField,m,redu){
 
    var that=this;
    var produkt=new Object;
    var target = document.getElementById('content');
    spinner.spin(target);
   
    if (produkt.BACK_PREIS!=undefined && produkt.BACK_PREIS!=""){
        produkt.PREIS = produkt.BACK_PREIS  
    }  
    var Kundennummer = app.getModel("userData").getData().KUNDENNR;
    var Land  = app.getModel("userData").getData().LAND;       
    var Euland = app.getModel("userData").getData().ISTEULAND;
    var Kundennummer_u_Euland = Kundennummer+"|"+Euland+"|"+Land;
    var verpackungseinheit = "";
    sap.ui.getCore().byId("app").getModel("kategorie").read("/PRODUKT_SET(MATNR='"+matnr+"',VKORG='"+VKORG+"',SPRAS='de',KAMPAGNE='"+Kundennummer_u_Euland+"',VTWEG='10')?$expand=MERKMAL",null,null,false,function(oData,response){
        produkt=oData;     
        var mindestbestellmenge = produkt.BOMRABATT;
        verpackungseinheit =  produkt.VERPACKUNGSEINHEIT
        if (mindestbestellmenge!="0.000 "&& mindestbestellmenge!=""  &&  mindestbestellmenge != undefined){        
            mindestbestellmenge=mindestbestellmenge.split(".")[0]
            var mindestbestellmenge = parseInt(mindestbestellmenge);
            produkt.BOMRABATT=mindestbestellmenge          
            if (menge != mindestbestellmenge && vielfacher(menge,mindestbestellmenge)==false && redu!=true){
                var dialog = new sap.m.Dialog({
                    showHeader: false,
                    content: [
                        new sap.ui.layout.HorizontalLayout({
                            content: [
                                new sap.m.Image({
                                    src: "Image/helia_small.png",
                                }),
                                new sap.m.Text({
                                    //text: sap.ui.getCore().byId("app").getModel("i18n").getProperty("dialogUsersonlyFooter")
                                }).addStyleClass('dialog__usersonlySmall'),
                            ]
                        }).addStyleClass('dialog__usersonlyHeader'),
                   
                        new sap.ui.layout.Grid({
                            hSpacing: 1,
                            vSpacing: 1,
                            layoutData: new sap.ui.layout.GridData({
                                span: "L12 M12 S12",
                            }),
                            content: [
                                new sap.ui.core.HTML({ 
                                    layoutData: new sap.ui.layout.GridData({
                                        span: "L12 M12 S12",
                                    }),
                                    content: verpackungseinheit=="ZS" ? sap.ui.getCore().byId("navContainer").getModel("i18n").getProperty("infozigarette") : sap.ui.getCore().byId("navContainer").getModel("i18n").getResourceBundle().getText("infonormal", produkt.BOMRABATT)
                                }).addStyleClass("dialog__usersonlyTitle"),
                               
                                new sap.m.Select("dialogSelect",{
                                    layoutData: new sap.ui.layout.GridData({
                                        span: "L2 M2 S2",
                                    }),
//                                  items: productListItems2("zweier","","","")
                                    items: productListItems4(null,null,produkt.MAXMENGE,produkt.BOMRABATT)
                                })/*.attachBrowserEvent(
                    "click",function(evt){
                      var _numProductsSelected = parseInt( this.getSelectedKey() );
                      var _i  = +_numProductsSelected;
                      var plus=+_i;
                      this.destroyItems();
                      for (_i;_i<=999;_i=_i+plus){
                        // XXX
                        this.addItem(new sap.ui.core.ListItem({ text: _i,  key: _i }))                                  
                      }
                      this.setSelectedKey( _numProductsSelected );
                    }
                ).attachBrowserEvent(
                    "tap",function(evt){
                      var _numProductsSelected = parseInt( this.getSelectedKey() );
                      var _i  = +_numProductsSelected;
                      var plus=+_i;
                      this.destroyItems();
                      for (_i;_i<=999;_i=_i+plus){
                        // XXX
                        this.addItem(new sap.ui.core.ListItem({ text: _i,  key: _i }))                                  
                      }
                      this.setSelectedKey( _numProductsSelected );
                    }
                )*/,
                                new sap.m.Button({
                                    text: "OK",
                                    press: function(oEvent) {
                                        var new_menge=sap.ui.getCore().byId("dialogSelect").getSelectedItem().mProperties.text
                                        dialog.destroy();
                                        directAddCartEntry  (matnr, new_menge,updateByField,m)
                                        simulateOrder()
                                        directController.setPreiseundRabatte();                        
                                    },
                                    layoutData: new sap.ui.layout.GridData({
                                        span: "L1 M1 S1",
                                    })
                                }),                        
                               
                                new sap.m.Button({
                                    text: app.getModel("i18n").getProperty("pwdabort"),
                                    press: function() {
                                        dialog.destroy();
                                    },
                                    layoutData: new sap.ui.layout.GridData({
                                        span: "L2 M2 S2",
                                    })
                                }),
                            ]
                        }),
                        //.addStyleClass('dialog__usersonlyChoice'),
 
                   
                       
                    ]
                }).addStyleClass('dialog__usersonlyChoice');
                dialog.open()
                spinner.stop();
                return;
               
            }
            else{
              if (istmindestmenge (oData,"","call")==true && redu!=true){
//              var menge2=menge/2 
                var menge2=menge/oData.BOMRABATT;
                directAddCartEntry (matnr, menge2,updateByField,m,true)
                return
               
              }
              else{
                produkt.MENGE = menge;
              }
             
            }          
           
        }else{
          if (istmindestmenge (oData,"","call")==true && redu!=true){
//          var menge2=menge/2  
            menge/oData.BOMRABATT;
        directAddCartEntry (matnr, menge2,updateByField,m,true)
            return
      }
      else{
        produkt.MENGE = menge;
      }
        }          
        var Preis;
        var model = m;
        var data = model.getData();
        var POSITIONEN = data.WK_POSITIONEN;
        var POSITION = null;
        var POSITIONIndex = -1;
        if (produkt.BACK_PREIS!=undefined && produkt.BACK_PREIS!=""){
            produkt.PREIS = produkt.BACK_PREIS  
        }
        //Position suchen
        for (var zxy = 0 ; zxy < POSITIONEN.length ; zxy ++) {
            if (POSITIONEN[zxy].MATNR === produkt.MATNR) {
                POSITION = POSITIONEN[zxy];
                POSITIONIndex = zxy;
                break;
            }
        }
        //Wenn Position nicht gefunden, neu hinzuf?gen...
        if (POSITION === null) {
            produkt.PAKETPREIS = produkt.PREIS;
            produkt.SPARPREIS = 0;
           
            //Aktionsstaffelpreise und Staffelpreise ber?cksichtigen           
             var Preis = parseFloat(produkt.PREIS).toFixed(2);
 
             if (produkt.STAFFELPREIS3!=""){
                if( (parseFloat(produkt.MENGE) >= parseFloat(produkt.STAFFELPREIS6)) && ( parseFloat(produkt.STAFFELPREIS3) < parseFloat(produkt.PREIS) ) ) {
                    produkt.PAKETPREIS  = produkt.STAFFELPREIS3;
                    produkt.SPARPREIS = ( parseFloat(produkt.PREIS) - parseFloat(produkt.STAFFELPREIS3));
                    var Preis = produkt.STAFFELPREIS3
                }
            }
            if (produkt.AKTIONSPREIS3!=""){
                if( (parseFloat(produkt.MENGE) >= parseFloat(produkt.AKTIONSPREIS6)) && ( parseFloat(produkt.AKTIONSPREIS3) < parseFloat(produkt.PREIS) ) ) {
                    produkt.PAKETPREIS  = produkt.AKTIONSPREIS3;
                    produkt.SPARPREIS = ( parseFloat(produkt.PREIS) - parseFloat(produkt.AKTIONSPREIS3));
                    var Preis = produkt.AKTIONSPREIS3
                }              
            }
            if (parseFloat(produkt.AKTIONSPREIS)< parseFloat(produkt.PREIS) && produkt.AKTIONSPREIS!=""){
                 var Preis = parseFloat(produkt.AKTIONSPREIS).toFixed(2);              
            }           // Vergleich Staffelpreis zu Aktionspreis, VRU 21.06.2016
            if ( (parseFloat(produkt.MENGE) >= parseFloat(produkt.AKTIONSPREIS6)) && (parseFloat(produkt.AKTIONSPREIS3)<parseFloat(produkt.STAFFELPREIS3)) && produkt.AKTIONSPREIS3!=""){
                var Preis = parseFloat(produkt.AKTIONSPREIS3).toFixed(2);  
            }
           
//          if( (produkt.MENGE >= 6) && ( parseFloat(produkt.AKTIONSPREIS6) < parseFloat(produkt.PREIS) ) ) {
//              produkt.PAKETPREIS  = produkt.AKTIONSPREIS6;
//              produkt.SPARPREIS = ( parseFloat(produkt.PREIS) - parseFloat(produkt.AKTIONSPREIS6));
//          }
//          if( (produkt.MENGE >= 12) && ( parseFloat(produkt.AKTIONSPREIS12) < parseFloat(produkt.PREIS) ) ) {
//              produkt.PAKETPREIS  = produkt.AKTIONSPREIS12;
//              produkt.SPARPREIS = ( parseFloat(produkt.PREIS) - parseFloat(produkt.AKTIONSPREIS12));
//          }
            produkt.GESAMTPREIS = parseFloat(Preis * menge).toFixed(2);
//          produkt.GESAMTPREIS = parseFloat(produkt.PAKETPREIS * produkt.MENGE).toFixed(2);
            produkt.GESAMTSPARPREIS = produkt.SPARPREIS * produkt.MENGE;
       
            produkt.MENGE=parseInt(produkt.MENGE);
          if (redu==true){
//        produkt.MENGE=produkt.MENGE*2
        produkt.MENGE=produkt.MENGE*produkt.BOMRABATT
      }
            // create new entry
            POSITION = {
                    MATNR:produkt.MATNR,
                    MAKTX:produkt.MAKTX,
                    MENGE:produkt.MENGE,
                    MAXMENGE:produkt.MAXMENGE,
                    KATTEXTKURZ:produkt.KATTEXTKURZ,
                    IMG_BIG:produkt.IMG_BIG.replace(locStatic,""),
                    IMG_THUMB:produkt.IMG_THUMB.replace(locStatic,""),
                    BACK_PREIS: produkt.PREIS,
                    PREIS:Preis,
                    GESAMTPREIS:parseFloat(produkt.GESAMTPREIS).toFixed(2),
                    STAFFELPREIS:produkt.STAFFELPREIS,
                    AKTIONSPREIS:produkt.AKTIONSPREIS,
                    WAEHRUNG:produkt.WAEHRUNG,
                    PAKETPREIS:produkt.PAKETPREIS,
                    SPARPREIS:produkt.SPARPREIS,
                    GESAMTSPARPREIS:produkt.GESAMTSPARPREIS,
                    AKTIONSPREIS3 : produkt.AKTIONSPREIS3,
                    AKTIONSPREIS6 : produkt.AKTIONSPREIS6,     
                    STAFFELPREIS3 : produkt.STAFFELPREIS3,
                    STAFFELPREIS6 : produkt.STAFFELPREIS6,
                    BOMRABATT: produkt.BOMRABATT,
                    VERPACKUNGSEINHEIT:produkt.VERPACKUNGSEINHEIT
            };
            data.WK_POSITIONEN[data.WK_POSITIONEN.length] = POSITION;
        } else {
        //...Ansonsten Menge aendern
            if(updateByField){
                POSITION.MENGE=parseInt(POSITION.MENGE) + parseInt(produkt.MENGE)
                if (redu!=undefined && redu ==true){
                  POSITION.MENGE = POSITION.MENGE/2 + parseInt(produkt.MENGE)/2  
                }
                var Preis = parseFloat(produkt.PREIS).toFixed(2);              
                if (produkt.STAFFELPREIS3!=""){                    
                    if( (parseFloat(POSITION.MENGE) >= parseFloat(produkt.STAFFELPREIS6)) && ( parseFloat(produkt.STAFFELPREIS3) < parseFloat(produkt.PREIS) ) ) {
                        POSITION.PAKETPREIS = produkt.STAFFELPREIS3;
                        POSITION.SPARPREIS = ( parseFloat(produkt.PREIS) - parseFloat(produkt.STAFFELPREIS3));
                        var Preis = produkt.STAFFELPREIS3
                    }
                }
                if (produkt.AKTIONSPREIS3!=""){                
                    if( (parseFloat(POSITION.MENGE) >= parseFloat(produkt.AKTIONSPREIS6)) && ( parseFloat(produkt.AKTIONSPREIS3) < parseFloat(produkt.PREIS) ) ) {
                        POSITION.PAKETPREIS = produkt.AKTIONSPREIS3;
                        POSITION.SPARPREIS = ( parseFloat(produkt.PREIS) - parseFloat(produkt.AKTIONSPREIS3));
                        var Preis = produkt.AKTIONSPREIS3
                    }              
                }
                if (parseFloat(produkt.AKTIONSPREIS)< parseFloat(produkt.PREIS) && produkt.AKTIONSPREIS!=""){
                     var Preis = parseFloat(produkt.AKTIONSPREIS).toFixed(2);              
                }
                // Vergleich Staffelpreis zu Aktionspreis, VRU 21.06.2016
                if ( (parseFloat(POSITION.MENGE) >= parseFloat(produkt.AKTIONSPREIS6)) && (parseFloat(produkt.AKTIONSPREIS3)<parseFloat(produkt.STAFFELPREIS3)) && produkt.AKTIONSPREIS3!=""){
                    var Preis = parseFloat(produkt.AKTIONSPREIS3).toFixed(2);  
                }
                POSITION.AKTIONSPREIS3 = produkt.AKTIONSPREIS3
                POSITION.AKTIONSPREIS6 = produkt.AKTIONSPREIS6     
                POSITION.STAFFELPREIS3 = produkt.STAFFELPREIS3
                POSITION.STAFFELPREIS6 = produkt.STAFFELPREIS6             
                POSITION.BACK_PREIS= produkt.PREIS,            
                POSITION.PREIS = parseFloat(Preis).toFixed(2);
                POSITION.AKTIONSPREIS6 = produkt.AKTIONSPREIS6;
                POSITION.AKTIONSPREIS12 = produkt.AKTIONSPREIS12;
                POSITION.PAKETPREIS = POSITION.PREIS;
                POSITION.SPARPREIS = 0;
//              if( (POSITION.MENGE >= 6) && ( parseFloat(POSITION.AKTIONSPREIS6) < parseFloat(POSITION.PREIS) ) ) {
//                  POSITION.PAKETPREIS = POSITION.AKTIONSPREIS6;  
//                  POSITION.SPARPREIS = ( parseFloat(POSITION.PREIS) - parseFloat(POSITION.AKTIONSPREIS6));
//              }
//              if( (POSITION.MENGE >= 12) && ( parseFloat(POSITION.AKTIONSPREIS12) < parseFloat(POSITION.PREIS) ) ) {
//                  POSITION.PAKETPREIS = POSITION.AKTIONSPREIS12; 
//                  POSITION.SPARPREIS = ( parseFloat(POSITION.PREIS) - parseFloat(POSITION.AKTIONSPREIS12));
//              }
                POSITION.GESAMTPREIS = parseFloat(POSITION.MENGE*POSITION.PAKETPREIS).toFixed(2);
                POSITION.GESAMTSPARPREIS = POSITION.MENGE*POSITION.SPARPREIS;
                POSITION.STAFFELPREIS = produkt.STAFFELPREIS;
                POSITION.AKTIONSPREIS = produkt.AKTIONSPREIS;
                POSITION.WAEHRUNG = produkt.WAEHRUNG;
                if (redu!=undefined && redu ==true){
//          POSITION.MENGE = POSITION.MENGE*2  
          POSITION.MENGE = POSITION.MENGE*POSITION.BOMRABATT
        }
               
            }else{
            }
            POSITION.AKTIONSPREIS3 = produkt.AKTIONSPREIS3
            POSITION.AKTIONSPREIS6 = produkt.AKTIONSPREIS6     
            POSITION.STAFFELPREIS3 = produkt.STAFFELPREIS3
            POSITION.STAFFELPREIS6 = produkt.STAFFELPREIS6
            POSITION.BOMRABATT = produkt.BOMRABATT
           
            POSITION.BACK_PREIS= produkt.PREIS,
            POSITION.PREIS = Preis;
            POSITION.GESAMTPREIS= toFixed(POSITION.GESAMTPREIS,2);
            POSITION.GESAMTSPARPREIS= toFixed(POSITION.GESAMTSPARPREIS,2);
            POSITIONEN[POSITIONIndex] = POSITION;
            data.WK_POSITIONEN = POSITIONEN;
        }
        // Gesamtpreis neu berechnen
        data.GESAMTPREIS = 0;
        data.GESAMTMENGE = 0;
        data.ZWISCHENSUMME = 0;
        data.GESAMTSPARPREIS = 0;      
        for (var xxy = 0 ; xxy < data.WK_POSITIONEN.length ; xxy ++) {
            data.GESAMTPREIS += parseFloat(data.WK_POSITIONEN[xxy].GESAMTPREIS);
            if (istmindestmenge (data.WK_POSITIONEN[xxy],"","call")==true && redu==true){
              data.GESAMTMENGE += parseInt(data.WK_POSITIONEN[xxy].MENGE);
            }else{
               data.GESAMTMENGE += parseInt(data.WK_POSITIONEN[xxy].MENGE);
            }
            //hier Gesamtmenge wieder erhoehen
           
           
            data.ZWISCHENSUMME += parseFloat(data.WK_POSITIONEN[xxy].GESAMTPREIS);
            data.GESAMTSPARPREIS += parseFloat(data.WK_POSITIONEN[xxy].GESAMTSPARPREIS);           
        }
        data.GESAMTPREIS = parseFloat(data.GESAMTPREIS).toFixed(2)
        data.GESAMTSPARPREIS = parseFloat(data.GESAMTSPARPREIS).toFixed(2);
//      data.INTERNETRABATT = parseFloat(menge) + parseFloat(menge)
//      data.GESAMTPREIS= parseFloat(data.GESAMTPREIS).toFixed(2);
        data.ENDPREIS=parseFloat(data.GESAMTPREIS).toFixed(2) - parseFloat(data.INTERNETRABATT).toFixed(2);
        data.ZWISCHENSUMME= toFixed(data.ZWISCHENSUMME,2);
        data.GESAMTSPARPREIS= toFixed(data.GESAMTSPARPREIS,2);
        data.ERSATZLIEFERUNG = data.ERSATZLIEFERUNG;
        data.LIEFERART=data.LIEFERART;
        data.LIEFERDATUM = data.LIEFERDATUM;
        data.KUNDENNACHRICHT=data.KUNDENNACHRICHT;
//      if(parseFloat(oData.INTERNETRABATT)>0){
//          //sap.ui.getCore().byId("app").getModel("warenkorb").setProperty("/INTERNETRABATT",parseFloat(oData.INTERNETRABATT).toFixed(2));
//          sap.ui.getCore().byId("app").getModel("warenkorb").setProperty("/ENDPREIS",(parseFloat(sap.ui.getCore().byId("app").getModel("warenkorb").getProperty("/GESAMTPREIS")) - parseFloat(oData.INTERNETRABATT)).toFixed(2));
//      }
//      // Model updaten
        model.setData(data,"warenkorb");
       
        if($.cookie("cookieUser")!=undefined){
            setBackendWK(sap.ui.getCore().byId("app").getModel("kategorie"),sap.ui.getCore().byId("app").getModel("userData").oData.KUNDENNR);
        }else{
            setCookieCart(model);
        }
        if (redu==true){
//        menge=menge*2;
          menge=menge*produkt.BOMRABATT;
        }
        showToastMessage(menge,produkt.MAKTX,produkt.MERKMAL.results);
        //Speichern des Warenkorbes in einen Cookie
        simulateOrder();
        spinner.stop();
    },function(oError){
        spinner.stop();
        messageToast(app.getModel("i18n").getProperty("keineWare"));
    });
};

Marigold adds: “I have no words for this. Make something up. I don’t care.”

It isn’t about what this code does, as much as the sheer mass of it, the weight of 350+ lines of code in one gigantic method which seems to do everything, makes me want to do nothing but eat a box of “einen Cookies” in one sitting.

[Advertisement] Ensure your software is built only once and then deployed consistently across environments, by packaging your applications and components. Learn how today!


CodeSOD: Brütäl Glöbs;

Noam and a few friends decided it was time for them to launch their own product. They were young, optimistic about their career, and had some opinions about the best way to handle some basic network monitoring and scanning tasks. So they iterated on the idea a few times, until one day the program just started hanging. At first, Noam thought it was just a hang, but after walking away from the machine for a few minutes in frustration, he discovered that it was just running really slow.

After a little investigation, he tracked down the problem to the function responsible for checking if an IP matched a filter. That filter could contain globs, which made things a bit tricky, but his partner had some ideas about how best to handle them.

def ip_check(ip, rule):
    ret_value = False # Return Value
    if ip == rule['host']: # Compare against rule
        ret_value = True
    elif '*' in rule['host']: # Handle wildcards
        mask = rule['host'].split('.')
        length = mask.count('*')
        final = []
        for subset in itertools.permutations(range(256), length):
            final.append(list(subset))
        for item in final:
            address = rule['host'].split('.')
            for index in range(length):
                address[address.index('*')] = str(item[index])
            address = '.'.join(address)
            if address == ip:
                ret_value = True
    return ret_value

This code takes a long way around.

We start with for subset in itertools.permutations(range(256), length):. itertools.permutations does exactly what you think- in this case, it creates every possible permutation of the numbers in the range 0–255, taken length at a time- where length is the number of wildcards. So, for example, 10.1.*.*, is a mere 65,280 entries. *.*.*.*, which is what Noam was doing when testing, is a lot more. 4,195,023,360 entries, to be exact.

Then we iterate across every possible combination to put them into the final list. The permutations method is smart, it lazily evaluates the permutations, calculating the next one when you need it. As you can see, Python does allow you to iterate across it. So we don’t need the final variable at all, we could have simply done for item in itertols.permutations(…) and that would have been fine. Well, not fine, none of this is fine.

So, we populate a list with every possible permutation, then we iterate across every permutation. We incorrectly slam the permuted values into the test string, and if that test string matches our IP, we set the ret_value to True. And then we keep looping. This block doesn’t even take the simplest optimization of simply quitting when it finds what it’s looking for.

Noam rewrote this function, replacing it with a much simpler 3-line function using built-in methods. Then Noam went on to have a long conversation with his team about how something like this happened.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!


The Enterprise Backup Batch;

If a piece of software is described in any way, shape or form as being "enterprise", it's a safe bet that you don't actually want to use it. As a general rule, "enterprise" software packages mix the Inner-Platform Effect with trying to be all things to all customers, with thousands upon thousands of lines of legacy code that can't be touched because at least one customer depends on those quirks. There doesn't tend to be much competition in the "enterprise" space, so none of the vendors actually put any thought into making their products good. That's what salesbeasts and lawyers are for.

Kristoph M supports a deployment of Initech's data warehouse system. Since this system is a mix of stored procedures and SSIS packages, Kristoph can actually read a good portion of the code which makes the product work. They just choose not to. And that's usually a good choice.

But one day, while debugging, Kristoph decided that they needed a simple answer to a simple question: "For a SQLAgent Job, how do you create a backup of the database with the day appended to the filename?"

SQLAgent is SQL Server's scheduling system, used for triggering tasks. SSIS is SQL Server's "drag and drop" dataflow tool, designed to let users draw data pipelines to handle extract-transform-load tasks.

In this case, the SQLAgent job's first step was to launch an SSIS package. Already, we're in questionable territory. SSIS is, as stated, an ETL tool. Yes, you can use it to extract data, it's not really meant as a replacement for an actual database backup.

The good news is that this SSIS package doesn't actually do anything to backup the database. Instead, it contains a single task, and it isn't a data flow task, it's a "Visual Basic Script Task". Yes, SSIS lets you run a stripped down Visual Basic dialect in its context. What does this task do?

Public Sub Main() ' ' Add your code here ' Dim sToday As Date = Now Dim sDay As String = sToday.Day.ToString If CInt(sDay) < 10 Then sDay = "0" & sDay Dim sMonth As String = MonthName(Month(sToday), True) Dim sYear As String = Year(sToday).ToString Dim sPara1 As String = sDay '& sMonth & sYear Dim sPath As String = "D:\Initech\DailyProcess\" Using fso As StreamWriter = New StreamWriter(sPath & "runBackupBatch.bat") fso.WriteLine(sPath & "DailyExtractBackup.bat " & sPara1) fso.Close() End Using Dts.TaskResult = ScriptResults.Success End Sub

This figures out the current day, and then writes out a runBackupBatch.bat file with contents like this:

D:\Initech\DailyProcess\DailyExtractBackup.bat 02

Once that step is completed, the SQLAgent job continues, and runs the runBackupBatch.bat, which in turn runs DailyExtractBackup.bat, which does this:

D:\Initech\DailyProcess\DailyExtractBackup.bat @echo off @echo Dumping DailyExtract database... osql -E -Slocalhost -oD:\Initech\DailyProcess\DailyExtractDump.log -Q"backup database DailyExtract to DISK='D:\Initech\MSSQL\Backup\DailyExtractDump%1.bak' with INIT" if errorlevel 1 goto dumperror REM Check for SQL Errors findstr "Msg" D:\Initech\DailyProcess\DailyExtractDump.log if not errorlevel 1 goto dumperror :OK @echo All Done!! exit 0 :dumperror @echo Error dumping database. exit 1

The osql call is about the first reasonable step in this process. That actually does the backup using SQL server's backup tools. Then again, the mechanism to see if there were any errors in the logfile is troubling. findstr sets the errorlevel to 1 if Msg is not found in the log file. So, if Msg is not not found in the logfile, we'll go to dumperror.

After reading through this process, Kristoph decide it was best to take a step outside, get some air, and stop thinking about the other horrible things that might be lurking in Initech's data warehouse product.

[Advertisement] Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps - Think Raygun! Installs in minutes. Learn more.


Error'd: Errors Don't Always Ad up;

"You know, I'm thinking that The guys working on AT&T's DIRECTV service must have not done well with fractions in school," Andrew T. writes.

 

"Come on, DNS Exit, you shouldn't objectify your users!" writes Lance G.

 

Tom G. wrote, "I guess if I wanted my actual name to appear here I should have signed in with my Microsoft account and not my 20 year old Skype account."

 

Michael P. wrote, "Tripp Lite's site is pretty smart to detect a mismatched password before I've even registered on their site!"

 

"I was using my Ubuntu laptop, when my app crashed," writes Will B., "I didn't realize that my OS needed to crash my app whenever it was ready."

 

"Well, it looks like I'm about to enter the Matrix. So, do I click the gray pill or the white pill?" writes Jim S.

 

[Advertisement] Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps - Think Raygun! Installs in minutes. Learn more.