Skip to content

Instantly share code, notes, and snippets.

View zhenlinyang's full-sized avatar

Zhenlin Yang zhenlinyang

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / CSharpCopyTarget.bat
Created August 24, 2016 11:41
CSharp Copy Target Assembly
copy $(TargetPath) $(TargetDir)..\..\..\$(TargetFileName)
@zhenlinyang
zhenlinyang / VS2015 Class Template
Last active September 7, 2016 01:49
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\2052\
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{
@zhenlinyang
zhenlinyang / ExtractZipFile.cs
Created September 27, 2016 05:45 — forked from r2d2rigo/ExtractZipFile.cs
Using SharpZipLib to extract zip files from Unity in a coroutine-friendly way
// This sample function uses SharpZipLib (http://icsharpcode.github.io/SharpZipLib/) to extract
// a zip file without blocking Unity's main thread. Remember to call it with StartCoroutine().
// Byte data is passed so a MemoryStream object is created inside the function to prevent it
// from being reclaimed by the garbage collector.
public IEnumerator ExtractZipFile(byte[] zipFileData, string targetDirectory, int bufferSize = 256 * 1024)
{
Directory.CreateDirectory(targetDirectory);
using (MemoryStream fileStream = new MemoryStream())
@zhenlinyang
zhenlinyang / StreamingAssetsSample.cs
Created October 9, 2016 09:25
Use StreamingAssets in Unity
private IEnumerator CopyVersion()
{
string _Version_txt_streamingAssetsPath = PathConf.VCRoot + "Version.txt";
if (_Version_txt_streamingAssetsPath.Contains("://"))
{
using (WWW www = new WWW(_Version_txt_streamingAssetsPath))
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
{