Click here to Skip to main content
15,883,705 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: It's Primes as far as the eye can see! Pin
Ian Shlasko27-Oct-14 8:44
Ian Shlasko27-Oct-14 8:44 
GeneralRe: It's Primes as far as the eye can see! Pin
Bert Mitton27-Oct-14 10:05
professionalBert Mitton27-Oct-14 10:05 
GeneralRe: It's Primes as far as the eye can see! Pin
PIEBALDconsult27-Oct-14 8:37
mvePIEBALDconsult27-Oct-14 8:37 
GeneralRe: It's Primes as far as the eye can see! Pin
PhilLenoir27-Oct-14 8:37
professionalPhilLenoir27-Oct-14 8:37 
GeneralRe: It's Primes as far as the eye can see! PinPopular
PaulLinton27-Oct-14 17:32
PaulLinton27-Oct-14 17:32 
GeneralRe: It's Primes as far as the eye can see! Pin
TheGreatAndPowerfulOz3-Nov-14 10:08
TheGreatAndPowerfulOz3-Nov-14 10:08 
GeneralRe: It's Primes as far as the eye can see! Pin
dan!sh 13-Nov-14 17:46
professional dan!sh 13-Nov-14 17:46 
GeneralIn the words of Sallah -- bad dates Pin
PIEBALDconsult25-Oct-14 14:43
mvePIEBALDconsult25-Oct-14 14:43 
Some date routines I found swept under the rug. How they got into the code-base I don't know, but there was only one C# developer on the project when I joined, so I waited until he left.


C#
// Return a string to display a DateTime object
// as DTZ: YYYYMMDDTHHMMSSZ = 20110101T070000Z
public static string GetDTZ(DateTime inDT)
{
  string rString = "";

  rString += inDT.Year;
  rString += FixDigits(inDT.Month, 2);
  rString += FixDigits(inDT.Day, 2);
  rString += "T";
  rString += FixDigits(inDT.Hour, 2);
  rString += FixDigits(inDT.Minute, 2);
  rString += FixDigits(inDT.Second, 2);
  rString += "Z";

  return rString;
}// end GetDTZ

// Return the name of the month that corresponds to a digit 1-12
public static string GetMonthName(int inMonth)
{
  string[] months = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  return months[inMonth % 13];
}// endGetMonthName


// Return a text version of an integer from 1-99
public static string GetDateName(int inNumber)
{
  string[] nos = {"", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth",
                "tenth", "eleventh", "twelfth", "thirteeth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth",
                "twenty", "twenty first", "twenty second", "twenty third", "twenty fourth", "twenty fifth", "twenty sixth", "twenty seventh", "twenty eigth", "twenty ninth",
                "thirty", "thirty first", "thirty second", "thirty third", "thirty fourth", "thirty fifth", "thirty sixth", "thirty seventh", "thirty eigth", "thirty ninth",
                "forty", "forty first", "forty second", "forty third", "forty fourth", "forty fifth", "forty sixth", "forty seventh", "forty eigth", "forty ninth",
                "fifty", "fifty first", "fifty second", "fifty third", "fifty fourth", "fifty fifth", "fifty sixth", "fifty seventh", "fifty eigth", "fifty ninth",
                "sixty", "sixty first", "sixty second", "sixty third", "sixty fourth", "sixty fifth", "sixty sixth", "sixty seventh", "sixty eigth", "sixty ninth",
                "seventy", "seventy first", "seventy second", "seventy third", "seventy fourth", "seventy fifth", "seventy sixth", "seventy seventh", "seventy eigth", "seventy ninth",
                "eighty", "eighty first", "eighty second", "eighty third", "eighty fourth", "eighty fifth", "eighty sixth", "eighty seventh", "eighty eigth", "eighty ninth",
                "ninety", "ninety first", "ninety second", "ninety third", "ninety fourth", "ninety fifth", "ninety sixth", "ninety seventh", "ninety eigth", "ninety ninth"
                };

  string outString = "";

  if (inNumber > 0 && inNumber < 100)
  {
    outString += nos[inNumber];
  }// end if

  return outString;
}// end GetDateName

// Return a string with date suffix given an integer from 1-32
public static string GetDayShortString(int inDay)
{
  string[] days = {"", "1st",  "2nd",  "3rd",  "4th",  "5th",  "6th",  "7th",  "8th",  "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th",
                      "17th", "18th", "19th", "20th", "21th", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st", "32nd"};
  return days[inDay % 33];
}// end GetDayShortString

QuestionRe: In the words of Sallah -- bad dates Pin
Member 9986689 (PandaLion98)25-Oct-14 20:57
professionalMember 9986689 (PandaLion98)25-Oct-14 20:57 
AnswerRe: In the words of Sallah -- bad dates Pin
PIEBALDconsult26-Oct-14 3:58
mvePIEBALDconsult26-Oct-14 3:58 
AnswerRe: In the words of Sallah -- bad dates Pin
Kornfeld Eliyahu Peter26-Oct-14 4:11
professionalKornfeld Eliyahu Peter26-Oct-14 4:11 
AnswerRe: In the words of Sallah -- bad dates Pin
Lutosław1-Nov-14 13:04
Lutosław1-Nov-14 13:04 
GeneralRe: In the words of Sallah -- bad dates Pin
Brisingr Aerowing27-Oct-14 5:17
professionalBrisingr Aerowing27-Oct-14 5:17 
GeneralWar of the Words Pin
Agent__00715-Oct-14 20:21
professionalAgent__00715-Oct-14 20:21 
GeneralRe: War of the Words Pin
Brisingr Aerowing16-Oct-14 8:49
professionalBrisingr Aerowing16-Oct-14 8:49 
GeneralRe: War of the Words PinPopular
PIEBALDconsult20-Oct-14 5:34
mvePIEBALDconsult20-Oct-14 5:34 
GeneralRe: War of the Words Pin
Brisingr Aerowing20-Oct-14 6:20
professionalBrisingr Aerowing20-Oct-14 6:20 
GeneralMS SmallBasic? Did you know? Silverlight plugin required Pin
newton.saber10-Oct-14 8:07
newton.saber10-Oct-14 8:07 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
ZurdoDev10-Oct-14 8:58
professionalZurdoDev10-Oct-14 8:58 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
newton.saber10-Oct-14 9:22
newton.saber10-Oct-14 9:22 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
ZurdoDev10-Oct-14 9:24
professionalZurdoDev10-Oct-14 9:24 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
newton.saber11-Oct-14 6:54
newton.saber11-Oct-14 6:54 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
DaveX8610-Oct-14 9:01
DaveX8610-Oct-14 9:01 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
DaveAuld10-Oct-14 9:13
professionalDaveAuld10-Oct-14 9:13 
GeneralRe: MS SmallBasic? Did you know? Silverlight plugin required Pin
Rob Grainger19-Oct-14 4:40
Rob Grainger19-Oct-14 4:40 

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.