Skip to content

Instantly share code, notes, and snippets.

View peace2048's full-sized avatar

naoki ochiai peace2048

View GitHub Profile
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
ctx.Database.Log = message => Console.WriteLine(message);
<Query Kind="Statements">
<Reference>&lt;RuntimeDirectory&gt;\System.Windows.Forms.dll</Reference>
<NuGetReference>OxyPlot.WindowsForms</NuGetReference>
<Namespace>OxyPlot</Namespace>
<Namespace>OxyPlot.Axes</Namespace>
<Namespace>OxyPlot.Series</Namespace>
</Query>
var pm = new PlotModel
{
@peace2048
peace2048 / Form1.vb
Last active March 2, 2016 06:41
forms_databinding.md
Imports System.ComponentModel
Public Class Form1
Private _model As New Model()
Public Sub New()
InitializeComponent()

サンプルデータの作成

<Extension>
Public Iterator Function Repeat(Of T)(element As T) As IEnumerable(Of T)
	While True
		Yield element
	End While
End Function
void Main()
{
var connection = ConnectionMultiplexer.Connect("192.168.5.40");
var sx1 = connection.ObservableSubscription("pa");
using (sx1.Subscribe(_ => Console.WriteLine(_))) Console.ReadLine();
var sx2 = connection.ObservableList("qa", TimeSpan.FromSeconds(5));
using (sx2.Subscribe(_ => Console.WriteLine(_))) Console.ReadLine();

TaskCompletionSource でハマる

別に TaskCompletionSource でハマったわけではないですが、TaskCompletionSource で作成したタスクを Async/Await で待ったときにハマってしまった。

元々、OPC Automation で非同期入出力が、コマンドに対しイベントで完了を通知していますので、TaskCompletionSource を使って Task にする説明を考えていました。

最初に、チョロット書こうとしていたことを事実を捻じ曲げて説明します。(本当は引数等が違います。) OPC Automation では、AsyncRead に対し完了を AsyncReadComplete イベントで通知し、操作のキャンセルも AsyncCancel に対し AsyncCancelComplete で完了を通知しています。

@peace2048
peace2048 / ReceiptPrinter.cs
Last active December 31, 2015 00:59
レシートプリンターに出力するのに使うつもり
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Printer.Sample
{
@peace2048
peace2048 / PropertyChain.vb
Last active December 29, 2015 17:19
ある `INotifyPropertyChanged` なオブジェクトのプロパティが変化したら 別のオブジェクトのプロパティも更新する
Enum PropertyChainMode
CopyOnly
RaiseOnly
CopyAndRaise
End Enum
Class PropertyChain(Of TSource As {Class, INotifyPropertyChanged}, TTarget)
Private WithEvents _source As TSource
Private _target As TTarget
@peace2048
peace2048 / Buffer.vb
Created November 27, 2013 10:54
T型のシーケンスを、任意サイズの配列のシーケンスに変える ref: http://qiita.com/peace2048/items/3ffd5dd1d5ddee4f6c06
Module EnumerableExBuffer
<Extension>
Public Function Buffer(Of T)(
ByVal source As IEnumerable(Of T),
ByVal count As Integer
) As IEnumerable(Of T())
If source Is Nothing Then Throw New ArgumentNullException("source")