This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// That's more exploiting JavaScript closures and global scope than re-writing functions. Can't you do the same in C#? | |
[Test] | |
public void test_we_can_rewrite_variable_in_closure() | |
{ | |
System.Func<string, string> fn = (a) => | |
{ | |
fn = (b) => "Goodbye " + b; | |
return "Hello " + a; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I always thought this really interesting in JavaScript, and doesn't seem to work the same in C# or Python. | |
get_counter = function() { | |
var counter = 0; | |
return function() { | |
print(counter); counter++; | |
} | |
}; | |
.. | |
js> counter1 = get_counter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example PowerShell script demonstrating configuring a website in IIS7 | |
# | |
# | |
# Import the required IIS administration module | |
# | |
Import-Module WebAdministration | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! src/guestbook_resource.erl | |
-module(guestbook_resource). | |
-export([init/1, | |
to_html/2, | |
process_post/2, | |
allowed_methods/2 | |
]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class Scheduler | |
{ | |
public delegate Process Process(string message); | |
public static Dictionary<Guid, Process> Processes = new Dictionary<Guid,Process>(); | |
public static Guid Spawn(Process process) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C# implementation of a circular message chain of n nodes, which pass a message around m times. | |
// Uses a basic scheduler instead of threads. | |
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
public class MessageChain | |
{ | |
public static void Main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(messagechain). | |
-compile(export_all). | |
start() -> | |
Pid = messagechain:setup(3, 3), | |
Pid ! { message }. | |
setup(Times, Loops) -> | |
Pid = spawn(fun() -> message_node(Loops) end), | |
EndPid = messagechain:create_nodes(Times, Loops, Pid), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
public class MessageChainThreads | |
{ | |
public static AutoResetEvent CreateNode(AutoResetEvent triggerEvent, int messages) | |
{ | |
var waitEvent = new AutoResetEvent(false); | |
CreateThread(waitEvent, triggerEvent, messages); | |
return waitEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public static class ExtensionMethods | |
{ | |
public static IEnumerable<T> ToList<T>(this T value) { | |
yield return value; | |
} | |
public static IEnumerable<U> SelectMany<T, U>(this IEnumerable<T> m, Func<T, IEnumerable<U>> k) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(accumulators). | |
-export([average/1]). | |
average(X) -> average(X, 0, 0). | |
average([H|T], Length, Sum) -> | |
average(T, Length + 1, Sum + H); | |
average([], Length, Sum) -> | |
Sum / Length. |
OlderNewer