Skip to content

Instantly share code, notes, and snippets.

View hidori's full-sized avatar
🏠
Working from home

Hiroaki SHIBUKI hidori

🏠
Working from home
  • Tokyo, Japan
  • 03:37 (UTC +09:00)
View GitHub Profile
@hidori
hidori / ByteArrayFactory.cs
Created May 10, 2012 04:09
Bulding byte array simply
using System;
using System.IO;
namespace Mjollnir
{
static class ByteArrayFactory
{
public static byte[] Create(Action<Stream> action)
{
if (action == null) throw new ArgumentNullException("action");
@hidori
hidori / StringFactory.cs
Created May 10, 2012 04:23
Blding string simply
using System;
using System.Text;
namespace Mjollnir
{
static class StringFactory
{
public static string Create(Action<StringBuilder> action)
{
if (action == null) throw new ArgumentNullException("action");
@hidori
hidori / Syncronized.cs
Last active October 4, 2015 14:08
Waiting asyncronous works completion simpley
static class Syncronized
{
public static void Invoke(Action<ManualResetEvent> action)
{
if (action == null) throw new ArgumentException("action");
using (var signal = new ManualResetEvent(false))
{
action(signal);
signal.WaitOne();
@hidori
hidori / TaskExtensions.cs
Created May 10, 2012 04:50
Waiting task completion simply
static class TaskExtensions
{
public static void Await(this Task task)
{
if (task == null) throw new ArgumentNullException("task");
task.Wait();
if (task.IsCompleted)
{
@hidori
hidori / TaskExtensions.tt
Created May 10, 2012 05:47
Waiting task completion simply - Delax
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#
var recipes = new[]
{
new
{
Parameters = "",
Arguments1 = "",
Arguments2 = "",
@hidori
hidori / Lock.cs
Created May 12, 2012 04:21
Lock and recieve result simply
using System;
namespace Mjollnir
{
static class Lock
{
public static TResult Invoke<TResult>(object syncRoot, Func<TResult> func)
{
lock (syncRoot)
{
@hidori
hidori / StreamExtensions.cs
Created May 16, 2012 07:20
Stream.CopyTo() for .NET Framework 3.5 SP1
using System;
using System.IO;
namespace Mjollnir.IO
{
static class StreamExtensions
{
const int DefaultBufferSize = 4096;
public static long CopyTo(this Stream source, Stream destination)
@hidori
hidori / StringExtensions.cs
Created May 22, 2012 03:18
StringExtensions.ToStream(), Create MemoryStream from String
using System;
using System.IO;
using System.Text;
namespace Mjollnir
{
static class StringExtensions
{
public static Stream ToStream(this string source, Encoding encoding)
{
@hidori
hidori / TaskIEnumerableT1.cs
Created August 7, 2012 14:32
Task<IEnumerable<T>> #1
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
@hidori
hidori / TaskIEnumerableT2.cs
Created August 7, 2012 14:33
Task<IEnumerable<T>> #2
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{