Haskell file reading

Not a bad start! The only thing to remember is that pure function application should use let instead of the binding <-. import System.IO import Control.Monad main = do let list = [] handle <- openFile “test.txt” ReadMode contents <- hGetContents handle let singlewords = words contents list = f singlewords print list hClose handle … Read more

Parse a log4j log file

I didn’t realize that Log4J ships with an XML appender. Solution was: specify an XML appender in the logging configuration file, include that output XML file as an entity into a well formed XML file, then parse the XML using your favorite technique. The other methods had the following limitations: Apache Chainsaw – not automated … Read more

Reading a .pdb file

If you mean PDB as in a “program database” that the debugger uses: PDB files contain data about a file such as an EXE or DLL that is used to aid in debugging. There are public interfaces that allow you to extract data from the file. See examples here: https://learn.microsoft.com/en-us/archive/blogs/jmstall/sample-code-for-pdb-2-xml-tool (Moved from http://blogs.msdn.com/jmstall/archive/2005/08/25/pdb2xml.aspx) http://www.codeproject.com/KB/bugs/PdbParser.aspx If … Read more

Log4Net config in external file does not work

Do you have the following attribute in your AssemblyInfo.cs file: [assembly: log4net.Config.XmlConfigurator(ConfigFile = “Log4Net.config”, Watch = true)] and code like this at the start of each class that requires logging functionality: private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); I have a blog post containing this and other info here.

How to check if a file exists in Go?

To check if a file doesn’t exist, equivalent to Python’s if not os.path.exists(filename): if _, err := os.Stat(“/path/to/whatever”); errors.Is(err, os.ErrNotExist) { // path/to/whatever does not exist } To check if a file exists, equivalent to Python’s if os.path.exists(filename): Edited: per recent comments if _, err := os.Stat(“/path/to/whatever”); err == nil { // path/to/whatever exists } … Read more