Click here to Skip to main content
15,887,350 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: code for browser Pin
Jeroen De Dauw2-Jun-11 10:02
Jeroen De Dauw2-Jun-11 10:02 
GeneralRe: code for browser Pin
walterhevedeich2-Jun-11 14:23
professionalwalterhevedeich2-Jun-11 14:23 
GeneralRe: code for browser Pin
fjdiewornncalwe4-Jun-11 7:11
professionalfjdiewornncalwe4-Jun-11 7:11 
GeneralRe: code for browser Pin
DerekT-P8-Jun-11 4:57
professionalDerekT-P8-Jun-11 4:57 
GeneralRe: code for browser Pin
Mel Pama8-Jun-11 20:17
professionalMel Pama8-Jun-11 20:17 
GeneralRe: code for browser Pin
Anuj Tripathi15-Jun-11 20:59
Anuj Tripathi15-Jun-11 20:59 
Generaltry to throw and catch. PinPopular
Kim Togo31-May-11 23:38
professionalKim Togo31-May-11 23:38 
GeneralLooks like a database call obsession to me… Pin
saxenaabhi631-May-11 15:18
saxenaabhi631-May-11 15:18 
C#
protected void LiveList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      HiddenField username = (HiddenField)e.Item.FindControl("hidden_username");
      Image mapbtn = (Image)e.Item.FindControl("mapbtn");
      System.Web.UI.HtmlControls.HtmlTableRow tr = (System.Web.UI.HtmlControls.HtmlTableRow)e.Item.FindControl("rowlive");

      if (mapbtn != null && username != null)
      {
          UserProfile selectedUser = null;
          selectedUser = Sql.GetUserDetails(username.Value);
          if (selectedUser != null)
          {
              BroadcastOptions broadcastOptions = BroadcastOptions.None;
              int sessionId = 0;
              if (Sql.CheckActiveSession(selectedUser.UserId, Visibility.IncludePrivate, out sessionId, out broadcastOptions))
              {
                  Location[] locs = Sql.GetLocationByVodID(sessionId);
                  if (locs.Length > 0)
                  {
                      String mapUrl = mViewWebSite.AbsolutePath(
                        String.Format("/map.aspx?live=true&target_id={0}&uid={1}", sessionId, selectedUser.UserId.ToString()));
                      mapbtn.Enabled = true;
                      mapbtn.ImageUrl = "Images/miniWorldMap.png";
                      mapbtn.Attributes.Add("style", "Cursor:Pointer");
                      mapbtn.Attributes.Add("onclick", "ShowLocation('" + mapUrl + "')");
                  }
              }
          }
      }
  }


The above code was written by our previous senior web developer (that's what told to me when I was hired).
On every item bound on the repeater he
1) reads the username from hidden control D'Oh! | :doh:
2) call database to load user details Hmmm | :|
3) another call to database to check any active sessions OMG | :OMG:
4) another call to load whole list of gps locations to find whether gps is enables or not D'Oh! | :doh:
5) then finally enable the map button if gps is enabled

Amazingly this list is inside an update panel that updated every 10 seconds Cry | :(( Cry | :((

So for an average list of 30 users => total 3x30 = 90 database calls every 10 seconds
when i traced the page it was hauling at 320 Kb every 10 sec. Dead | X|

Fixed this in database, bringing a bool flag back by doing some joins and determining weather gps is enabled or not. Now only 1 db call every 10 sec.
GeneralRe: Looks like a database call obsession to me… Pin
Firo Atrum Ventus31-May-11 16:05
Firo Atrum Ventus31-May-11 16:05 
GeneralRe: Looks like a database call obsession to me… Pin
StM0n31-May-11 18:32
StM0n31-May-11 18:32 
GeneralRe: Looks like a database call obsession to me… Pin
saxenaabhi631-May-11 18:48
saxenaabhi631-May-11 18:48 
GeneralRe: Looks like a database call obsession to me… Pin
StM0n31-May-11 20:53
StM0n31-May-11 20:53 
GeneralRe: Looks like a database call obsession to me… Pin
RobCroll1-Jun-11 0:00
RobCroll1-Jun-11 0:00 
GeneralBad, very bad, test unit test.... PinPopular
richiej25-May-11 22:59
richiej25-May-11 22:59 
GeneralRe: Bad, very bad, test unit test.... Pin
R. Giskard Reventlov25-May-11 23:21
R. Giskard Reventlov25-May-11 23:21 
GeneralRe: Bad, very bad, test unit test.... Pin
Al_Brown26-May-11 1:55
Al_Brown26-May-11 1:55 
GeneralRe: Bad, very bad, test unit test.... Pin
Samuel Cragg26-May-11 2:54
Samuel Cragg26-May-11 2:54 
GeneralRe: Bad, very bad, test unit test.... Pin
Al_Brown26-May-11 3:03
Al_Brown26-May-11 3:03 
GeneralVBA data storage the text box way PinPopular
hairy_hats25-May-11 0:55
hairy_hats25-May-11 0:55 
GeneralRe: VBA data storage the text box way Pin
fjdiewornncalwe25-May-11 2:40
professionalfjdiewornncalwe25-May-11 2:40 
JokeRe: VBA data storage the text box way Pin
StM0n25-May-11 3:19
StM0n25-May-11 3:19 
GeneralRe: VBA data storage the text box way PinPopular
AspDotNetDev25-May-11 11:27
protectorAspDotNetDev25-May-11 11:27 
GeneralRe: VBA data storage the text box way Pin
Firo Atrum Ventus25-May-11 15:16
Firo Atrum Ventus25-May-11 15:16 
GeneralRe: VBA data storage the text box way PinPopular
StM0n25-May-11 20:08
StM0n25-May-11 20:08 
GeneralRe: VBA data storage the text box way Pin
CDP180225-May-11 22:35
CDP180225-May-11 22:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.