Skip to content

Instantly share code, notes, and snippets.

@pierre3
pierre3 / OpenFiles_2.cs
Last active December 16, 2015 02:38
async /await で複数の値を返す場合は IObservable
// 複数のファイルをまとめて非同期に読む
// Observable.Create がいいらしい
// IObservable<T> Create<T>(Func<IObserver<T>,CancellationToken, Task> subscribe)
// このオーバーロードがない(Rx2.0?)ので自作してみる
private IObservable<Tuple<string, string>> OpenFiles(string[] fileNames)
{
return ObservableEx.Create<Tuple<string, string>>(async (observer, ct) =>
{
try
@pierre3
pierre3 / GistObjects.cs
Last active December 16, 2015 04:59
JSON of gists object
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace GistsApi
{
public class GistObject
{
public string url { set; get; }
public string id { set; get; }
public string description { set; get; }
@pierre3
pierre3 / GistJson.md
Last active February 26, 2018 05:14
[DynamicJson] JSON 要素の名前(key)部分が不定の場合の変換方法

[DynamicJson] JSON の名前(key)が不定の場合の変換方法について

DynamicJson とSystem.Net.Http.HttpClient でGists APIを作ってみました

こちらで公開しております。

Gist API が返してくるJSONの変換にはDynamicJsonを使用させていただきました。

@pierre3
pierre3 / GistJson2.md
Last active February 26, 2018 05:15
[DynamicJson] JSON 要素の名前(key)部分が不定の場合の変換方法(2)

[DynamicJson] JSON の名前(key)が不定の場合の変換方法について(その2)

ObjectをJSONにシリアライズする

前回 とは逆のパターン、Gistを生成したりする場合にPOSTするJSONの生成方法に関するメモ。

Gist生成用のJSON

"files"の下に、 " ファイル名 " : { "content": " ファイルの内容 " } を1つ以上含むオブジェクトを設定します。
やはり、" ファイル名 "の部分が不定となります。

@pierre3
pierre3 / Manual.md
Last active December 20, 2015 22:48
WpfGists v0.5.1.0

WpfGists

Gistの作成、編集、閲覧が可能なWindows用デスクトップアプリケーションです。

wpfGists window

動作環境

  • このアプリケーションを実行するには .Net Framework4.5が必要です。
@pierre3
pierre3 / StringExtensions.t4.cs
Created August 21, 2013 14:28
string to primitive

using System;
using System.Linq;
using System.Text;
using System.Globalization;
namespace TextDataUtility
{
public static partial class StringExtensions
{
@pierre3
pierre3 / Program.md
Last active December 21, 2015 12:39
[C#][小ネタ] 文字列を各種組み込み型にキャスト(もどき)

こちらの記事から

bool dat = (bool:TextToBoolConverter)file[0];
こんな構文ないけど、型変換演算子のオーバーロードで、ほぼ同等ことができるのでは?ということで作ってみました。

他の主要な組み込み型についてもT4を使ってさくっと作れます。

(個人的にはToBoolean()みたいな拡張メソッドの方が使いやすいと思いますが。(インテリセンス使えますし))

@pierre3
pierre3 / file0.cs
Created October 5, 2013 12:46
[WPF]PasswordBoxのセキュアなパスワードSecurePasswordにバインドしたい ref: http://qiita.com/pierusan2010/items/5d4ceb28ee18cd4e3853
public static class SecureStringEx
{
public static bool Equals(this SecureString a, SecureString b)
{
if (a == null && b == null)
{ return true; }
if (a == null || b == null)
{ return false; }
@pierre3
pierre3 / Readme.md
Created December 14, 2013 01:59
XsvData

HandyUtilities, .Net C# Xsv data processing library

This is CSV, TSV and any character separated value data processing library.

Reading XSV data

Can read from TextReader. And accesses by indexer.

[TestMethod]
public void ReadCsvTest_indexer()
{
@pierre3
pierre3 / xsvReader.Parse.cs
Last active August 29, 2015 13:57
Parse a csv
public static IEnumerable<string> Parse(string line,
ICollection<string> delimiters, Func<string> followingLineSelector)
{
//読み取った文字の種類に応じて処理を振り分けるために使用するTokenState 列挙型
var state = TokenState.Empty;
string token = "";
// -フィールドを1文字ずつ読み取り、token へ格納する
// -1フィールド分を読み取ったら yield return token; で出力
foreach (var c in line)
{