Click here to Skip to main content
12,898,174 members (58,676 online)

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: CodeProject Daily News - The only newsletter I would, deliberately, subscribe to Pin
OriginalGriff16-Jun-14 5:28
protectorOriginalGriff16-Jun-14 5:28 
GeneralEnhanced Password Security Pin
Bernhard Hiller10-Jun-14 21:08
professionalBernhard Hiller10-Jun-14 21:08 
JokeRe: Enhanced Password Security Pin
Kornfeld Eliyahu Peter10-Jun-14 22:17
professionalKornfeld Eliyahu Peter10-Jun-14 22:17 
GeneralRe: Enhanced Password Security Pin
Eddy Vluggen11-Jun-14 0:29
professionalEddy Vluggen11-Jun-14 0:29 
GeneralRe: Enhanced Password Security Pin
Trajan McGill11-Jun-14 3:07
memberTrajan McGill11-Jun-14 3:07 
GeneralRe: Enhanced Password Security Pin
PIEBALDconsult11-Jun-14 12:02
memberPIEBALDconsult11-Jun-14 12:02 
GeneralRe: Enhanced Password Security Pin
PIEBALDconsult11-Jun-14 12:10
memberPIEBALDconsult11-Jun-14 12:10 
GeneralDateTime.Now vs. GetSystemTime Pin
Bernhard Hiller30-May-14 0:17
professionalBernhard Hiller30-May-14 0:17 
Working with date and time is known to be a source of beautiful code...
System.DateTime.Now gets the current system time, but you cannot set it. When you want to be able to set the system time, you can try SetSystemTime(ref SYSTEMTIME lpSystemTime) of kernel32.dll; and there is also a GetSystemTime(ref SYSTEMTIME lpSystemTime) function in that dll.
When I played with these functions, I wrote some tests to make sure I got the conversion from struct SYSTEMTIME to System.DateTime and vice versa right.
[Test]
public void GetSystemTime()
{
    DateTime expected = System.DateTime.Now;
    DateTime actual = SystemTime.GetSystemTime();
    Assert.AreEqual(expected, actual);
}

Well, that always failed: it takes a tick or two to do all the calculations.
I had to update it to allow for some delay:
[Test]
public void GetSystemTime()
{
    DateTime expected = System.DateTime.Now;
    DateTime actual = SystemTime.GetSystemTime();
    int delta = Math.Abs(Convert.ToInt32((actual - expected).Ticks));
    int maxDuration = Convert.ToInt32(2 * TimeSpan.TicksPerMillisecond);
    Assert.Less(delta, maxDuration);
}
That's 2 Milliseconds for that simple code. But still it fails rather often:
Errors and Failures:
1) Test Failure : XY.SystemTimeTests.GetSystemTime
  Expected: less than 20000
  But was:  147763

What does the computer do during those almost 15 ms? Is this a test for catching the computer asleep?
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Pete O'Hanlon30-May-14 1:05
protectorPete O'Hanlon30-May-14 1:05 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Bernhard Hiller2-Jun-14 0:30
professionalBernhard Hiller2-Jun-14 0:30 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Pete O'Hanlon2-Jun-14 0:32
protectorPete O'Hanlon2-Jun-14 0:32 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Jörgen Andersson2-Jun-14 21:11
professionalJörgen Andersson2-Jun-14 21:11 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Bernhard Hiller2-Jun-14 21:35
professionalBernhard Hiller2-Jun-14 21:35 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Jörgen Andersson2-Jun-14 21:56
professionalJörgen Andersson2-Jun-14 21:56 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
BobJanova2-Jun-14 0:51
memberBobJanova2-Jun-14 0:51 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Rob Philpott10-Jun-14 5:20
professionalRob Philpott10-Jun-14 5:20 
GeneralRe: DateTime.Now vs. GetSystemTime Pin
Eddy Vluggen6-Jun-14 5:11
professionalEddy Vluggen6-Jun-14 5:11 
GeneralSuccessfully writing to a string literal Pin
Indivara18-May-14 23:44
professionalIndivara18-May-14 23:44 
GeneralRe: Successfully writing to a string literal Pin
Freak3019-May-14 1:45
memberFreak3019-May-14 1:45 
GeneralRe: Successfully writing to a string literal Pin
Indivara19-May-14 5:17
professionalIndivara19-May-14 5:17 
GeneralRe: Successfully writing to a string literal Pin
newton.saber19-May-14 1:45
membernewton.saber19-May-14 1:45 
GeneralRe: Successfully writing to a string literal Pin
Indivara19-May-14 5:15
professionalIndivara19-May-14 5:15 
GeneralRe: Successfully writing to a string literal Pin
newton.saber19-May-14 5:34
membernewton.saber19-May-14 5:34 
GeneralThe Exception to the C# Rules Pin
Brady Kelly15-May-14 18:55
memberBrady Kelly15-May-14 18:55 
GeneralRe: The Exception to the C# Rules Pin
Bernhard Hiller15-May-14 21:54
professionalBernhard Hiller15-May-14 21:54 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 30 Apr 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid