Skip to content

Instantly share code, notes, and snippets.

View mrtank's full-sized avatar

Márton Garai mrtank

  • Budapest, Hungary
View GitHub Profile
[TestMethod]
public void OnCompletedCalled()
{
TestScheduler scheduler = new TestScheduler();
ReplaySubject<TcpClient> subject = new ReplaySubject<TcpClient>(scheduler);
TcpListener listener = new TcpListener(IPAddress.Any, 11122);
listener.Start();
CancellationDisposable cancel = new CancellationDisposable();
bool isOk = false;
Func<IObservable<TcpClient>> asyncObs = Observable.FromAsyncPattern(listener.BeginAcceptTcpClient, listener.EndAcceptTcpClient);
private static IObservable<byte[]> ForEveryMessage(this TcpClient self, int byteCount, CancellationToken token)
{
return Observable.Create<byte[]>(
obs =>
{
NetworkStream stream = self.GetStream();
byte[] buffer = new byte[byteCount];
var recieving = Observable.FromAsyncPattern<byte[], int, int, int>(stream.BeginRead, stream.EndRead);
bool zeroBytesRead = false;
int remainder = byteCount;
[TestMethod]
public void BeginEndPairWithData()
{
byte[] changingData = new byte[] { 0 };
Action changeData = () => changingData = new byte[] { 1 };
IAsyncResult res = changeData.BeginInvoke(changeData.EndInvoke, null);
res.AsyncWaitHandle.WaitOne();
changingData.ShouldAllBeEquivalentTo((byte)1);
}
var numberList = new List<int>();
numberList.AddRange(new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
var totalNumber = 0;
foreach (var item in YieldingNotFive(numberList))
{
totalNumber += item;
}
private IEnumerable<int> YieldingNotFive(List<int> numberList)
{
using System.Collections.Generic;
namespace test
{
public class Something
{
public Something()
{
OrderableItems c1 = new Car(200);
OrderableItems b1 = new Bus(31);
internal class A
{
public void DoSixth()
{
}
public void DoFirst()
{
}
}
internal class A: IFirstFive, ISecondFive
{
public void DoSixth()
{
}
public void DoFirst()
{
}
}
@mrtank
mrtank / tree stuff
Last active September 20, 2016 13:32
// wiew
<TreeView Name="MyTree">
<TreeView.Resources>
<!-- would be nice, if it would be ILink for more extendability. Didn't work for some reason. Click and Children have to be added to ILink for that to work. In that case LinkViewModel should be implemented to have a clear short ILink -->
<HierarchicalDataTemplate DataType="{x:Type local:Link}" ItemsSource="{Binding Children}">
<StackPanel>
<Label Content="{Binding ElementName}"/>
<Button Command="{Binding Click}">Press to update</Button>
</StackPanel>
</HierarchicalDataTemplate>
// usage
// ...
IUnityContainer container = new UnityContainer();
container.RegisterType(typeof (IPhone), typeof (Phone));
container.RegisterType(typeof (IPda), typeof (Pda));
container.RegisterType(typeof (ICellPhone), typeof (CellPhone));
ICellPhone cellPhone = container.Resolve<ICellPhone>()
// ...
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Drawer drawer = new Drawer();
//MyTree.Items.Add(new Link(new CollectionInformation(new List<IElement>())));
MyTree.Items.Add(
new CollectionInformation(new List<IElement>
{