Skip to content

Instantly share code, notes, and snippets.

@renestein
renestein / Program.cs
Last active October 19, 2022 06:21 — forked from rarous/gist:4352819
Aleš Roubíček Task with retry logic.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TaskWithRetry
{
internal class Program
{
@renestein
renestein / GenericNullable1.cs
Last active September 2, 2021 14:22
GenericNullable1.cs
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
MyStack<MyItem> stack = new MyStack<MyItem>();
public class MyStack<T> where T : class
{
private T[] _items;
@renestein
renestein / gist:2979279
Created June 23, 2012 18:17
Simple twitter account checker
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reactive.Linq;
using System.Text;
using System.Xml.Linq;
namespace TwitterSearcher
{
//Actor inherits from the ActorPolicy class.
class TestActor : public Actors::ActorPolicy
{
public:
TestActor() : ActorPolicy{}
{
}
TEST(SimpleActorTest, WhenUsingAsyncStatefulActorThenHasExpectedState)
{
const int MESSAGES_COUNT = 101;
const int EXPECTED_STATE = MESSAGES_COUNT;
auto seenMessages = 0;
auto testState = 0;
{
//Create the actor (asynchronous logic/with state/no reply).
auto stateFullActor = RStein::AsyncCpp::Actors::CreateAsyncSimpleActor<int, int>([&seenMessages, &testState](const int& message, const int& state)->Task<int>
{
Tasks::Task<size_t> WhenAsyncForkJoinDataflowThenAllInputsProcessedImpl(int inputItemsCount)
{
//Create TransformBlock. As the name of the block suggests, TransformBlock transforms input to output.
//Following block transforms int to string.
auto transform1 = DataFlowAsyncFactory::CreateTransformBlock<int, int>([](const int& item)-> Tasks::Task<int>
{
//Simulate work
co_await Tasks::GetCompletedTask();
auto message = "int: " + to_string(item) + "\n";
cout << message;
@renestein
renestein / AgentRX.cs
Last active December 16, 2015 13:38
P. riedl emwac
var ts = myAgentList.ToObservable().Concat(
Observable.FromEventPattern
<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>
(
handler => myAgentList.CollectionChanged += handler,
handler => myAgentList.CollectionChanged -= handler
)
.Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Add)
.SelectMany(c => c.EventArgs.NewItems.Cast<MyAgent>()))
@renestein
renestein / gist:5434943
Last active December 16, 2015 12:29
Avoid lock in console - .Net 4.,5
// https://twitter.com/jechtom/status/326325740503175169
using System;
using System.Threading;
internal class Program
{
private static void Main(string[] args)
{
Console.Error.WriteLine("Dummy error init");
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace Mormegill_test
//https://twitter.com/mormegil_cz/status/321991296019484672
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mormegill_test
{