Friday, May 6, 2011

Sunday, May 1, 2011

Obfuscated Programming Contests

Wiki: Obfuscated code

In C:
Wiki: International Obfuscated C Code Contest
The International Obfuscated C Code Contest Winning entries

In Assembly:
世界编程大赛第一名的3D程序 (or see here)
又是一个64k华丽至极的程序

Quine and Programming languages for fun

Quine is a program that prints itself. See wiki page on Quine. Here is a special Quine that prints a series of programs in 11 languages and eventually comes back to itself.

Here is an article BT雷人的程序语言(大全) about strange programming languages (made for fun in most cases). They are really funny. The end of this article gives these references:

- Esoteric_programming_languages
- Top 13 Most Absurd Programming Languages
- Befunge语言和文言文编程
- 疯狂的编程语言——ENGLISH,Chef Shakespeare
- DM’s Esoteric Programming Languages
- 十大另类程序语言(上)
- 十大另类程序语言(下)

Monday, April 25, 2011

C# Mapping a network drive

C# can map a network drive by calling OS commands [1] or using native win32 API [2].

The code below is from [1]:

System.Diagnostics.Process.Start("net.exe", "use K: \\Server\URI\\path\\here");
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = "C:\\application.exe";
psi.WorkingDirectory = "K:\\working\\directory";
psi.WindowStyle = System.Diagnostics.
ProcessWindowStyle.Maximized;
System.Diagnostics.Process p =
System.Diagnostics.Process.Start(psi);

[1] http://forum.codecall.net/c-programming/1119-c-mapping-network-drive.html
[2] http://bytes.com/topic/c-sharp/answers/812115-mapping-network-drive-c

Saturday, April 23, 2011

Nature: The Future of the PhD

Nature: The Future of the PhD [Nature 472 (20 April 2011)]

Set of articles discussing the current (problematic) system of PhD, from the training of PhD to the career prospects, and speculations on ways to fix the problems.

Monday, February 28, 2011

A problem with process pipe communication in C#

In C#, the Process component communicates with a child process via a pipe. If a child process writes enough data to the pipe to fill the buffer, the child will block until the parent reads the data from the pipe. This can cause deadlock if your application is reading all output to standard error and standard output, for example, using the following C# code.
              Process p = new Process("...", "...");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();

In this instance, both the parent and the child processes would be blocked, as the filled pipe prevents the child process from completing, while the parent process is waiting indefinitely for the child process to exit. The pipe buffer, in my code, was 4096 bytes. If the output reaches this limit, it would hang.

This problem can be solved by moving the ReadToEnd() before the WaitForExit(), as follows..
              Process p = new Process("...", "...");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

References:
[1] http://bytes.com/topic/c-sharp/answers/459800-redirect-standard-output-size-limit
[2] http://www1.cs.columbia.edu/~lok/csharp/refdocs/System.Diagnostics/types/Process.html

Blog Archive

Followers