Hacker News new | ask | show | jobs
by miguelrochefort 3882 days ago
C#

https://dotnetfiddle.net/afyTvh

    using System;
    using System.IO;
    using System.Threading;
					
    public class Blink
    {
    	const string FilePath = @"/sys/class/leds/beaglebone\:green\:usr0/brightness";
    	const int BlinkDelay = 2000;
    	
    	public static void Main()
    	{		
    	    using (var writer = new StreamWriter(FilePath))
    	    {
    	 	for (var state = true; true; state = !state)
    		{
		    writer.Write((state ? 1 : 0).ToString("00"));
                    Thread.Sleep(2000);	
    		}
    	    }
    	}
    }
Reactive Extensions (C#)

https://dotnetfiddle.net/bpOF5e

    Observable
	.Repeat(Observable.Unit)
	.Select((index, _) => index % 2)
        .Select(string.Format({0:00})
	.Delay(TimeSpan.FromSeconds(2))
	.Aggregate(
	    new StreamWriter(@"/sys/class/leds/beaglebone\:green\:usr0/brightness"), 
	    writer => (writer, state) => writer.Write(state)
	)
	.Subscribe(writer => writer.Close());
1 comments

Both your example and the Java one are not abstract enough (although the added string conversion is nice.) I was expecting more design patterns and layering for a truly enterprise-quality solution, like this:

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...

This is my favorite comment :-) After years of programming in enterprise Java, I failed to truly make it enterprise worthy! I'm going to see if I can get an assembly example added per your other comment.