Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Runtime.CompilerServices;
using System.Threading;
class Program
{
static readonly EventWaitHandle wh = new ManualResetEvent(false);
static volatile bool beforeSet = false;
static volatile bool afterSleep = false;
@yutopio
yutopio / Volatile.cs
Last active September 23, 2016 06:28
using System;
using System.Threading;
class Program
{
class Flag
{
public bool done;
}
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
public static class StreamUtil
{
public static async Task<byte[]> ReadAsync(this Stream stream,
int length, CancellationToken cancellationToken)
{
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
public static class ZipUtil
{
public static byte[] Compress(this Dictionary<string, byte[]> entries)
{
using (var stream = new MemoryStream())
{
@yutopio
yutopio / BytesEncoder.cs
Last active January 4, 2016 08:09
Encoder/decoder for byte array into string with 0-9,a-v
using System;
using System.Diagnostics;
using System.Text;
class Program
{
static void Main(string[] args)
{
var rnd = new Random(1);
for (var i = 0; i < 5000; i++)
@yutopio
yutopio / YTONotificationTest.m
Created January 19, 2014 04:45
Sample project to inspect notification messages during iOS application running.
//
// YTONotificationTest.m
//
// Created by Yuto Takei on 1/19/14.
// Copyright (c) 2014 Yuto Takei. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@yutopio
yutopio / YTOMultilineTextbox.m
Created January 18, 2014 11:00
Multiline Textbox for iOS 7.
//
// YTOMultilineTextbox.m
// MultilineTextbox
//
// Created by Yuto Takei on 1/18/14.
// Copyright (c) 2014 Yuto Takei. All rights reserved.
//
@interface YTOMultilineTextbox : UITextView
@yutopio
yutopio / neville.cs
Created May 24, 2013 14:54
Neville interpolation
using System;
class Program
{
static void Main()
{
var funcs = new Func<double, double>[8];
funcs[0] = x => Math.Exp(x);
funcs[1] = x => Math.Log(x);
funcs[2] = x => 1 + x + x * x;
@yutopio
yutopio / pseudoprimes.cs
Created May 24, 2013 14:43
Enumerates some pseudoprimes.
using System;
using System.IO;
unsafe class Program
{
const int size = 1000000000;
static bool[] sieve = null;
static void Main()
{
@yutopio
yutopio / ipv4.cs
Created May 24, 2013 14:35
Enumerates IPv4 address space allocation.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
class Program
{
static void Main()