I asked Grok to generate C# code to get the innermost string between strings. The initial test case worked, but soon realized with some testing of edge cases, this implementation failed.
Monday, March 31, 2025
AI Coding Challenge Major Fail - Part 2 using Grok to get innermost string between strings
Wednesday, March 26, 2025
AI Coding Challenge Major Fail - Why AI coding still has a long way to go
I asked Microsoft's AI Chat 'Copilot' to generate C# code to get the innermost string between strings. This is generalized version of getting a string between braces. Copilot generated a very plausible result, and even gave an example input and output. But the output, was very wrong. It was very misleading, given the very convincing Explanation below.
Conveniently, we can test this code for accuracy.
The output describe is "Innermost", which is the ideal output.
The actual output if you run the code is "Innermost]Middle".
TL;DR
When you go for a credit check, or cancer treatment, or battle policy cost increase, can you so easily argue the 'computer is wrong'?
using System; public class Program { public static void Main() { string input = "Outer[Middle[Innermost]Middle]Outer"; string start = "["; string end = "]"; string result = GetInnermostString(input, start, end); Console.WriteLine("Innermost string: " + result); } public static string GetInnermostString(string input, string start, string end) { int endIndex = input.LastIndexOf(end); if (endIndex == -1) return ""; // End marker not found int startIndex = input.LastIndexOf(start, endIndex - 1); if (startIndex == -1) return ""; // Start marker not found startIndex += start.Length; return input.Substring(startIndex, endIndex - startIndex); } }
Monday, March 17, 2025
C# Round Datetime Extension To Nearest Minute, Round Up, Round Down

C# DateTime extensions that rounds a datetime Up, Down or Nearest minutes and smaller units are rounded to zero.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | using System; public static class Program { /// <summary> /// Rounds datetime up, down or to nearest minutes and all smaller units to zero /// </summary> /// <param name="dt">ignore, implicitly passed</param> /// <param name="rndmin">mins to round to</param> /// <param name="directn">Up,Down,Nearest</param> /// <returns>rounded datetime with all smaller units than mins rounded off</returns> public static DateTime RoundToNearestMinuteProper(this DateTime dt, int rndmin, RoundingDirection directn) { if (rndmin == 0) //can be > 60 mins return dt; TimeSpan d = TimeSpan.FromMinutes(rndmin); //this can be passed as a parameter, or use any timespan unit FromDays, FromHours, etc. long delta = 0; Int64 modTicks = dt.Ticks % d.Ticks; switch (directn) { case RoundingDirection.Up: delta = (modTicks != 0) ? d.Ticks - modTicks : 0; break; case RoundingDirection.Down: delta = -modTicks; break; case RoundingDirection.Nearest: { bool roundUp = modTicks > (d.Ticks / 2); var offset = roundUp ? d.Ticks : 0; delta = offset - modTicks; break; } } return new DateTime(dt.Ticks + delta, dt.Kind); } public enum RoundingDirection { Up, Down, Nearest } public static void Main() { //var dt = new DateTime(2001, 1, 1, 0, 0, 0, 000); //var dt = new DateTime(2018, 08, 03, 10, 7, 30, 000); //8/3/2018 10:00:00 AM Nearest, re 15/2 = 7.5 mins or 7 mins and 30 secs var dt = new DateTime(2018, 08, 03, 10, 7, 31, 000); //8/3/2018 10:15:00 AM Nearest Console.WriteLine(dt.RoundToNearestMinuteProper(15, RoundingDirection.Up)); Console.WriteLine(dt.RoundToNearestMinuteProper(15, RoundingDirection.Down)); Console.WriteLine(dt.RoundToNearestMinuteProper(15, RoundingDirection.Nearest)); } } |
Optimizations: 1/2 of a number use right-shift
int half = number >> 1; // Right-shift by 1 to divide by 2
Wednesday, March 12, 2025
Google Search Console takes design cue from my metadata consulting blog
Nice to see new Google Search Console layout and design took a bit out of my design for this blog. 😉
Saturday, March 8, 2025
Best modern way to remember days of the month
Odd numerical months are 31 days and even are 30, except when calendar authors got a hangover/vacation in August (08) and bumps the rest of the calendar by 1 month.
Month | Abbreviation |
Month Numerical |
Month No. of days |
Johnny Mnemonic |
Qtr | Season |
---|---|---|---|---|---|---|
January | Jan. | 1 | 31 | odd month | Q1 | Winter |
February | Feb. | 2 |
28 (common year) 29 (leap year/4) |
Jan-3 (even month - 2) |
Q1 | Winter |
March | Mar. | 3 | 31 | odd month | Q1 | Spring |
April | Apr. | 4 | 30 | even month | Q2 | Spring |
May | May. | 5 | 31 | odd | Q2 | Spring |
June | Jun. | 6 | 30 | even | Q2 | Summer |
July | Jul. | 7 | 31 | odd | Q3 | Summer |
August | Aug. | 8 | 31 |
summer vacation / hangover |
Q3 | Summer |
September | Sep. | 9 | 30 | bumped | Q3 | Autumn |
October | Oct. | 10 | 31 | bump-odd now | Q4 | Autumn |
November | Nov. | 11 | 30 | bump-even now | Q4 | Autumn |
December | Dec. | 12 | 31 | bump-odd now | Q4 | Winter |
Historically, August was named by Gaius Julius Caesar Augustus (born Gaius Octavius; 23 September 63 BC – 19 August AD 14. Another way to remember this...
- Augustus was born in 63 B.C. and named Gaius Octavius (Octavian) and was the grandson of Julius Caesar's sister.
- In addition to changing Sextilis to Augustus, speculation states that he took one day from February and one from September to add to his month, making it 31 days; because he apparently did not wish to have August with fewer days than Julius (July).
The calendar commonly used in modern America is the Gregorian calendar. It was introduced by Pope Gregory XIII in 1582 and is a modification of the Julian calendar. The Gregorian calendar is widely used worldwide and is the calendar system officially followed by most countries, including the United States.
Date Range Picker Outlook.com and Outlook Client