Skip to content

Instantly share code, notes, and snippets.

View waynebaby's full-sized avatar

Wayne Wang 韦恩卑鄙 waynebaby

View GitHub Profile
interface IMyList<T> : IEnumerable<T>
{
// O(1)
// Add an item at the beginning of the list.
void AddFirst(T item);
// O(1)
// Add an item at the end of the list.
void AddLast(T item);
@waynebaby
waynebaby / RemoveMultipleSpaces.cs
Created March 30, 2012 17:05 — forked from Ninputer/RemoveMultipleSpaces.cs
模拟微面试之去空格
//请实现下面的函数,输入参数baseStr是一个(可以更改的)字符串,请将其中所有连续出现的多个空格都替换成一个空格,单一空格需保留。
//请直接使用baseStr的空间,如需开辟新的存储空间,不能超过o(N)(注意是小o,N是字符串的长度)。返回值是替换后的字符串的长度。
//样例代码为C#,但可以使用任何语言。如需使用任何库函数,必须同时给出库函数的实现。
class Program
{
//linq version, did not read your code, just for less lines.
public static int RemoveMultipleSpaces(char[] baseStr)
{
int currentReadIdx = 0;
int currentWriteIdx = 0;
// The code below would print overlapped A and B sequences like:
// ...
// A
// A
// B
// B
// ...
//
// Please add multi-threading protection code to make sure that
// As and Bs are printed in the order of:
----------------------------------Unsafe Code---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace WordsRandom
String makeRandom(String content)
{
if(content == null)
throw Exception("Null input vlaue");
if(content.length <= 3)
return content;
else
return generateRadom(content);
}
@waynebaby
waynebaby / vm_property_logic.cs
Created November 23, 2012 06:57
MVVMSideKick 用Rx来配置属性之间的关系
namespace TableGameSidekick_Metro.Games.DefaultTradeGame.Models
{
[DataContract]
public class ResourceConfig : BindableBase<ResourceConfig>
{
// If you have install the code sniplets, use "propvm + [tab] +[tab]" create a property。
// 如果您已经安装了 MVVMSidekick 代码片段,请用 propvm +tab +tab 输入属性
public ResourceConfig(int players)
@waynebaby
waynebaby / gist:5843843
Last active December 18, 2015 20:59
一个类似Lazy<T>的模式 Link<TId,TTarget> 支持Async. 求Code Review //不再使用参数Id 这样可以保证不会出现旧id 执行完毕覆盖新Id的状况
using AzureChat.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AzureChat.Common
{
@waynebaby
waynebaby / eventBind.cs
Created August 9, 2013 01:41
如何用一个方法 将任意eventarg类型的EVent 绑定到一个 Action<object,object> /*支持 windows RT 下的 托管/非托管 EVENT*/
public static IDisposable BindEvent(this object sender, string eventName, EventHandlerInvoker executeAction)
{
var t = sender.GetType();
while (t != null)
{
public class AsyncCompletion
{
static AsyncCompletion()
{
CompletedSource = new TaskCompletionSource<Unit>();
CompletedSource.SetResult(Unit.Default);
public class AsyncCompletion
{
/// <summary>
/// 跟着实例走的默认未完成源
/// </summary>
Lazy<TaskCompletionSource<Unit>> _lazyIncompletByDefaultSource =
new Lazy<TaskCompletionSource<Unit>>(() => new TaskCompletionSource<Unit>(), true);
/// <summary>
/// 静态完成源