IOError: [Errno 32] Broken pipe when piping: `prog.py | othercmd`

I haven’t reproduced the issue, but perhaps this method would solve it: (writing line by line to stdout rather than using print) You could catch the broken pipe? This writes the file to stdout line by line until the pipe is closed. You also need to make sure that othercommand is reading from the pipe before it gets too big – https://unix.stackexchange.com/questions/11946/how-big-is-the-pipe-buffer

How to implement a property in an interface

In the interface, you specify the property: In the implementing class, you need to implement it: This looks similar, but it is something completely different. In the interface, there is no code. You just specify that there is a property with a getter and a setter, whatever they will do. In the class, you actually … Read more

Should I use printf(“\n”) or putchar(‘\n’) to print a newline in C?

It will make no difference which one you chose if you’re using a modern compiler[1]. Take for example the following C code. When compiled with gcc -O1 (optimizations enabled), we get the following (identical) machine code in both foo and bar: Both foo and bar end up calling putchar(‘\n’). In other words, modern C compilers are smart enough to optimize printf calls very efficiently. Just use whichever … Read more

Categories c Tags

Why is access to the path denied?

According to File.Delete Method… An UnauthorizedAccessException means one of 4 things: The caller does not have the required permission. The file is an executable file that is in use. Path is a directory. Path specified a read-only file.

Categories c#

How to handle .tar.md5 files

First of all tar -xf should work since tar continues while it matches its’ packing algorithm. If the file stops matching so would tar. Also most archive managers such as 7-zip or winrar will open it if you remove the “.md5”. They might print error regarding mismatch with the end of the file, ignore it. … Read more

select * from table where column = something or, when unavailable, column = something else

You can provide a custom ordering, then take the first row, like this: Explanation: The inner select’s order by field(LOCALE, ‘ge’, ‘_’) gets you the rows in the order you define – in this case German first if it exists, then English (you could add more languages to the list). The “trick” here is using mysql’s “non-standard” GROUP … Read more

ArrayList of int array in java

First of all, for initializing a container you cannot use a primitive type (i.e. int; you can use int[] but as you want just an array of integers, I see no use in that). Instead, you should use Integer, as follows: For adding elements, just use the add function: Last, but not least, for printing the ArrayList you may use the build-in functionality … Read more