Click here to Skip to main content
15,900,973 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.

 
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 
GeneralRe: Take care of your TEMP folder! Pin
TnTinMn1-Jun-13 16:53
TnTinMn1-Jun-13 16:53 
GeneralRe: Take care of your TEMP folder! Pin
Bernhard Hiller2-Jun-13 22:56
Bernhard Hiller2-Jun-13 22:56 
GeneralRe: Take care of your TEMP folder! Pin
BobJanova3-Jun-13 0:05
BobJanova3-Jun-13 0:05 
GeneralRe: Take care of your TEMP folder! Pin
Richard Deeming3-Jun-13 2:09
mveRichard Deeming3-Jun-13 2:09 
GeneralMessage Closed Pin
31-May-13 9:10
professionalkburman631-May-13 9:10 
GeneralMessage Closed Pin
31-May-13 10:33
professionalDaveAuld31-May-13 10:33 
GeneralRe: Why do users click randomly and rapidly when an application hangs? Pin
kburman631-May-13 10:36
professionalkburman631-May-13 10:36 
GeneralRe: Why do users click randomly and rapidly when an application hangs? Pin
kburman631-May-13 10:45
professionalkburman631-May-13 10:45 
NewsCatches win matches... they say Pin
tumbledDown2earth30-May-13 4:54
tumbledDown2earth30-May-13 4:54 
GeneralRe: Catches win matches... they say Pin
PIEBALDconsult30-May-13 5:39
mvePIEBALDconsult30-May-13 5:39 
GeneralRe: Catches win matches... they say Pin
Rob Grainger31-May-13 2:58
Rob Grainger31-May-13 2:58 
GeneralRe: Catches win matches... they say PinPopular
PIEBALDconsult31-May-13 4:06
mvePIEBALDconsult31-May-13 4:06 

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.