Skip to content

Instantly share code, notes, and snippets.

View peace2048's full-sized avatar

naoki ochiai peace2048

View GitHub Profile
@peace2048
peace2048 / DatabaseExtensions.vb
Created September 24, 2013 01:19
IDbConnection 等の拡張メソッド
Imports System.Runtime.CompilerServices
Imports System.Dynamic
Module DatabaseExtensions
Sub Main()
Dim conn = New SqlClient.SqlConnection("Data Source=...")
Dim one = Convert.ToInt32(conn.ExecuteScalar("SELECT 1"))
@peace2048
peace2048 / PropertyChangedExtensions.vb
Created October 24, 2013 11:16
PropertyChanged イベントを IObservable で監視しやすいように、INotifyPropertyChanged を拡張します。
Imports System
Imports System.ComponentModel
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Reactive.Linq
Imports System.Runtime.CompilerServices
''' <summary>
''' INotifyPropertyChanged に拡張メソッドを追加し、PropertyChanged イベントを IObservable で監視可能にします。
''' </summary>
@peace2048
peace2048 / gist:7560933
Created November 20, 2013 10:25
指定時間待機する。 Thread.Sleep の代わりに TaskCancellationSource を使ってみる
'例えば、30秒間隔で状態監視を実行する場合とか
Dim ループ = New CancellationTokenSource()
Dim 状態監視間隔の待機 As CancellationTokenSource
Dim 状態監視タスク = Task.Factory.StartNew(
Sub()
While True
' 状態を監視する処理を実行
@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")
@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 / 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 / RemotingSample.cs
Created February 20, 2014 06:17
Remoting の超簡単なサンプル
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
if (args.Select(_ => _.ToUpper()).Any(_ => _ == "C"))
@peace2048
peace2048 / gdc.vb
Created April 4, 2014 03:16
最大公約数を求める
Module Module1
Sub Main()
' 1000,2500,5000 の最大公約数を求める
Dim n = {1000, 2500, 5000}.Aggregate(AddressOf GDC)
Console.WriteLine(n)
Console.ReadLine()
End Sub
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
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;