shit.programmers.write();

RSS
FUNCTION RET_PRG (P_EPSD IN NUMBER) RETURN NUMBER IS
w_cdprogr NUMBER :=4;
BEGIN
RETURN w_cdprogr;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN NULL;
WHEN TOO_MANY_ROWS THEN
RETURN NULL;
END RET_PRG;

Loading XML like a boss

System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
xmlDocument.LoadXml(promoXml);

XDocument xmlDoc = new XDocument();
xmlDoc = XDocument.Load(new System.Xml.XmlNodeReader(xmlDocument));

Jan 5

let there be a better way to foreach

foreach (var tuple in
    from type in Assembly.GetExecutingAssembly().GetTypes()
    where typeof(IAll).IsAssignableFrom(type)
    let constructors = type.GetConstructors()
    where constructors.Any(constructor => !constructor.GetParameters().Any())
    let consumer = (IAll) Activator.CreateInstance(type)
    from method in type.GetMethods()
    where String.Equals(method.Name, "Consumes", StringComparison.Ordinal)
    let parameters = method.GetParameters()
    where parameters.Count() == 1
    let messageParameter = parameters.Single()
    let messageType = messageParameter.ParameterType
    where typeof(Message).IsAssignableFrom(messageType)
    select new {
        MessageType = messageType,
        Delegate = Delegate.CreateDelegate(typeof(Action).MakeGenericType(
            messageParameter.ParameterType), consumer, method) }) {

    registerHandlerMethod.MakeGenericMethod(tuple.MessageType)
        .Invoke(bus, new object[] { tuple.Delegate });
}

No need for if

$res = $db->query($SQL);

while (!$arrB = $res->fetchRow()) {
    return 0;
}

Did we remember to load the Grids?

Protected Overrides Sub LoadControls()
    ‘need to override 
    LoadGrids()
    …
End Sub

Public Overrides Sub PageChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
    Dim grid As DataGrid = CType(source, DataGrid)
    grid.CurrentPageIndex = e.NewPageIndex()

    LoadGrids()

End Sub

Public Overrides Sub ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
    …
    LoadControls()
End Sub

Private Sub btnAssign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssign.ServerClick
   
    If (Not userAllowed) Or (itemBusy) Then
      …
      LoadGrids()
      …
    Else
      …
      LoadGrids()
    End If

    Catch Ex As Exception
      …
    Finally
    End Try
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  …
  LoadGrids()
  …
End Sub

Private Sub btnRelease_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRelease.ServerClick
  …

  If (itemBusy OrElse itemUnassigned OrElse noUnassignedQueue) Then
    …
    LoadGrids()
    …
  Else
    …
    LoadGrids()
  End If
  Catch Ex As Exception
    …
  Finally
  End Try

End Sub


Private Sub btnAssignConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssignConfirm.ServerClick
    …
    LoadGrids()
    …
End Sub


Private Sub btnReleaseConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReleaseConfirm.ServerClick
    …
    LoadGrids()
    …
End Sub


Private Sub lstInboxGridSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstInboxGridSize.SelectedIndexChanged
    Try
        …
        LoadGrids()
    Catch ex As Exception
        …
    End Try
End Sub


Private Sub btnApplyFilters_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApplyFilters.Click
    Try
        …
        LoadGrids()
    Catch ex As Exception
        …
    End Try
End Sub

Replace just got better

int q = 0;

while (dr.Title.Length > q)
{
  if (dr.Title[q].Equals(‘'’))
  {
    newTitle.Append(“\” + dr.Title[q]);
  }
  else
  {
    newTitle.Append(dr.Title[q]);
  }
  
  q++;
}

Don’t all textboxes represent date/time objects?

<script type=”text/javascript”>
                $(function() {
                    $(“:text”).each(function() {
                        jQueryFacade.attachDatePicker($(this))
                    });
                });
</script>

Important Abstractions. (comment added later)

/* WTF is the point of this interface? */

public interface NumberConstants {

public static Integer NUMBER_0 = 0;

public static Integer NUMBER_1 = 1;

public static Integer NUMBER_2 = 2;

public static Integer NUMBER_3 = 3;

public static Integer NUMBER_4 = 4;

public static Integer NUMBER_5 = 5;

public static Integer NUMBER_6 = 6;

public static Integer NUMBER_7 = 7;

public static Integer NUMBER_8 = 8;

}

mIRC and America

alias life {
  set %age $?=”How old are you?”
  var %expectancy $calc(79 - %age)
  msg # You have the potential to live another %expectancy years, on     average. $& Too bad you’re not from Monaco, it could be possibly be     $calc(%expectancy + 15) years instead.
}

#include <cmath>

class Cos {
    public:
        Cos() {}
        ~Cos() {}
        double run(double x) { return cos(x); }
};