Skip to content

Instantly share code, notes, and snippets.

View zhenlinyang's full-sized avatar

Zhenlin Yang zhenlinyang

View GitHub Profile
@zhenlinyang
zhenlinyang / CSharpCopyTarget.bat
Created August 24, 2016 11:41
CSharp Copy Target Assembly
copy $(TargetPath) $(TargetDir)..\..\..\$(TargetFileName)
@zhenlinyang
zhenlinyang / RandomMng.cs
Last active August 24, 2016 11:18
Get No-repeat Random Value
public static class RandomMng
{
private static Random random = new Random();
public static int GetRandomInt32(ICollection<int> coll)
{
int ret;
do
{
ret = random.Next();
@zhenlinyang
zhenlinyang / LinqSample.cs
Created August 23, 2016 07:56
Linq Sample
public bool TryGetPlayerInfoByUserName(string userName, out PlayerInfo playerInfo)
{
IEnumerable<PlayerInfo> infoQuery =
from info in _PlayerInfoDic.Values
where info.UserName == userName
select info;
if (0 != infoQuery.Count())
{
playerInfo = infoQuery.First();
return true;
@zhenlinyang
zhenlinyang / 0_reuse_code.js
Created August 19, 2016 02:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@zhenlinyang
zhenlinyang / RichTextBoxChangeCodeColor.cs
Created August 16, 2016 06:28
Windows Forms RichTextBox Change Code Color
internal static class ProtoChangeColorHandler
{
private static readonly string[] c_KeyWords =
{
"default", "enum", "message", "import", "group", "package",
"extend", "extensions", "to", "max",
"service", "rpc", "returns",
"true", "false",
"required", "optional", "repeated",
"double", "float", "int32", "int64", "uint32", "uint64",
@zhenlinyang
zhenlinyang / FPS.cs
Created August 9, 2016 02:25
Show FPS by Google
// Copyright 2015 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@zhenlinyang
zhenlinyang / HexStringAndUlongConverter.cs
Last active August 9, 2016 01:56
HexString & Ulong Converter
public static ulong HexStringToUlong(this string str)
{
return ulong.Parse(str, System.Globalization.NumberStyles.HexNumber);
}
[NotNull]
public static string UlongToHexString(this ulong num)
{
return string.Format("{0:x}", num);
}
@zhenlinyang
zhenlinyang / DataMatrixRotating.cs
Created August 9, 2016 01:49
Data Matrix Rotating
/// <summary>
/// Data Matrix Rotating
/// </summary>
/// <param name="number">Original Data</param>
/// <returns>Four directions of the number, the original data in the final.</returns>
public static ulong[] GetRotatedNumbers(ulong number)
{
ulong[] ulongs = new ulong[4];
ulongs[3] = number;
for (int t = 0; t < 3; ++t)
@zhenlinyang
zhenlinyang / DataMatrixMatchingCheck.cs
Created August 9, 2016 01:44
Data Matrix Matching Check
/// <summary>
/// Data Matrix Matching Check
/// </summary>
/// <param name="u1"></param>
/// <param name="u2"></param>
/// <param name="num">Maxdiff</param>
public static bool Match(ulong u1, ulong u2, byte num)
{
for (u1 ^= u2; 0 != u1 && 0 != num; num--)
{
@zhenlinyang
zhenlinyang / Explicit.cs
Created August 9, 2016 01:35
CSharp Explicit
public static explicit operator UnityEngine.Vector3(NanoFramework.UnityForServer.DataStructure.Vector3 v)
{
return new UnityEngine.Vector3(v.x, v.y, v.z);
}