Click here to Skip to main content
15,918,808 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 as War Crime Pin
Gary Wheeler4-Jun-13 1:51
Gary Wheeler4-Jun-13 1:51 
GeneralRe: Code as War Crime Pin
Phil Boyd4-Jun-13 2:45
Phil Boyd4-Jun-13 2:45 
GeneralRe: Code as War Crime Pin
Gordon Kushner4-Jun-13 3:40
Gordon Kushner4-Jun-13 3:40 
GeneralRe: Code as War Crime Pin
Rob Grainger5-Jun-13 2:54
Rob Grainger5-Jun-13 2:54 
GeneralRe: Code as War Crime Pin
Gary Wheeler5-Jun-13 6:42
Gary Wheeler5-Jun-13 6:42 
GeneralRe: Code as War Crime Pin
Diana Arnos4-Jun-13 3:30
Diana Arnos4-Jun-13 3:30 
GeneralRe: Code as War Crime Pin
Gordon Kushner4-Jun-13 3:39
Gordon Kushner4-Jun-13 3:39 
GeneralRe: Code as War Crime Pin
Diana Arnos4-Jun-13 3:46
Diana Arnos4-Jun-13 3:46 
GeneralRe: Code as War Crime Pin
vonb4-Jun-13 4:21
vonb4-Jun-13 4:21 
GeneralRe: Code as War Crime Pin
RafagaX4-Jun-13 6:14
professionalRafagaX4-Jun-13 6:14 
GeneralRe: Code as War Crime Pin
BobJanova4-Jun-13 6:17
BobJanova4-Jun-13 6:17 
GeneralRe: Code as War Crime Pin
Gordon Kushner4-Jun-13 6:45
Gordon Kushner4-Jun-13 6:45 
JokeRe: Code as War Crime Pin
Chad3F4-Jun-13 18:56
Chad3F4-Jun-13 18:56 
GeneralVisual Basic is a problem. Pin
Lutosław4-Jun-13 22:34
Lutosław4-Jun-13 22:34 
GeneralRe: Code as War Crime Pin
Gordon Kushner5-Jun-13 3:01
Gordon Kushner5-Jun-13 3:01 
GeneralRe: Code as War Crime Pin
Lutosław5-Jun-13 21:50
Lutosław5-Jun-13 21:50 
GeneralRe: Code as War Crime Pin
Gordon Kushner6-Jun-13 2:03
Gordon Kushner6-Jun-13 2:03 
GeneralRe: Code as War Crime Pin
shiprat5-Jun-13 13:00
shiprat5-Jun-13 13:00 
GeneralRe: Code as War Crime Pin
giuchici7-Jun-13 3:51
giuchici7-Jun-13 3:51 
GeneralTake care of your TEMP folder! Pin
Bernhard Hiller31-May-13 22:49
Bernhard Hiller31-May-13 22:49 
The ghosts of the past won't let me rest. My former boss informed me that our project web page "was broken. At least, it is not listed as a malware site on Google".
Well, last thing happened to us last year after a hacker attack (see http://www.codeproject.com/Messages/4323984/Analysing-an-obfuscated-malware-script.aspx[^]).
Since that project was my best piece of work (seriously, not in the satirical meaning of the rest of this post, and despite the code shown below), I immediately looked into it: the home page loaded smoothly. Nothing wrong. The next pages also. So, what was wrong? I tried an aspx page. Worked. Next aspx page, and here it was:
Error: Access violation. File exists. at
strFileName = System.IO.Path.GetTempFileName

The page creates an image dynamically, based on user input. The image is written into Graphics folder of the web site. After the web site was moved to a different server, the clean-up process for that folder failed due to a lack of access rights. But that was long ago. I looked into that folder, and it was empty.
But wait, that line mentioned in the error message does something different!
Before the temporary image file is created, I ask Windows to give me a file name. I created such a superb function for that purpose:
VB
Public Function getTempFileName(Optional ByVal Extension As String = "tmp") As String
    Dim strFileName As String

    'system temp file name
    strFileName = System.IO.Path.GetTempFileName

    'file name only
    strFileName = strFileName.Substring(System.IO.Path.GetTempPath.Length)

    'default extension is "tmp", if we want a different one, we must exchange it
    If Extension <> "tmp" Then
        strFileName = strFileName.Substring(0, strFileName.Length - 3) & Extension
    End If

    'done
    Return strFileName
End Function

Overwhelmed by the beauty of this piece of code (it will surely be honored as the proper solution to that problem in many VB and aspx fora throughout the web soon), you'll likely not see how this function can fail. Also I had to take a look into Microsoft's documentation:
Not only does System.IO.Path.GetTempFileName return the full path for a temporary file, it does also create it! And yes, Windows must do so to ensure that two programs do not share one temp file. I took the filename only, never did I care for that file. And somewhen Windows run out of temp files...
GeneralRe: Take care of your TEMP folder! Pin
AlphaDeltaTheta1-Jun-13 2:51
AlphaDeltaTheta1-Jun-13 2:51 
GeneralRe: Take care of your TEMP folder! Pin
AlphaDeltaTheta1-Jun-13 2:59
AlphaDeltaTheta1-Jun-13 2:59 
GeneralRe: Take care of your TEMP folder! Pin
Lutosław1-Jun-13 4:29
Lutosław1-Jun-13 4:29 
GeneralRe: Take care of your TEMP folder! Pin
AlphaDeltaTheta1-Jun-13 15:24
AlphaDeltaTheta1-Jun-13 15:24 
GeneralRe: Take care of your TEMP folder! Pin
PIEBALDconsult1-Jun-13 8:23
mvePIEBALDconsult1-Jun-13 8:23 

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.